[root@web1 postgresql-10.5]# useradd postgres
[root@web1 postgresql-10.5]# chown -R postgres.postgres /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]# ll /usr/local/ |grep pgsql-10.5
drwxr-xr-x 6 postgres postgres 56 May 23 18:06 pgsql-10.5
[root@web1 postgresql-10.5]#
11、给/usr/local/pgsql-10.5目录设置软连接(方便查看和管理吧....)
[root@web1 postgresql-10.5]# ln -s /usr/local/pgsql-10.5/ /usr/local/pgsql
[root@web1 postgresql-10.5]# ll /usr/local/pgsql
lrwxrwxrwx 1 root root 22 May 23 18:15 /usr/local/pgsql -> /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]#
12、进入刚创建的postgres用户
[root@web1 postgresql-10.5]# su postgres
[postgres@web1 postgresql-10.5]$
13、设置环境变量(注意路径)
[postgres@web1 ~]$ vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH=$PATH:/usr/local/pgsql-10.5/bin
PGDATA=/usr/local/pgsql-10.5/data
export PGDATA
export PATH
14、当前生效
[postgres@web1 ~]$ source ~/.bash_profile
[postgres@web1 ~]$
15、测试
[postgres@web1 ~]$ which psql
/usr/local/pgsql-10.5/bin/psql
[postgres@web1 ~]$ psql -V
psql (PostgreSQL) 10.5
16、初始化数据库(initdb --help查看讲情),指定库文件路径
[postgres@web1 ~]$ initdb /usr/local/pgsql-10.5/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /usr/local/pgsql-10.5/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /usr/local/pgsql-10.5/data -l logfile start
[postgres@web1 ~]$
***在此就已经部署成功了,现在要做的就是修改下配置文件,优化下***
17、前往文件安装所在地,修改pg_hba.conf配置文件
[postgres@web1 data]$ cp pg_hba.conf pg_hba.conf.`date +%F`
[postgres@web1 data]$ vim pg_hba.conf
#######################################
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
#host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5 #所有ip都可以通过密码连接
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
######################################
18、前往文件安装所在地,修改postgresql.conf配置文件
[postgres@web1 data]$ cd /usr/local/pgsql/data/
[postgres@web1 data]$ cp postgresql.conf postgresql.conf.`date +%F`
[postgres@web1 data]$ vim postgresql.conf
#########################################
# - Connection Settings -