安装MySQL-操作系统配置
一、降低 swap 使用权重
Linux内核3.5-rc1及更高版本建议swappiness设置为1;
Linux内核低于3.5-rc1版本建议swappiness设置为0
#检查服务器内核版本
shell> uname -r
#内核版本为3.5-rc1或更高版本
shell> vim /etc/sysctl.conf
vm.swappiness = 1
#内核版本低于3.5-rc1版本
shell> vim /etc/sysctl.conf
vm.swappiness = 0
# 保存后使其生效
shell> sysctl -p
二、ulimit 设置
修改OS用户mysql资源限制:
cp /etc/security/limits.conf /etc/security/limits.conf.`date +%Y%m%d`
echo "mysql soft nofile 65535
mysql hard nofile 65535
mysql soft nproc 65535
mysql hard nproc 65535
" >> /etc/security/limits.conf
三、配置ntp服务
根据实际的 ntp 服务器地址修改配置
shell> vim /etc/ntp.conf
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
# 改为
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 100.65.0.1 iburst
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
## 启动服务:
# 先手工对时一下:
shell> ntpdate 100.65.255.1
# redhat6/centos6
shell> service ntpd start
shell> chkconfig ntpd on
# redhat7/centos7
shell> systemctl start ntpd
shell> systemctl enable ntpd
# 注:修改时间后须手动重启crontab,cron的执行时间才会同步
shell> systemctl restart crond
四、检查时区是否为东八区
# 查看时区,如果不是东八区需要按时区进行校准
shell> date -R
Wed, 06 Mar 2019 14:17:16 +0800
# 设置软连接,进行时区校准
shell> ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 注:修改时间后须手动重启crontab,cron的执行时间才会同步
shell> systemctl restart crond
五、关闭 iptables 及 selinux
服务器上的 iptables 应该是关闭的,否则规则可能对数据库服务造成影响,需要与客户确认
# 关闭iptables
# redhat6/centos6
shell> /etc/init.d/iptables stop
shell> chkconfig iptables off
# redhat7/centos7
shell> systemctl stop firewalld.service
shell> systemctl disable firewalld.service
# 关闭selinux
# 临时关闭
shell> setenforce 0
# 永久关闭
shell> vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
六、关闭numa
改 grub.conf
1、对于RHEL/CentOS 6:
在 /boot/grub/grub.conf 文件中修改 kernel 行(添加numa=off):
shell> vi /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel_vm-210/root rd.lvm.lv=rhel_vm-210/swap vconsole.font=latarcyrheb-sun16 crashkernel=auto vconsole.keymap=us rhgb quiet numa=off
2、对于RHEL 7:
2.1、在/etc/default/grub 文件中修改 kernel 行:
shell> vi /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel_vm-210/root rd.lvm.lv=rhel_vm-210/swap vconsole.font=latarcyrheb-sun16 crashkernel=auto vconsole.keymap=us rhgb quiet numa=off
2.2、RHEL7/CentOS7 必须要重建 GRUB 配置文件才能生效:
shell> grub2-mkconfig -o /etc/grub2.cfg
七、关闭透明大页
1、查询系统是否开启了 THP 命令
shell> cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
shell> cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
如果括号中的是 always 表示开启了,never 则表示未开启
2、实时生效关闭方案
shell> echo never >> /sys/kernel/mm/transparent_hugepage/enabled
shell> echo never >> /sys/kernel/mm/transparent_hugepage/defrag
3、写进配置文件(需要重启)
在/etc/rc.local中增加如下内容
if test -f /sys/kernel/mm/transparent_hugepage/enabled;
then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag;
then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
4、执行以下操作,使rc.local可以在系统引导期间执行
shell> chmod +x /etc/rc.d/rc.local
grubby --update-kernel=ALL --args="transparent_hugepage=never"