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 P2982 [USACO10FEB]慢下来 Slowing down | dfs序、线段树
题目链接 题目大意: 有一棵N个结点树和N头奶牛,一开始所有奶牛都在一号结点,奶牛们将按从编号1到编号N的顺序依次前往自己的目的地,求每头奶牛在去往自己目的地的途中将会经过多少已经有奶牛的结点. 题解 ...
- Linux题目学习
一.填空题: 1. 在Linux系统中,以 文件 方式访问设备 . 2. Linux内核引导时,从文件/etc/fstab 中读取要加载的文件系统. 3. Linux文件系统中每个文件用 i节点来标识 ...
- AndroidStudio中debug.keystore文件不存在解决办法
Android项目丢失了debug.keystore,直接重新生存一个key. 在cmd下,进入C:\Users\Administrator\.android目录执行命令如下: keytool -g ...
- docker 加入域名
先运行docker镜像 # 进入 docker 容器 mynginx 是容器名 docker exec -i -t mynginx /bin/bash #安装vim apt-get install v ...
- 单自由度系统中质量、阻尼和刚度变化对频率响应函数(FRF)影响图的绘制
作者:赵兵 日期:2020-02-17 目录 单自由度系统中质量.阻尼和刚度变化对频率响应函数(FRF)影响图的绘制 1. 背景 2. VISIO绘制 3. Matlab绘制 ...
- PyCharm Django Python 开发环境配置 详细教程
PyCharm Django Python 开发环境配置 详细教程 1. Python 下载及安装 (1)根据需要的版本去 Python 官网(https://www.python.org/downl ...
- vs Code配置C++运行和调试环境以及相关问题
vs Code配置C++运行和调试环境以及相关问题 第一步:下载c++插件 第二步:安装编译.调试环境 如果没有Dev-C++下载MinGW 下载地址:https://sourceforge.net/ ...
- Linux NameSpace (目录)
1. User Namespace 详解 2. Pid Namespace 详解 3. Mnt Namespace 详解 4. UTS Namespace 详解 5. IPC Namespace 详解 ...
- Veeam Backup & Replication 10.0.0.4461安装部署(包含补丁)
Veeam Backup & Replication 是一款数据保护软件,为VMware 和Hyper-V 虚拟机.物理与云环境提供了备份.复制与恢复选项.如有需要请去官方购买正版授权:htt ...
- 力扣 - 剑指 Offer 52. 两个链表的第一个公共节点
题目 剑指 Offer 52. 两个链表的第一个公共节点 思路1(栈) 若两个链表相遇,则从它开始相遇的地方到链表末尾应该都是相同的,那么我们可以将两个链表分别放入两个栈中,然后依次循环比较两个栈顶的 ...