postgresql安装部署
一、下载安装:
1、下载:
官网下载地址:https://www.postgresql.org/download/linux/redhat/
也可以用这个:https://www.enterprisedb.com/download-postgresql-binaries
从上述地址可以看到,其实官方从11开始已经没有二进制版本提供了,都是使用对应平台的发行版yum安装了。

去官网看other linux,已经没有最新的二进制包了。
https://www.postgresql.org/download/linux/#generic

2、安装:
我们使用官方提供的yum方式安装
https://www.postgresql.org/download/linux/redhat/
选择对应的平台与版本

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Install PostgreSQL:
sudo yum install -y postgresql13-server # Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
二、初始化配置:
默认安装目录:
bin目录:/usr/pgsql-13/bin
data目录:/var/lib/pgsql/13/data
1、修改data目录
# 暂停服务
systemctl stop postgresql-13
# 移动data目录:
mv /var/lib/pgsql /data/apps/pgsql
# 修改配置,第46行
vim /data/apps/pgsql/13/data/postgresql.conf
...
data_directory = '/data/apps/pgsql/13/data'
...
# 修改postgres用户家目录,否则使用su - postgres的时候会报错:su: warning: cannot change directory to /var/lib/pgsql: No such file or directory
vim /etc/passwd
...
postgres:x:26:26:PostgreSQL Server:/data/apps/pgsql:/bin/bash # 修改启动项里的data目录路径PGDATA
vim /usr/lib/systemd/system/postgresql-13.service
...
Environment=PGDATA=/data/apps/pgsql/13/data/
... # 启动服务
systemctl daemon-reload
systemctl start postgresql-13.service
2、登录修改超级用户密码:
需要从root切换到postgres用户,修改密码:
# 切换用户到postgres
[root@dev-predictionio-206 bin]# su - postgres
Last login: Mon Sep 6 10:22:28 CST 2021 on pts/0
# 直接用postgres超级用户登录,默认不需要密码,psql直接回车就以postgres用户进入了postgres数据库
-bash-4.2$ psql -U postgres
psql (13.4)
Type "help" for help.
# 修改超级用户密码为:postgres
postgres=# alter role postgres with password 'postgres';
ALTER ROLE
# 退出
postgres-# \q
在postgres用户下重载配置
修改用户
# 修改用户认证模式trust为md5
bash-4.2$ vim /data/apps/pgsql/13/data/pg_hba.conf
# IPv4 local connections:
host all all all md5
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5 # 重载配置
-bash-4.2$ export PGPORT=5432
-bash-4.2$ export PGDATE=postgres
-bash-4.2$ export PGDATA=/data/apps/pgsql/13/data
-bash-4.2$ export PGUSER=postgres
-bash-4.2$ vim /etc/profile
-bash-4.2$ source /etc/profile
-bash-4.2$ pg_ctl reload
server signaled
-bash-4.2$ exit
logout
3、创建新用户:
如上所述,先切换到Linux用户postgres,并执行psql:
[root@dev-predictionio-206 data]# su - postgres
Last login: Mon Sep 6 13:57:07 CST 2021 on pts/4
-bash-4.2$ psql
psql (13.4)
Type "help" for help. postgres=#
# 现在位于数据库提示符下。
# 创建数据库新用户,如 dbuser:
postgres=# CREATE USER wangshuangxi WITH PASSWORD '123456';
CREATE ROLE
postgres=# CREATE USER dbuser WITH PASSWORD '*****';
注意:
语句要以分号结尾。
密码要用单引号括起来。
3、创建用户数据库,如exampledb:
postgres=# CREATE DATABASE exampledb OWNER dbuser;
4、将exampledb数据库的所有权限都赋予dbuser:
postgres=# GRANT ALL PRIVILEGES ON DATABASE exampledb TO dbuser;
5、使用命令 \q 退出psql:
postgres=# \q 6、创建Linux普通用户,与刚才新建的数据库用户同名,如 dbuser: $ sudo adduser dbuser $ sudo passwd dbuser 7、以dbuser的身份连接数据库exampledb: $ su - dbuser Password:
Last login: Wed Mar 1 11:52:07 CST 2017 on pts/ [dbuser@master ~]$ psql -d exampledb
4、开启远程访问:
# 修改配置文件,添加监听地址,改为*
vim postgresql.conf
listen_addresses = '*' # 修改pg_hba.conf,添加远程主机地址,放在第一行:允许任意用户从任意机器上以密码方式访问数据库,把下行添加为第一条规则:
host all all 0.0.0.0/0 md5 # 重启服务:
sudo systemctl restart postgresql-13.service
5、通过navicat连接访问:

