环境
代码语言:javascript复制docker rm -f lhruosv201060apg
docker run -itd --name lhruosv201060apg -h lhruosv201060apg
-v /sys/fs/cgroup:/sys/fs/cgroup
--restart=always
--privileged=true lhrbest/uos_server:v20-1060a-v3.0
/usr/sbin/init
[root@lhrdb ~]# docker exec -it lhruosv201060apg bash
[root@lhruosv201060apg /]$
[root@lhruosv201060apg /]$ uosinfo
#################################################
Release: UOS Server release 20 (kongzi)
Kernel : 3.10.0-1160.95.1.el7.x86_64
Build : UOS Server 20 (1060a) 20230606 amd64
#################################################
[root@lhruosv201060apg /]$
安装
代码语言:javascript复制dnf install -y cmake make gcc gcc-c perl readline readline-devel zlib zlib-devel
perl python36 tcl openssl ncurses-devel openldap pam perl-IPC-Run libicu-devel libarchive libzstd
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/pgdg-redhat-all.repo
sed -i 's/repo_gpgcheck = 1/repo_gpgcheck = 0/g' /etc/yum.repos.d/pgdg-redhat-all.repo
-- 国产OS,需要修改yum源的配置
sudo sed -i 's/$releasever/8/g' /etc/yum.repos.d/pgdg-redhat-all.repo
-- 若是CentOS8和9,则需要禁用内置的PostgreSQL模块,否则会报错 All matches were filtered out by modular filtering for argument
sudo dnf -qy module disable postgresql
yum repolist enabled | grep pgdg
-- 安装pg15和16版本
yum install -y postgresql15 postgresql15-server postgresql15-contrib postgresql15-libs postgresql15-devel
yum install -y postgresql16 postgresql16-server postgresql16-contrib postgresql16-libs postgresql16-devel
# 最终一共需要5个rpm包
[root@lhruosv201060apg ~]$ rpm -aq| grep postgres | grep 15
postgresql15-server-15.5-2PGDG.rhel8.x86_64
postgresql15-devel-15.5-2PGDG.rhel8.x86_64
postgresql15-15.5-2PGDG.rhel8.x86_64
postgresql15-contrib-15.5-2PGDG.rhel8.x86_64
postgresql15-libs-15.5-2PGDG.rhel8.x86_64
[root@lhruosv201060apg ~]$ rpm -aq| grep postgres | grep 16
postgresql16-16.1-4PGDG.rhel8.x86_64
postgresql16-libs-16.1-4PGDG.rhel8.x86_64
postgresql16-server-16.1-4PGDG.rhel8.x86_64
postgresql16-devel-16.1-4PGDG.rhel8.x86_64
postgresql16-contrib-16.1-4PGDG.rhel8.x86_64
其它配置
以pg16为例:
代码语言:javascript复制-- 环境变量
echo "export PATH=/usr/pgsql-16/bin:$PATH" >> /etc/profile
locale -a | grep zh_CN
/usr/pgsql-16/bin/postgresql-16-setup initdb
-- 重新初始化中文 --locale=en_US.utf8
su - postgres
rm -rf /var/lib/pgsql/16/data/
/usr/pgsql-16/bin/initdb -D /var/lib/pgsql/16/data -E UTF8 --locale=zh_CN.UTF-8 -U postgres --data-checksums
systemctl enable postgresql-16
systemctl restart postgresql-16
systemctl status postgresql-16
-- 本地登陆
su - postgres
psql
-- 安装插件
create extension pageinspect;
create extension pg_stat_statements;
select * from pg_extension ;
select * from pg_available_extensions order by name limit 2;
-- 修改postgres密码
alter user postgres with password 'lhr'; 或 password
create user lhr with password 'lhr' superuser;
select * from pg_tables;
select version();
-- 开放防火墙
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-port
systemctl status firewalld.service
systemctl stop firewalld.service
echo 'export LANG=en_US.UTF-8' >> /etc/profile
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
setenforce 0
-- 配置允许PG远程登录,注意版本:
cat >> /var/lib/pgsql/16/data/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
unix_socket_directories='/var/lib/pgsql/16/data'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOF
cat << EOF > /var/lib/pgsql/16/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all ::1/128 trust
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
host replication all 0.0.0.0/0 md5
EOF
systemctl restart postgresql-16
systemctl status postgresql-16
mkdir -p /home/postgres
chown postgres.postgres /home/postgres -R
sed -i 's|/var/lib/pgsql|/home/postgres|' /etc/passwd
echo "lhr" |passwd --stdin postgres
echo "postgres ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
cat > /home/postgres/.bash_profile <<"EOF"
export PGPORT=5432
export PGHOME=/usr/pgsql-16
export PGDATA=/var/lib/pgsql/16/data
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.UTF-8
export DATE='date "%Y%m%d%H%M"'
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGPASSWORD=lhr
export PGDATABASE=postgres
export PS1="[u@h W]$ "
EOF
chown postgres.postgres /home/postgres/.bash_profile
systemctl restart postgresql-16
systemctl status postgresql-16
参考
https://www.xmmup.com/dbbao67shiyongyumlaianzhuangpostgresql13-3shujuku.html
https://www.xmmup.com/postgresql-16shujukudegezhonganzhuangfangshihuizongyumbianyidockerdeng.html