postgresql Centos7部署

1、创建postgres用户组

yum -y install libicu libxslt-devel
useradd postgres
echo 'postgres'|passwd --stdin postgres  //设置密码为postgres
2、rpm安装
rpm -ivh postgresql10-libs-10.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-10.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-server-10.15-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-contrib-10.15-1PGDG.rhel7.x86_64.rpm



3、修改自定义数据目录
# 使用root用户
systemctl edit postgresql-10.service

# 编辑内容
[Service]
Environment=PGDATA=/dbdata/postgresql/data
# 自定义配置在/etc/systemd/system/postgresql-10.service.d/override.conf
=====================================================================
cat /etc/systemd/system/postgresql-10.service.d/override.conf

4、重新加载系统
systemctl daemon-reload

5、设置目录权限
chown postgres:postgres /dbdata/postgresql/data

6、初始化pg
/usr/pgsql-10/bin/postgresql-10-setup initdb

7、设置开机启动pg
systemctl enable postgresql-10.service
systemctl start postgresql-10.service

8、修改用户名密码
su - postgres
psql
# 设置postgres用户密码
ALTER USER postgres WITH PASSWORD 'postgres';
#退出
\q

9、远程连接配置
vi /dbdata/postgresql/data/pg_hba.conf
添加:
host all all 0.0.0.0/0 md5
# 开启远程访问,修改postgresql.conf配置文件
vi /dbdata/postgresql/data/postgresql.conf
添加:
listen_addresses='*'
# 开放postgresql服务
firewall-cmd –add-service=postgresql –permanent
# 重载防火墙
firewall-cmd –reload

# 重启pg服务
systemctl restart postgresql-10

10、修改系统环境变量
su - postgres
vi .bash_profile
PGDATA=/dbdata/postgresql/data/
PGHOME=/usr/pgsql-10
export PGDATA
export PGHOME
export PATH=$PATH:$PGHOME/bin

# 生效
source .bash_profile

 

posted @ 2021-02-26 14:20  Simon92  阅读(208)  评论(0编辑  收藏  举报