银河麒麟V10——Postgres-12.5主从编译安装
一、配置免密登录
#生成私钥
[root@localhost lib]# vim /etc/profile
[root@localhost lib]# cd
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:lHsJtF23Wf/zZHWv4SzBR7Iml6K2Kyws/NIJHcf4IBA root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|E. . . . .|
|. . + . . +.|
| . o = . . + +|
| . + o. o o = =|
| o = S = B o.=|
| . . . o = = =o|
| . + o o . + .|
| + = o. . . |
| +.. .o. |
+----[SHA256]-----+
#拷贝密钥到其他机器(例举一台)
[root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.65.132
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.65.132 (192.168.65.132)' can't be established.
ECDSA key fingerprint is SHA256:MaIR4AJ02WMecACcn4Kw8wM+oZJFTbf/zdCIkR92ez4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed # 试图用新的密钥登录,以过滤掉任何已经安装的密钥
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys # 1个密钥仍待安装——如果现在提示您安装新的密钥
Authorized users only. All activities may be monitored and reported. # 仅限授权用户使用。所有活动都可以被监测和报告。
root@192.168.65.132's password:
root@192.168.65.132's password:
Connection closed by 192.168.65.132 port 22
二、解压并安装postgresql-12.5
1、#安装包
[root@localhost ~]# yum install -y openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel install perl-ExtUtils-Embed readline readline-devel zlib zlib-devel gettext gettext-devel bison flex gcc gcc-c++ readline-devel
上次元数据过期检查:0:23:02 前,执行于 2023年03月03日 星期五 10时19分26秒。 软件包 openssl-1:1.1.1f-15.p06.ky10.x86_64 已安装。 软件包 openssl-devel-1:1.1.1f-15.p06.ky10.x86_64 已安装。 软件包 pam-1.4.0-8.p03.se.03.ky10.x86_64 已安装。 软件包 pam-devel-1.4.0-8.p03.se.03.ky10.x86_64 已安装。 软件包 libxml2-2.9.10-25.ky10.x86_64 已安装。 软件包 libxml2-devel-2.9.10-25.ky10.x86_64 已安装。 软件包 libxslt-1.1.34-4.ky10.x86_64 已安装。 软件包 perl-4:5.28.3-7.se.01.ky10.x86_64 已安装。 软件包 perl-devel-4:5.28.3-7.se.01.ky10.x86_64 已安装。 未找到匹配的参数: install 软件包 perl-4:5.28.3-7.se.01.ky10.x86_64 已安装。 软件包 readline-8.0-3.ky10.x86_64 已安装。 软件包 readline-devel-8.0-3.ky10.x86_64 已安装。 软件包 zlib-1.2.11-18.ky10.x86_64 已安装。 软件包 zlib-devel-1.2.11-18.ky10.x86_64 已安装。 软件包 gettext-0.21-4.ky10.x86_64 已安装。 软件包 gettext-devel-0.21-4.ky10.x86_64 已安装。 软件包 bison-3.6.4-2.ky10.x86_64 已安装。 软件包 flex-2.6.4-3.ky10.x86_64 已安装。 软件包 gcc-7.3.0-20220207.45.p01.ky10.x86_64 已安装。 软件包 gcc-c++-7.3.0-20220207.45.p01.ky10.x86_64 已安装。 错误:没有任何匹配: install
2、上传postgresql-12.5.tar.gz安装包,我的放在了/root/postgresql-12.5文件夹下
3、解压
[root@localhost ~]# tar -zvxf postgresql-12.5.tar.gz # 解压并得到文件夹
4、创建文件路径,并将解压后的文件复制到该路径下
[root@localhost ~]# mkdir -p /export/servers/app/postgresql-12.5 # 创建文件路径,并将解压后的文件复制到该路径下
[root@localhost ~]# cd postgresql-12.5
5、配置并安装make
[root@localhost postgresql-12.5]# ./configure --prefix=/export/servers/app/postgresql-12.5 &&make &&make install # 打开并安装make
表示安装完成
6、添加环境变量:wq保存退出。
[root@localhost postgresql-12.5]# vim /etc/profile
export PGHOME=/export/servers/app/postgresql-12.5 export PGDATA=/export/servers/data/pgsql/ export PATH=$PGHOME/bin:$PATH export LANG=en_US.utf8 export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
#刷新并使文件生效
[root@localhost postgresql-12.5]# source /etc/profile
7、创建数据目录
useradd postgres
mkdir -p /export/servers/data/pgsql/
chown postgres:postgres /export/servers/data/pgsql/
8、初始化数据库
[root@localhost postgresql-12.5]# su - postgres # 切换用户 进入相应路径: [postgres@localhost postgresql-12.5]$ cd /export/servers/app/postgresql-12.5/bin
使用initdb启动
[postgres@localhost bin]$ /export/servers/app/postgresql-12.5/bin/initdb -D /export/servers/data/pgsql/
9、修改监听端口
[postgres@localhost bin]$ vim /export/servers/data/pgsql/postgresql.conf
listen_addresses = '*'
10、启动pg_ctl
[postgres@localhost bin]$ /export/servers/app/postgresql-12.5/bin/pg_ctl -D /export/servers/data/pgsql/ -l logfile start waiting for server to start..../bin/sh: logfile: Permission denied stopped waiting pg_ctl: could not start server Examine the log output.
# 启动服务
[postgres@localhost bin]$ pg_ctl start
waiting for server to start....2023-03-03 11:27:58.887 CST [41939] LOG: starting PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
2023-03-03 11:27:58.888 CST [41939] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-03-03 11:27:58.888 CST [41939] LOG: listening on IPv6 address "::", port 5432
2023-03-03 11:27:58.890 CST [41939] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2023-03-03 11:27:58.908 CST [41940] LOG: database system was shut down at 2023-03-03 11:12:37 CST
2023-03-03 11:27:58.911 CST [41939] LOG: database system is ready to accept connections
done
server started
11、验证5432端口已经开启
[postgres@localhost bin]$ netstat -anp | grep 5432
12、登录并修改postgres密码
[root@localhost pgsql]# su - postgres # 切换用户 [postgres@localhost pgsql]# psql # 登录数据库 alter user postgres with password 'postgres'; # 修改用户密码为postgres exit
#修改为md5表示用密码登录,如果为trust表示不需要密码,
[postgres@localhost bin]$ cd /export/servers/data/pgsql/
[postgres@localhost bin]$ vim pg_hba.conf
把trust修改成md5,保存
修改配置文件后需要重启
[postgres@localhost pgsql]$ /export/servers/app/postgresql-12.5/bin/pg_ctl -D /export/servers/data/pgsql/ -l logfile restart
13、验证密码是否修改成功
密码修改前的状态如下
密码修改后的状态如下:
[postgres@localhost pgsql]$ psql Password for user postgres: # 输入修改的密码:这里是postgres
三、编译安装proj-6.2.1
我的文件位置:/root/postgresql-12.5
[root@localhost postgresql-12.5]# tar -zvxf proj-6.2.1.tar.gz # 解压
[root@localhost postgresql-12.5]# mv proj-6.2.1 /usr/local # 把proj-6.2.1文件移到/usr/local
[root@localhost local]# cd proj-6.2.1
[root@localhost proj-6.2.1]# ./configure --prefix=/usr/local/proj-6.2.1
安装make 时间较长预计20分钟
[root@localhost proj-6.2.1]# make &&make install
四、编译安装geos-3.7.4
我的文件位置:/root/postgresql-12.5
[root@localhost postgresql-12.5]# tar -xf geos-3.7.4.tar.bz2 # 解压
[root@localhost postgresql-12.5]# mv geos-3.7.4 /usr/local # 移动到/usr/local/下
[root@localhost local]# cd geos-3.7.4 # 打开目录
[root@localhost geos-3.7.4]# ./configure --prefix=/usr/local/geos-3.7.4 # 配置
[root@localhost geos-3.7.4]# make && make install # 安装make安装时间较长预计15分钟
五、编译安装gdal-3.1.1
我的文件位置:/root/postgresql-12.5
[root@localhost postgresql-12.5]# tar -xf gdal-3.1.1.tar.gz /uar/local # 解压
[root@localhost postgresql-12.5]# mv gdal-3.1.1 /usr/local # 移动到/usr/local/下
[root@localhost local]# cd gdal-3.1.1 # 打开gdal-3.1.1
[root@localhost gdal-3.1.1]# ./configure --prefix=/usr/local/gdal-3.1.1
六、编译安装postgis-3.0.5
我的文件位置:/root/postgresql-12.5
[root@localhost postgresql-12.5]# tar -xf postgis-3.0.5.tar.gz # 解压
[root@localhost postgresql-12.5]# mv postgis-3.0.5 /usr/local # 移动到/usr/local/下
cd postgis-3.0.5 # 打开目录
# 配置
[root@localhost postgis-3.0.5]# ./configure --prefix=/export/servers/app/postgresql-12.5 --with-pgconfig=/export/servers/app/postgresql-12.5/bin/pg_config --with-projdir=/usr/local/proj-6.2.1 --with-geosconfig=/usr/local/geos-3.7.4/bin/geos-config --with-gdalconfig=/usr/local/gdal-3.1.1/bin/gdal-config