PostgresQL 安装环境

一、CentOS 7 安装

1. 环境说明

  • CentOS7
  • PosgreSQL 11.2

2. 在线安装

到目前为止(2019-12-4),CentOS7 默认携带了9.2.24版本的PostgreSQL,我们可以直接从源进行安装:
# 在线安装
sudo yum install postgresql postgresql-server postgresql-contrib
# 初始化数据库
sudo postgresql-setup initdb
sudo systemctl start postgresql
# 设置为开机自启动
sudo systemctl enable postgresql
# 重启服务
systemctl restart postgresql

3. 离线RPM包安装

下载地址:https://yum.postgresql.org/rpmchart.php
下载地址:https://yum.postgresql.org/11/redhat/rhel-7-x86_64/repoview
# 先安装依赖包
yum -y install libicu libxslt perl-lib systemd-libs
# 按照如下顺序安装好所有的包
[root@node1 opt]# rpm -ivh postgresql11-libs-11.2-1PGDG.rhel7.x86_64.rpm
[root@node1 opt]# rpm -ivh postgresql11-11.2-1PGDG.rhel7.x86_64.rpm
[root@node1 opt]# rpm -ivh postgresql11-contrib-11.2-1PGDG.rhel7.x86_64.rpm
[root@node1 opt]# rpm -ivh postgresql11-server-11.2-1PGDG.rhel7.x86_64.rpm
- 注意:注意离线的安装方式,版本号会影响相关的文件路径。例如 `/var/lib/pgsql` 变成 `/var/lib/pgsql/11` `systemctl status postgresql-11`
- 注意:程序会被按照到 `/usr/pgsql-11/` 这个目录
# 初始化DB
/usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK
# 启动DB服务
systemctl start postgresql-11
systemctl stop postgresql-11
# 设置开机启动
systemctl enable postgresql-11
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

4. 初始配置

默认PostgreSQL会创建一个 postgres 用户(Linux)来访问数据库软件。

注意:postgres不应该有其他的操作(例如连接到其他网络),这样会给数据库留下安全隐患。

# 修改postgres用户密码:
[root@node1 bin]# passwd postgres # Rexen@123.com.cn
# 切换到postgres用户:
[root@node1 bin]# su - postgres
# 修改PostgreSQL的postgres用户的密码:注意:Linux上的postgres用户用来访问数据库,PostgreSQL 中的 postgres 用户用来管理数据库
bash-4.2$ psql -d template1 -c "ALTER USER postgres WITH PASSWORD '123456';" # 这里我们测试用:123456
# 访问数据库:
bash-4.2$ psql postgres
psql (11.2)
Type "help" for help.
postgres=#

5. 远程访问

# 配置文件位置,如下是默认的配置文件路径:
vi /var/lib/pgsql/11/data/pg_hba.conf
# 在配置文件的下面添加如下内容,允许所有地址进行访问,通过md5加密的密码,注意该文件的优先级是从上到下的,所以需要写在默认的上面
host all all 0.0.0.0/0 md5
host all all 127.0.0.1/32 ident # 这里是默认的位置 # 修改配置文件
vi /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = '*' # 监听所有ip,默认是localhost
max_connections = 1000 # 默认100
tcp_keepalives_idle = 600 # TCP_KEEPIDLE, in seconds;
tcp_keepalives_interval = 10 # TCP_KEEPINTVL, in seconds;
tcp_keepalives_count = 6 # TCP_KEEPCNT;
systemctl restart postgresql-11.service

最新文章

  1. discuz首页设置默认地址不带forum.php后缀的方法
  2. 【Python网络爬虫二】使用urllib2抓去网页内容
  3. sprintf溢出的bug
  4. Python格式化字符串~转
  5. 关于使用flexible.js自适应页面,发现文字很多时,字体会变大的问题的原因和解决方案
  6. 升级PHP
  7. 【题解】【BST】【Leetcode】Validate Binary Search Tree
  8. 多线程11_张孝祥 java5的线程锁技术
  9. OS笔记047代理传值和block传值
  10. 解决Ubuntu下安装VMware错误could not open /dev/vmmon
  11. "The Application was unable to start correctly (0xc000007b). Click OK to close the application"
  12. sql将查询结果建立为新表
  13. 迁移MSSQL实例的所有login(包含密码)
  14. ZH奶酪:哈工大LTP云平台标记含义及性能
  15. Bat注释符号
  16. 微信小游戏 修改appid
  17. Oracle 使用GSON库解析复杂json串
  18. Hive如何加载和导入HBase的数据
  19. MySQL学习笔记:创建整年日期
  20. Git_撤销修改

热门文章

  1. Git 报错:Updates were rejected because the tip of your current branch is behind
  2. A - Alice and the List of Presents (排列组合+快速幂取模)
  3. ubuntu下查询网络的常用命令
  4. JDK11 JAVA11下载安装与快速配置环境变量教程
  5. 虚拟机virtualBox
  6. 吴裕雄--天生自然ShellX学习笔记:Shell 数组
  7. Jupyter notebook 和 Jupyter lab 的区别
  8. ccf201403-3 记录一个神tmwa了的代码 莫非我没看懂题。。。
  9. ZJNU 1538 - YN!ngC的取子游戏--高级
  10. python 拆解包