Thingworx高可用集群部署(二)-PG数据库安装

目录

服务器配置

关闭防火墙

配置内核参数

Limit参数

配置YUM源

安装Linux工具

修改主机名

创建主机用户

PG部署

创建目录

环境变量

修改目录

初始化数据库

服务启动

验证


主机: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;

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值