PG初始环境之——Linux 系统配置
适用于: Oracle Linux 7.9.x、Centos Linux 7.9.x、Redhat Linux 7.9.x
一、用户环境变量
# 禁止DNS解析,提高ssh连接速度
sed -i 's/^#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
# 配置/etc/hosts
sed -i '/^# HOSTSBEGIN/,/^# HOSTSEND/d' /etc/hosts
echo '' >> /etc/hosts
echo '# HOSTSBEGIN' >> /etc/hosts
echo '192.168.192.101 pgnode101' >> /etc/hosts
echo '192.168.192.102 pgnode102' >> /etc/hosts
echo '192.168.192.103 pgnode103' >> /etc/hosts
echo '192.168.192.104 pgnode104' >> /etc/hosts
echo '# HOSTSEND' /etc/hosts >> /etc/hosts
# 合并连续空行
awk 'begin{b=0}{if($0==""){b=1;next;} if(b){print "\n"$0;b=0;} else print;}' /etc/hosts > hosts.tmp
cat hosts.tmp > /etc/hosts
rm -f hosts.tmp
# 配置~/.bash_profile环境变量
sed -i '/^# LANGBEGIN/,/^# LANGEND/d' ~/.bash_profile
echo '' >> ~/.bash_profile
echo '# LANGBEGIN' >> ~/.bash_profile
echo 'export LANG=en_US.UTF8' >> ~/.bash_profile
echo '# LANGEND' >> ~/.bash_profile
# 合并连续空行
awk 'begin{b=0}{if($0==""){b=1;next;} if(b){print "\n"$0;b=0;} else print;}' ~/.bash_profile > profile.tmp
cat profile.tmp > ~/.bash_profile
rm -f profile.tmp
# sed -ri 'h;n;:a;H;n;$!ba;g;s/(\n){2,}/\n\n/g' ~/.bash_profile
# sed -i '${/^\s*$/d}' ~/.bash_profile # 删除文件末尾空行
source ~/.bash_profile
二、配置yum源(从本地ISO)
注意:要提前先挂载本地iso镜像到主机
mount /dev/cdrom /mnt
cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/
echo "[EL7]" >> localsource.repo
echo "name = linux 7.9 dvd" >> localsource.repo
echo "baseurl=file:///mnt" >> localsource.repo
echo "gpgcheck=0" >> localsource.repo
echo "enabled=1" >> localsource.repo
yum list
systemctl set-default multi-user.target
systemctl get-default
三、内核参数
echo "vm.swappiness = 10" >> /etc/sysctl.conf
echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "fs.file-max = 6815744" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf
echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf
echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.wmem_max = 1048586" >> /etc/sysctl.conf
# 信号量及共享内存,可以使用ipcs -l来获取
# semaphore为每个进程通讯需要的信号灯或者IPC标志
# 每个连接的process都要分配一个semaphore
# 所以 semaphore的设置跟process的数量有关系
echo "kernel.sem = 512 262144 512 4096" >> /etc/sysctl.conf
# kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI
# 512G好配置:4096 2147483647 2147483646 512000
# 1G差配置:250 512000 100 2048
# 2G RAM: 512 262144 512 4096
# SEMMSL:每个信号量set中信号量最大个数
# 设置:最小250;对于processes参数设置较大的系统,建议设置为processes+10
# SEMMNS:linux系统中信号量最大个数
# 设置:最少32000;SEMMSL * SEMMNI
# SEMOPM:semop系统调用允许的信号量最大个数
# 设置:最少100;或者等于SEMMSL
# SEMMNI:linux系统信号量set最大个数
# 设置:最少128
# 查看信号量设置:cat /proc/sys/kernel/sem
# kernel.shmmax 单个共享内存段大小,建议为内存的一半,单位是byte
# kernel.shmall 控制全部共享内存页数,系统所有共享内存段相加的大小限制,建议为内存的80%,例如:64G*80%/4k 即是页数
# kernel.shmmni 共享内存段的最大数量,shmmni缺省值4096 足够
# shmmax(bytes) = shmmni(page size, default 4k) * shmall (page的个数)
# 2G RAM
echo "kernel.shmmax = 1073741824" >> /etc/sysctl.conf
echo "kernel.shmall = 419430" >> /etc/sysctl.conf
echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
sysctl -p
四、禁用selinux和防火墙
sed -ri 's/(^SELINUX=).*/\1disabled/' /etc/selinux/config
cat /etc/selinux/config
setenforce 0
systemctl disable --now firewalld.service
systemctl status firewalld.service
五、设置资源限制
sed -i '$ a\
session required pam_limits.so' /etc/pam.d/login
cat /etc/pam.d/login
echo "* - nproc unlimited" > /etc/security/limits.d/90-nproc.conf
echo "* soft nproc unlimited" >> /etc/security/limits.conf
echo "* hard nproc unlimited" >> /etc/security/limits.conf
echo "* soft nofile 16384" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "* soft stack unlimited" >> /etc/security/limits.conf
echo "* hard stack unlimited" >> /etc/security/limits.conf
cat /etc/security/limits.conf
rm -f /etc/security/limits.d/20-nproc*
六、关闭透明大页和numa
sed -ri '/GRUB_CMDLINE_LINUX=/s/(rhgb).*(quiet)/\1 numa=off transparent_hugepage=never \2/' /etc/default/grub
cat /etc/default/grub
# 然后执行:
grub2-mkconfig -o /etc/grub2.cfg
numastat
numactl --show
numactl --hardware
shutdown -r now
# reboot
*** 你必须十分努力,才能看起来毫不费力 ***