一、安装依赖
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libicu-50.2-4.el7_7.x86_64.rpm
wget https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/postgresql96-9.6.20-1PGDG.rhel7.x86_64.rpm
wget https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/postgresql96-libs-9.6.20-1PGDG.rhel7.x86_64.rpm
wget https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/postgresql96-server-9.6.20-1PGDG.rhel7.x86_64.rpm
二、安装数据库
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm --force --nodeps
rpm -ivh postgresql96-libs-9.6.20-1PGDG.rhel7.x86_64.rpm --force --nodeps
rpm -ivh postgresql96-9.6.20-1PGDG.rhel7.x86_64.rpm --force --nodeps
rpm -ivh postgresql96-server-9.6.20-1PGDG.rhel7.x86_64.rpm --force --nodeps
三、配置启动项
#初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
#开机启动
systemctl enable postgresql-9.6
#启动pg
systemctl start postgresql-9.6
四、访问权限配置
1、放开所有 IP 连接
执行如下命令修改配置文件:
vi /var/lib/pgsql/9.6/data/postgresql.conf
将 listen_addresses 内容改为 * 号,参考如下:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
2、取消 IP 连接限制
执行如下命令修改配置文件:
vi /var/lib/pgsql/9.6/data/pg_hba.conf
主要添加如下内容:
host all all 0.0.0.0/0 trust
参考如下:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
host all all 0.0.0.0/0 trust
五、重启数据库
systemctl restart postgresql-9.6
六、测试数据库是否安装成功
[root@localhost pgsql-9.6]# su - postgres
e-bash-4.2$ psql
psql (9.6.20)
输入 "help" 来获取帮助信息
七、修改默认用户postgres密码
[root@localhost pgsql-9.6]# su - postgres
上一次登录:二 6月 15 14:40:17 CST 2021pts/0 上
e-bash-4.2$ psql
psql (9.6.20)
输入 "help" 来获取帮助信息.
postgres=# ALTER USER postgres WITH PASSWORD '123456';
ALTER ROLE
八、重新读取数据库配置
[root@localhost pgsql-9.6]# su - postgres
上一次登录:二 6月 15 15:04:03 CST 2021pts/0 上
-bash-4.2$ psql -U postgres
psql (9.6.20)
输入 "help" 来获取帮助信息.
postgres=# select pg_reload_conf()
postgres-# ;
pg_reload_conf
----------------
t
(1 行记录)
九、放开防火墙端口限制
执行如下命令即可
[root@localhost pgsql-9.6]# iptables -I INPUT -p tcp --dport 22 -j ACCEPT
[root@localhost pgsql-9.6]# iptables -I INPUT -p tcp --dport 5432 -j ACCEPT
以上就是安装过程,安装完成之后使用工具测试连接数据库吧。
参考内容如下,侵删: