1#!/bin/bash
2
3##Configure Linux environment For openGauss
4echo vertica | passwd --stdin root
5sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
6## 1.Disable firewalld service
7systemctl mask firewalld.service
8systemctl disable firewalld.service
9systemctl stop firewalld.service
10echo "Firewalld " `systemctl status firewalld|grep Active`
11echo "1.Disable firewalld service completed."
12echo -e "\n"
13
14## 2.Disable SELINUX
15sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
16setenforce 0
17getenforce
18cat /etc/selinux/config|grep "SELINUX=disabled"
19echo "2.Disable SELINUX completed."
20echo -e "\n"
21
22## 3.检查 pts 是否挂载
23df -Th /dev/pts
24echo "3.Check pts completed."
25echo -e "\n"
26
27## 4.创建用户和组
28groupadd -g 1001 verticadba
29useradd -u 1001 -g verticadba dbadmin
30echo "dbadmin" | passwd dbadmin --stdin
31id dbadmin
32echo "4.Create group and user completed."
33echo -e "\n"
34
35## 5.配置 Disk Readahead
36lsblk
37/sbin/blockdev --setra 8192 /dev/sda
38echo '/sbin/blockdev --setra 8192 /dev/sda' >> /etc/rc.local
39chmod +x /etc/rc.d/rc.local
40echo "5.Set Disk Readahead completed."
41echo -e "\n"
42
43## 6. Configure YUM and Install Packages
44yum install -y gdb mcelog sysstat openssh which dialog chrony expect
45rpm -q gdb mcelog sysstat openssh which dialog chrony expect
46echo "6.Configure YUM and Install Packages completed."
47echo -e "\n"
48
49## 7.配置透明大页
50## 默认为 always
51cat /sys/kernel/mm/transparent_hugepage/enabled
52## 如果不是 always,通过以下命令设置
53echo always > /sys/kernel/mm/transparent_hugepage/enabled
54## 设置开机自启动设置 always
55cat<<EOF>>/etc/rc.local
56if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
57echo always > /sys/kernel/mm/transparent_hugepage/enabled
58fi
59EOF
60## redhat7 或 centos7 需要设置可执行权限
61chmod +x /etc/rc.d/rc.local
62echo "7.Enable transparent_hugepage completed."
63echo -e "\n"
64
65## 8.配置 I/O Scheduler
66cat /sys/block/sda/queue/scheduler
67echo deadline > /sys/block/sda/queue/scheduler
68## 加入开机自启
69echo 'echo deadline > /sys/block/sda/queue/scheduler' >> /etc/rc.local
70chmod +x /etc/rc.d/rc.local
71echo "8.Set I/O Scheduler completed."
72echo -e "\n"
73
74## 9.配置 TZ(TimeZone)
75yum update -y tzdata
76timedatectl set-timezone Asia/Shanghai
77echo "9.Set TZ completed."
78echo -e "\n"
79
80## 10.配置环境变量
81cat<<EOF>>/home/dbadmin/.bash_profile
82export TZ="Asia/Shanghai"
83export LANG=en_US.UTF-8
84EOF
85echo "10.Set Profile completed."
86echo -e "\n"
87
88## 11.关闭 tuned
89systemctl stop tuned.service
90systemctl disable tuned.service
91systemctl status tuned.service
92echo "11.Disable tuned completed."
93echo -e "\n"
94
95
96## 12.配置 swapiness
97cat /proc/sys/vm/swappiness
98echo 0 > /proc/sys/vm/swappiness
99echo vm.swappiness=0 >>/etc/sysctl.conf
100sysctl -p
101echo "12.Disable swappiness completed."
102echo -e "\n"
103
104## 13.禁用 Defrag(碎片整理)
105cat /sys/kernel/mm/transparent_hugepage/defrag
106echo never > /sys/kernel/mm/transparent_hugepage/defrag
107cat<<EOF>>/etc/rc.local
108if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
109echo never > /sys/kernel/mm/transparent_hugepage/defrag
110fi
111EOF
112chmod +x /etc/rc.d/rc.local
113echo "13.Disable Defrag completed."
114echo -e "\n"
115
116## 14.配置 limits.conf
117cat<<EOF>>/etc/security/limits.conf
118dbadmin - nice 0
119dbadmin - nofile 65536
120dbadmin - as unlimited
121dbadmin - fsize unlimited
122dbadmin - nproc 30152
123EOF
124echo "14.Set limits completed."
125echo -e "\n"
126
127## 15.配置 pam.d
128cat<<EOF>>/etc/pam.d/su
129session required pam_limits.so
130EOF
131echo "15.Set pam.d completed."
132echo -e "\n"
133
134## 16.配置 sysctl.conf
135cat<<EOF>>/etc/sysctl.conf
136fs.file-max=65536
137vm.min_free_kbytes=7980
138kernel.pid_max=524288
139vm.max_map_count=65536
140EOF
141sysctl -p
142echo "16.Set sysctl completed."
143echo -e "\n"
144
145## 17. Configure SSH Service
146sed -i '/Banner/s/^/#/' /etc/ssh/sshd_config
147sed -i '/PermitRootLogin/s/^/#/' /etc/ssh/sshd_config
148echo -e "\n" >> /etc/ssh/sshd_config
149echo "Banner none " >> /etc/ssh/sshd_config
150echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
151cat /etc/ssh/sshd_config |grep -v ^#|grep -E 'PermitRoot|Banner'
152echo "17.Configure SSH Service completed."
153echo -e "\n"
154
155## 18.开启 chrony
156systemctl status chronyd
157systemctl enable chronyd
158chronyc tracking
159echo "18.Enable chrony completed."
160echo -e "\n"