CentOS7 下安装 PostgreSQL10

来源:互联网 发布:linux phpmyadmin 编辑:程序博客网 时间:2024/05/17 02:55

1、下载源代码并解压

1. wget https://ftp.postgresql.org/pub/source/v9.4.15/postgresql-9.4.15.tar.gz2. tar -xvzf postgresql-10.0.tar.gz  #解压pg包3. ./configure4. sudo make5. sudo make install

2、创建用户组和用户

1. groupadd postgres    #新增用户组2. useradd -g postgres postgres    #新增用户3. passwd postgres    #为用户设置密码

3、创建数据目录

1. mkdir /usr/local/pgsql/data2. chown postgres /usr/local/pgsql/data    #设置data文件加属性3. chmod 700 /usr/local/pgsql/data    #设置data文件夹权限

4、数据库操作

1. /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data    #初始化数据库2. ./pg_ctl start\stop\restart -D /usr/local/pgsql/data/   #启动\停止\重启数据库 3. /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &  #设置日志输出位置4. /usr/local/pgsql/bin/createdb test    #创建测试数据库5. /usr/local/pgsql/bin/psql test    #启动测试数据库

5、修改postgresql.conf

1. listen_addresses = '*'2. port = 5432

6、修改pg_hba.conf

# "local" is for Unix domain socket connections onlylocal   all             all                                  trust# IPv4 local connections:host    all             all             0.0.0.0/0            trust

7、远程连接

1. 查看防火墙是否关闭:firewall-cmd --state2. 启动服务:systemctl start firewalld.service3. 关闭服务:systemctl stop firewalld.service4. 重启服务:systemctl restart firewalld.service5. 显示服务的状态:systemctl status firewalld.service6. 在开机时启用服务:systemctl enable firewalld.service7. 在开机时禁用服务:systemctl disable firewalld.service8. 查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?9. 查看已启动的服务列表:systemctl list-unit-files|grep enabled10. 添加开发端口:firewall-cmd --zone=public --add-port=5432/tcp --permanent11. 重新加载防火墙:firewall-cmd --reload
原创粉丝点击