目录
主机:10.10.10.71(主)、10.10.10.72(备)、10.10.10.73(级联备份) 、10.10.10.101(vip)
服务器配置
关闭防火墙
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
配置内核参数
cat >> /etc/sysctl.conf <<EOF
#define
net.ipv4.tcp_syncookies = 1
fs.file-max = 1000000
vm.swappiness=10
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.tcp_max_syn_backlog = 8096
net.ipv4.ip_local_port_range = 1024 65000 # not for k8s
EOF
/sbin/sysctl -p
Limit参数
cat >>/etc/security/limits.conf<<EOF
root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
sed -i 's/4096/65535/' /etc/security/limits.d/20-nproc.conf
配置YUM源
vi /etc/yum.repos.d/epel.repo
[base]
name=CentOS-$releasever-Base-mirrors.trinasolar.com
failovermethod=priority
baseurl=http://mirrors.trinasolar.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.trinasolar.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever-Updates-mirrors.trinasolar.com
failovermethod=priority
baseurl=http://mirrors.trinasolar.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.trinasolar.com/centos/RPM-GPG-KEY-CentOS-7
安装Linux工具
yum install -y sysstat-*x86_64
yum install -y unzip
yum install -y gzip
yum install -y zip
yum install -y tar
yum install -y wget
yum install -y lrzsz
yum install -y twm
yum install -y xterm
yum install -y xhost
yum install -y pixman
yum install -y pixman-devel
yum install -y libXfont
yum install -y fio
yum install -y ntp
yum install -y telnet
yum install -y bc
yum install -y dos2unix
yum install -y net-tools
yum install -y iperf
yum install -y iftop
yum install -y iotop
yum install -y psmisc
yum install -y lsof
yum install -y nethogs
yum install -y htop
yum install -y wget
修改主机名
hostnamectl --static set-hostname testpg01
cat >> /etc/hosts << EOF
10.10.10.71 testpg01
10.10.10.72 testpg02
10.10.10.73 testpg03
EOF
创建主机用户
useradd postgres && echo 'Postgres#2024' | passwd --stdin postgres
sed -i 'N;100a\postgres ALL=(ALL) ALL' /etc/sudoers
chage -M 99999 postgres
passwd postgres
PG部署
下载最新版PostgreSQL
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql12-server postgresql12-contrib -y
创建目录
生产数据库文件通常存储在非操作系统磁,在每个 PostgreSQL 节点上创建以下文件夹位置。
mkdir /data/pg_data -p
chown -R postgres:postgres /data/pg_data
chmod 750 /data/pg_data -R
环境变量
PostgreSQL 数据库将位于每个 PostgreSQL 节点上的/db/postgres下。在初始化数据库之前,需要先将 postgres 用户配置文件调整到新位置。
cat > /etc/profile.d/postgresql12.sh << EOF
#!/usr/bin/env bash
export PGDATA=/data/pg_data
export PATH=\$PATH:/usr/pgsql-12/bin
EOF
source /etc/profile.d/postgresql12.sh
修改目录
返回具有 sudo 权限的用户并修改 PostgreSQL 服务中的 PGDATA 参数。编辑postgresql-12.service文件
vi /usr/lib/systemd/system/postgresql-12.service
[Service]
Environment=PGDATA=/data/pg_data/
初始化数据库
/usr/pgsql-12/bin/postgresql-12-setup initdb
服务启动
sudo systemctl reload
sudo systemctl enable postgresql-12.service
sudo systemctl start postgresql-12
sudo systemctl stop postgresql-12
sudo systemctl status postgresql-12
验证
sudo -u postgres psqlshow data_directory;