连接成功如下:

三、安装pgadmin图形管理界面
参考:https://www.cnblogs.com/whitebai/p/13094540.html
查看官网安装方式:https://www.pgadmin.org/download/pgadmin-4-rpm/
我们选择rpm包的安装方式:(也可以选择python或者其他方式)
# 安装基础repo包
sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm # To install pgAdmin, run one of the following commands:
# Install for both desktop and web modes.
# 同时安装桌面版与web版
sudo yum install pgadmin4 # Install for desktop mode only.
sudo yum install pgadmin4-desktop # Install for web mode only.
# 只安装web版,(我们只需要安装这个就可以了)
sudo yum install pgadmin4-web
安装过程有点长,可能需要输入y确认。
安装完成后:启动web初始化配置:
Finally, if you have installed pgadmin4 or pgadmin4-web, run the web setup script to configure the system to run in web mode:
# sudo /usr/pgadmin4/bin/setup-web.sh
Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
NOTE: Configuring authentication for SERVER mode. Enter the email address and password to use for the initial pgAdmin user account: Email address: ops@lgitt.com
Password:
Retype password:
pgAdmin 4 - Application Initialisation
====================================== Creating storage and log directories...
Configuring SELinux...
setsebool: SELinux is disabled.
setsebool: SELinux is disabled.
The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? y
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Apache successfully enabled.
Apache successfully started.
You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4
输入地址:http://192.168.90.206/pgadmin4/
如下:

登录后如图所示:

四、安装插件mysql-fdw (可选)
网上很多编译安装的方法,官网也是编译安装的,编译安装依赖包太多,因为只是插件,这里直接采用yum安装:
yum安装mysql-fdw
# 首先查找一下fdw
yum search postgresql|grep fdw
# 找到了对应包名,安装:
yum install mysql_fdw_13
源码编译安装参考:https://www.cnblogs.com/funnyzpc/p/14223167.html
准备libmysqlclient
注意:若mysql与postgresql在同一台linux机上,则无需安装mysql工具,请略过本段
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.22-linux-glibc2.17-x86_64-minimal.tar.xz
tar -xf mysql-8.0.22-linux-glibc2.17-x86_64-minimal.tar.xz
mv mysql-8.0.22-linux-glibc2.17-x86_64-minimal /data/apps/mysql-client
chown -R mysql:mysql /data/apps/mysql-client
配置环境变量
- 配置文件
vi /etc/profile
- 添加mysql环境变量
# mysql-client
export MYSQL_HOME=/data/apps/mysql-client
export PATH=$PATH:$MYSQL_HOME/bin
export LD_LIBRARY_PATH=$PG_HOME/lib:$MYSQL_HOME/lib:$LD_LIBRARY_PATH
确保pgsql的环境变量存在:
# pgsql
export PG_HOME=/usr/pgsql-13/
export PATH=$PATH:$PG_HOME/bin
刷新配置
source /etc/profile
下载并编译mysql_fdw
下载地址:
https://github.com/EnterpriseDB/mysql_fdw/releases
tar xf mysql_fdw-REL-2_6_0.tar.gz
cd mysql_fdw-REL-2_6_0
make USE_PGXS=1
make USE_PGXS=1 install
编译报错:
# make USE_PGXS=1
Makefile:39: /usr/pgsql-13/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
Makefile:44: *** PostgreSQL 9.6, 10, 11, 12, or 13 is required to compile this extension. Stop.

