美文网首页
postgresql数据库安装

postgresql数据库安装

作者: 我是大黄蜂 | 来源:发表于2021-11-01 09:08 被阅读0次

#本次部署的用户是 postgres 如果想用别的用户记得修改

#安装解压工具

1.yum -y install bzip2

#解压

2.tar xjf postgresql-9.6.5.tar.bz2

3.cd postgresql-9.6.5

#编译postgresql数据库

#如果报错 :configure: error: no acceptable C compiler found in $PATH

#安装GCC套件:yum -y install gcc

#如果报错 :configure: error: readline library notfound

#安装readline-devel 包:yum -y install -y readline-devel

#如果报错 :configure: error: zlib library not found

#安装:yum -y install zlib-devel

4. ./configure

#需要等待3分钟,看到‘Ready to install’表示成功

5.gmake

6.gmake install

7.完成

创建数据库用户:

1.useradd postgres

2.passwd postgres

3.usermod -a -G postgres postgres

数据库用户设置:

1.vi /etc/passwd

2.把 postgres:x:528:528::/home/postgres:/bin/bash改成 postgres:x:528:528::/usr/local/pgsql:/bin/bash

3.cp /home/postgres/.bash_profile /usr/local/pgsql/

4.cd /usr/local/pgsql/

5.chown postgres.postgres .bash_profile

6.cd /home/

7.rm -rf postgres/

postgresql数据库配置:

#设置环境变量

1.vi ~/.bash_profile

2.修改 PATH=$PATH:$HOME/bin 为 PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin

#使环境变量生效

3.source ~/.bash_profile

4.mkdir /usr/local/pgsql/data

5.chown postgres /usr/local/pgsql/data

6.su postgres

7./usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/

alter user postgres with password 'postgres'; #密码初始化

8.exit

9.cd /opt/postgresql-9.6.5

10.cp contrib/start-scripts/linux /etc/init.d/postgresql

11.chmod +x /etc/init.d/postgresql

#设置数据库自动启动

12.chkconfig --add postgresql

13.chkconfig postgresql on

#设置可被访问

14.cd /usr/local/pgsql/data

#可被192.168.1网段访问

修改 pg_hba.conf 中 127.0.0.1/32  trust为 192.168.1.0/24 md5

15.vi pg_hba.conf

#修改 listen_addresses=’localhost’ 为listen_addresses=’*’

#修改 log_timezone = 'Asia/Shanghai'  使用亚洲/上海时区

#修改 timezone = 'Asia/Shanghai'  使用亚洲/上海时区

#修改 wal_log_hints = on  恢复备机时pg_rewind需要使用

16.vi postgresql.conf

17.su postgres

#使用postgresql用户开启数据库

18. /etc/init.d/postgresql start

#验证数据库是否开启

#查看5432端口是否开启

19.netstat -tpnl |grep 5432

相关文章

网友评论

      本文标题:postgresql数据库安装

      本文链接:https://www.haomeiwen.com/subject/cwczaltx.html