CentOS 7 安装 Postgresql 9.6
来源:互联网 发布:网络很卡用英语怎么说 编辑:程序博客网 时间:2024/06/16 08:53
添加RPM
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
安装PostgreSQL 9.6
postgresql96-server 数据库核心服务端
postgresql96-contrib 附加第三方扩展
postgresql96-devel C语言开发Header头文件和库(可以不装)
yum install postgresql96-server postgresql96-contrib postgresql96-devel
验证是否安装成功
rpm -aq| grep postgres
更改数据库数据存储路径(原默认路径为:/var/lib/pgsql/9.6/data )
cd /mnt
sudo mkdir vdb1
sudo chown -R postgres:postgres vdb1
sudo chmod 700 vdb1
vi /usr/lib/systemd/system/postgresql-9.6.service
初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
开启服务
service postgresql-9.6start 或者 systemctl start postgresql-9.6.service
开机启动
sudo chkconfig postgresql-9.6 on 或者 systemctl enable postgresql-9.6.service
修改密码
su postgres
psql
ALTER USER postgres WITH PASSWORD '密码'; --必须以分号结束,成功执行后会出现ALTER ROLE
\q
su root
开启远程访问
vi /var/lib/pgsql/9.6/data/postgresql.conf 或者 vi /mnt/vdb1/postgresql.conf
修改#listen_addresses = 'localhost' 为 listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
信任远程连接
vi /var/lib/pgsql/9.6/data/pg_hba.conf 或者 vi /mnt/vdb1/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 10.211.55.6/32(需要连接的服务器IP,或者直接改为0.0.0.0/0,表示任意服务器连接) md5
重启服务
service postgresql-9.6 restart 或者 systemctl restart postgresql-9.6.service
配置防火墙
CentOS 防火墙中内置了PostgreSQL服务,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我们只需以服务方式将PostgreSQL服务开放即可。
systemctl enable firewalld 开机启用防火墙
systemctl start firewalld 开启防火墙
firewall-cmd --add-service=postgresql --permanent 开放postgresql服务
firewall-cmd --zone=public --add-port=5432/tcp --permanent 或者可以直接添加端口
firewall-cmd --reload 重载防火墙
firewall-cmd --list-ports 查看占用端口
简单使用
psql -U postgres postgres 连接数据库
说明:-h表示主机(Host),-p表示端口(Port),-U表示用户(User)
显示所有数据库: \l
卸载PostgreSQL
yum erase postgresql96
结束
备注:
[root@ip-10-0-0-228 ec2-user]# service postgresql initdbData directory is not empty! [FAILED]
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]# ll -lhtr /var/lib/pgsql9/data/
total 88K
-rw——- 1 postgres postgres 4 May 5 09:32 PG_VERSION
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_twophase
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_tblspc
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_stat_tmp
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_snapshots
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_serial
drwx—— 4 postgres postgres 4.0K May 5 09:32 pg_multixact
-rw——- 1 postgres postgres 20K May 5 09:32 postgresql.conf
-rw——- 1 postgres postgres 1.6K May 5 09:32 pg_ident.conf
-rw——- 1 postgres postgres 4.2K May 5 09:32 pg_hba.conf
drwx—— 3 postgres postgres 4.0K May 5 09:32 pg_xlog
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_subtrans
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_clog
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_notify
drwx—— 2 postgres postgres 4.0K May 5 09:32 global
drwx—— 5 postgres postgres 4.0K May 5 09:32 base
drwx—— 2 postgres postgres 4.0K May 5 09:32 pg_log
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#rm -rf /var/lib/pgsql9/data/*
[root@ip-10-0-0-228 ec2-user]# ll -lhtr /var/lib/pgsql9/data/
total 0
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]# service postgresql initdb
Initializing database: [ OK ]
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]#
[root@ip-10-0-0-228 ec2-user]# ll -lhtr /var/lib/pgsql9/data/
total 88K
-rw——- 1 postgres postgres 4 May 7 10:42 PG_VERSION
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_twophase
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_tblspc
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_stat_tmp
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_snapshots
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_serial
drwx—— 4 postgres postgres 4.0K May 7 10:42 pg_multixact
-rw——- 1 postgres postgres 20K May 7 10:42 postgresql.conf
-rw——- 1 postgres postgres 1.6K May 7 10:42 pg_ident.conf
-rw——- 1 postgres postgres 4.2K May 7 10:42 pg_hba.conf
drwx—— 3 postgres postgres 4.0K May 7 10:42 pg_xlog
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_subtrans
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_clog
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_notify
drwx—— 2 postgres postgres 4.0K May 7 10:42 global
drwx—— 5 postgres postgres 4.0K May 7 10:42 base
drwx—— 2 postgres postgres 4.0K May 7 10:42 pg_log
[root@ip-10-0-0-228 ec2-user]#
转载于Qbit编程学习笔记
- CentOS 7 安装PostgreSQL 9.6
- CentOS 7 安装 Postgresql 9.6
- CentOS 7 安装 PostgreSQL
- centos 7 下安装postgreSQL
- CentOS下安装postgresql
- CentOS 安装 PostgreSQL 9.2
- centos 下安装postgresql
- centos安装psotgis+postgresql
- CentOS下安装PostgreSQL
- centos 安装postgresql
- CentOS 安装PostgreSQL 9.1
- CentOS安装PostgreSQL数据库
- centos 安装postgreSQL
- CentOS安装PostgreSQL 9.4
- centos 安装postgresql
- centos 下 PostgreSql安装
- centos 操作系统 安装 postgresql-9.4 postgresql-9.3
- CentOS从源码安装PostgreSQL
- 理解维度数据仓库——事实表、维度表、聚合表
- 基于Spring+SpringMVC+Mybatis分布式敏捷开发系统架构
- 计算机组成原理知识点梳理(二)
- ls 命令的用法
- fastjson对json字符串JSONObject和JSONArray互相转换操作示例
- CentOS 7 安装 Postgresql 9.6
- Atom python3 Mac
- 基数排序
- getc和putc
- 【编程题】Java编程题三(10道)
- Using Kotlin, RxJava 2 and Retrofit to consume REST API on Android
- Vue 爬坑之路(八)—— 使用 Echarts 创建图表
- web开发之路——javascript、dom、jQuery(上)
- 中级笔记