解决办法:
yum install postgresql13-devel -y
如果遇到依赖报错:
--> Finished Dependency Resolution
Error: Package: postgresql13-devel-13.4-1PGDG.rhel7.x86_64 (pgdg13)
Requires: llvm-toolset-7-clang >= 4.0.1
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
解决办法:
yum install centos-release-scl-rh -y
yum install postgresql13-devel -y
编译完,重启pgsql
systemctl restart postgresql-13.service
postgresql安装部署的更多相关文章
- Linux下apache+phppgadmin+postgresql安装配置
Linux下apache+phppgadmin+postgresql安装配置 操作系统:CentOS 安装包:httpd(首选yum), php(包括php以及php-pgsql,php-mbstri ...
- Greenplum 数据库安装部署(生产环境)
Greenplum 数据库安装部署(生产环境) 硬件配置: 16 台 IBM X3650, 节点配置:CPU 2 * 8core,内存 128GB,硬盘 16 * 900GB,万兆网卡. 万兆交换机. ...
- 在Ubuntu 12.10 上安装部署Openstack
OpenStack系统有几个关键的项目,它们能够独立地安装但是能够在你的云计算中共同工作.这些项目包括:OpenStack Compute,OpenStack Object Storage,OpenS ...
- [转]Centos 7 安装部署 GitLab 服务器
Centos 7 安装部署 GitLab 服务器 转自:https://www.jianshu.com/p/79bfded68899 文前说明 作为码农中的一员,需要不断的学习,我工作之余将一些分析总 ...
- zabbix的安装部署及自定义监控的实现
此篇感谢我的小师傅. 1. Zabbix主要功能和优劣势说明 1. Zabbix主要功能和优劣势说明 1.1 Zabbix主要功能: 1)Application monitoring 应用监控 数据库 ...
- ubuntu14.04, Cloudera Manager 5.11.1, cdh5.11.1 postgresql离线部署
最近一段时间团队接到的项目需要处理的数据量非常大,之前的处理方式难以满足现有需求.最近两周前前后后折腾了不少,在搭建了hadoop+hbase+hive+spark的一个集群后,由于感觉管理和监控太麻 ...
- Sqoop-1.4.6安装部署及详细使用介绍
之所以选择Sqoop1是因为Sqoop2目前问题太多.无法正常使用,综合比较后选择Sqoop1. Sqoop1安装配置比较简单 一.安装部署 (1).下载安装包 下载地址:http://archive ...
- CentOS7.4安装部署openstack [Liberty版] (一)
一.OpenStack简介 OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. OpenStack是一个 ...
- [转帖]VMware Vsphere 6.0安装部署 (三) vCenter Server安装
VMware Vsphere 6.0安装部署 (三) vCenter Server安装 2016年08月29日 14:59:14 dAng1r0Us 阅读数:72942 版权声明:本文为博主原创文 ...
随机推荐
- Luogu P2024 [NOI2001]食物链 | 并查集
题目链接 思路:并查集,因为一开始我们并不知道每一只动物是哪一个种类的,所以我们干脆建立三倍于n的空间,1~n这三分之一用来存第i只动物是A的情况,n+1~2n这三分之一用来存第(i-n)只动物是B的 ...
- 51nod_1003 阶乘后面0的数量(求N!中5的个数,数论)
题意: n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720,720后面有1个0. Input 一个数N(1 <= N <= 10^9) OutPut 输出0的数 ...
- hdu 4288 Coder (线段树+离线)
题意: 刚开始有一个空集合.有三种操作: 1.往集合中加入一个集合中不存在的数 x 2.从集合中删除一个已经存在的数 x 3.计算集合的digest sum并输出. digest sum求 ...
- 恶意代码の奇客pdf分析
目录 恶意代码の奇客pdf分析 奇客PDF安装包分析 静态分析基础技术 上传杀毒网 查壳 编译时间 导入表分析 资源查看 动态分析基础技术 Process Monitor监控 Process Expl ...
- PicGo+Gitee(码云)中的404错误解决方案
今天在用PicGo配置Gitee时,出现了404问题,记录一下解决方案. 安装与配置 PicGo默认是不支持Gitee的,只能通过安装插件来进行支持.我这里安装的插件是Gitee. 在图床设置---& ...
- k3s单机版安装部署 附一键安装脚本
作者:SRE运维博客 博客地址: https://www.cnsre.cn/ 文章地址:https://www.cnsre.cn/posts/211109907029/ 相关话题:https://ww ...
- go条件语句
1. if else package main import "fmt" func main(){ a :=123 if a>100{ fmt.prinln("大于 ...
- HVV奇兵—网页防篡改系统在网络安全实战演习中的妙用(上)
近年来,网络安全实战演习受到各大关基单位的高度关注.对于网络安全实战演习的防守方,防火墙.Web应用防火墙.态势感知.EDR.蜜罐等都是较为常见的防守工具,而网页防篡改系统则鲜有露脸的机会-- 很多人 ...
- 关于 RocketMQ 事务消息的正确打开方式 → 你学废了吗
开心一刻 昨晚和一哥们一起吃夜宵,点了几瓶啤酒 不一会天空下起了小雨,哥们突然道:糟了 我:怎么了 哥们:外面下雨了,我老婆还在等着我去接她 他给了自己一巴掌,说道:真他妈不是个东西 我心想:哥们真是 ...
- Django笔记&教程 3-1 模板(Template)基础
Django 自学笔记兼学习教程第3章第1节--模板(Template)基础 点击查看教程总目录 1 介绍 模板文件:让Django能够自动生成html代码 作为一个web框架,Django需要需要在 ...