MySQL(六) 服务器上线检查流程

MySQL 服务器上线检查流程

1. 操作系统磁盘分区
挂节点分区类型大小用处
/dataxfs根据实际情况而定数据文件使用
2. 主机常用软件检测
  • systat 包提供了常用的iostat,mpstat,sar等常用工具包,需提前安装。
  • gdb 提供一些常用的 debug 工具,比如 gstack,当MySQL hang住时,可使用 pstack ( gstack 的软链)收集信息。
#pstack收集命令如下
pstack `pidof mysqld` > /tmp/pstack.out
#安装常用包
yum install –y  sysstat  gdb  strace
3. 禁止iptables
[root@db ~]# /etc/init.d/iptables stop
[root@db ~]# chkconfig --list|grep iptables
[root@db ~]# chkconfig iptables off
4. 禁止selinux
[root@db ~]# getenforce 0
[root@db ~]# vim /etc/sysconfig/selinux
把SELINUX=enforcing 替换为:
SELINUX=disable
5. 关闭numa
  • 服务器关闭 numa 会影响所有进程,关闭 numa 主要是解决MySQL 服务器 swap 严重以及内存泄漏的问题。需要注意的是 MySQL5.7.9 引入了 innodb_numa_interleave 参数,MySQL自己解决了内存分类策略的问题,前提是服务器支持 numa。也就是说如果使用 MySQL5.7.9 之后的版本,可以不用关闭服务器的 numa。

1. 修改 grub.conf

  • RHEL/CentOS 6
    • 在 /boot/grub/grub.conf 文件中修改 kernel 行(添加numa=off
[root@db ~]# vi /boot/grub/grub.conf
kernel /vmlinuz-2.6.39-400.215.10.EL ro root=/dev/VolGroup00/LogVol00 numa=off
  • For RHEL 7
    在/etc/default/grub 文件中修改 kernel 行。
[root@db ~]# 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

[root@db ~]# grub2-mkconfig -o /etc/grub2.cfg
  • RHEL7/CentOS7 必须要重建 GRUB 配置文件才能生效

2. 重启操作系统

[root@db ~]# reboot
6. 配置swap权重
  • 数据库服务器必须降低 swap 的使用权重
[root@db ~]# vim /etc/sysctl.conf
vm.swappiness = 1

保存后使其生效s
[root@db ~]# sysctl -p
7. 检查时区是否为东八区
# 查看时区,如果不是东八区需要按时区进行校准
[root@db ~]# date -R
Wed, 06 Mar 2019 14:17:16 +0800

# 设置软连接,进行时区校准
[root@db ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 注:修改时间后须手动重启crontab,cron的执行时间才会同步
[root@db ~]# systemctl restart crond
8. 配置ntp服务
  • 根据实际的 ntp 服务器地址修改配置
[root@db ~]# 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

##  启动服务:  ##
# 先手工对时一下:
[root@db ~]# ntpdate 100.65.255.1
# redhat6/centos6
[root@db ~]# service ntpd start
[root@db ~]# chkconfig ntpd on

# redhat7/centos7
[root@db ~]# systemctl start ntpd
[root@db ~]# systemctl enable ntpd

# 注:修改时间后须手动重启crontab,cron的执行时间才会同步
[root@db ~]# systemctl restart crond
9. 核对umask
# 查看/ etc / profile并搜索umask关键字,查看以下代码是否被扩展
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
     umask 002
else
    umask 022
fi

# 查看当前系统umask的值,确保与文件中的值一致
[root@db ~]# umask
0022
10. 配置历史命令
[root@db ~]# vi /etc/bashrc  # 在末尾添加: 
export HISTFILESIZE=500000000 
export HISTSIZE=1000000 
export PROMPT_COMMAND="history -a" 
export HISTTIMEFORMAT='%F %T ' 
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami`  " 

# 使配置生效: 
[root@db ~]# source /etc/bashrc
11. 关闭透明大页面(THP)
  • 查询系统是否开启了 THP 命令
  • 如果括号中的是 always 表示开启了,never 则表示未开启
[root@db ~]# cat /sys/kernel/mm/transparent_hugepage/enabled 
[always] madvise never 
[root@db ~]# cat /sys/kernel/mm/transparent_hugepage/defrag 
[always] madvise never
  • 实时生效关闭方案
[root@db ~]# echo never >> /sys/kernel/mm/transparent_hugepage/enabled 
[root@db ~]# echo never >> /sys/kernel/mm/transparent_hugepage/defrag
  • 写进配置文件永久生效(需要重启)
# 在/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

# 执行以下操作,使rc.local可以在系统引导期间执行
[root@db ~]# chmod +x /etc/rc.d/rc.local
12. 检查系统虚拟内存超配参数
  • 虚拟机环境的宿主机超配,cpu超配。并给客户提出风险告知。
  • 检查系统虚拟内存超配参数
  • 确认vm.overcommit_memory=0, 如果为其他值, 需报备
  • ( 场景, 若vm.overcommit_memory为2, 虚拟内存超配受到vm.overcommit_ratio限制, 可能无法分配足够大的内存 )
[root@db ~]# sysctl -A | grep "vm.overcommit_memory" 
sysctl: reading key "net.ipv6.conf.all.stable_secret" 
sysctl: reading key "net.ipv6.conf.default.stable_secret" 
sysctl: reading key "net.ipv6.conf.eth0.stable_secret" 
sysctl: reading key "net.ipv6.conf.lo.stable_secret" 
vm.overcommit_memory = 0
13. 检查字符集
[root@db ~]# locale | grep en
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"

[root@db ~]# echo $LANG
en_US.UTF-8
14. 检查网络是否与外网打通,ping是否正常
  • 本次测试在内网环境应无法ping通外网
[root@db ~]# ping www.baidu.com    
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.            
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=51 time=8.39 ms 
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=51 time=7.16 ms 
^C 
--- www.a.shifen.com ping statistics --- 
2 packets transmitted, 2 received, 0% packet loss, time 1008ms 
rtt min/avg/max/mdev = 7.160/7.776/8.393/0.622 ms
15. 检查网络丢包率是否正常
[root@db ~]# ping 10.186.60.32
PING 10.186.60.32 (10.186.60.32) 56(84) bytes of data. 
64 bytes from 10.186.60.32: icmp_seq=1 ttl=64 time=0.022 ms 
64 bytes from 10.186.60.32: icmp_seq=2 ttl=64 time=0.029 ms 
64 bytes from 10.186.60.32: icmp_seq=3 ttl=64 time=0.034 ms 
64 bytes from 10.186.60.32: icmp_seq=4 ttl=64 time=0.040 ms 
64 bytes from 10.186.60.32: icmp_seq=5 ttl=64 time=0.028 ms 
64 bytes from 10.186.60.32: icmp_seq=6 ttl=64 time=0.031 ms 
64 bytes from 10.186.60.32: icmp_seq=7 ttl=64 time=0.028 ms 
64 bytes from 10.186.60.32: icmp_seq=8 ttl=64 time=0.031 ms 
64 bytes from 10.186.60.32: icmp_seq=9 ttl=64 time=0.032 ms 
64 bytes from 10.186.60.32: icmp_seq=10 ttl=64 time=0.029 ms 
64 bytes from 10.186.60.32: icmp_seq=11 ttl=64 time=0.039 ms 
64 bytes from 10.186.60.32: icmp_seq=12 ttl=64 time=0.032 ms 
64 bytes from 10.186.60.32: icmp_seq=13 ttl=64 time=0.031 ms 
64 bytes from 10.186.60.32: icmp_seq=14 ttl=64 time=0.036 ms 
^C 

--- 10.186.60.32 ping statistics --- 
14 packets transmitted, 14 received, 0% packet loss, time 13043ms 
rtt min/avg/max/mdev = 0.022/0.031/0.040/0.007 ms
16. 检查tcp keepalive是否打开
[root@db ~]# sysctl -a | grep keepalive 
net.ipv4.tcp_keepalive_intvl = 75 
net.ipv4.tcp_keepalive_probes = 9 
net.ipv4.tcp_keepalive_time = 7200 
sysctl: reading key "net.ipv6.conf.all.stable_secret" 
sysctl: reading key "net.ipv6.conf.default.stable_secret" 
sysctl: reading key "net.ipv6.conf.eth0.stable_secret" 
sysctl: reading key "net.ipv6.conf.lo.stable_secret
17. 检查tcp连接以及随机端口参数
# 表示开启重用(通过timestamp 递增性,客户端和服务器能够处理outofbind fin包)。允许将TIME-WAIT sockets重新用于新的TCP连接
[root@db ~]# cat /proc/sys/net/ipv4/tcp_tw_reuse
1

# 表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭 。注意: Linux 从4.12内核版本开始移除了 tcp_tw_recycle 配置
[root@db ~]# cat /proc/sys/net/ipv4/tcp_tw_recycle
0     

# 查看网络随机端口参数的值,如果参数范围包含DMP平台端口5690-5800(会有可能导致产品组件端口被占用)或者MySQL的端口范围,建议修改
[root@db ~]# cat /proc/sys/net/ipv4/ip_local_port_range  
32768 60999        # 默认值

# 指定为已知的第三方应用程序保留的端口。这些端口将不会被自动端口分配使用(例如,使用端口号0调用connect()或bind()时)。
# 防呆参数,如果有ip_local_port_range 可不配置此参数,显式端口分配行为不受此影响。
[root@db ~]# cat /proc/sys/net/ipv4/ip_local_reserved_ports     # 注意:内核版本要大于2.6.18-164,否则不支持该参数。

[root@db ~]# vim /etc/sysctl.conf            # 修改系统配置信息
net.ipv4.tcp_tw_reuse = 1               # 默认为空,表示关闭,建议为1,表示允许将TIME-WAIT sockets重新用于新的TCP连接
net.ipv4.tcp_tw_recycle = 0             # 默认为空,表示关闭,建议关闭
ip_local_port_range  = 32768 60999      # 默认为32768 60999,如ip_local_port_range中为默认值,则本行无需填写
ip_local_reserved_ports  = 5690-5800    # 默认为空,表示无保留端口

[root@db ~]# sysctl -p     # 配置生效
18. MySQL用户ulimit设置
  • 操作系统对mysql用户注意以下参数的设置,该设置为必须的设置
# 如果是Redhat7
[root@db ~]# vi /etc/security/limits.d/20-nproc.conf
mysql soft nofile 65535
mysql hard nofile 65535
mysql soft nproc 65535
mysql hard nproc 65535

#如果是Redhat6
[root@db ~]# vi /etc/security/limits.d/90-nproc.conf
mysql soft nofile 65535
mysql hard nofile 65535
mysql soft nproc 65535
mysql hard nproc 65535
19. 卸载系统自带旧版本MySQL相关RPM包
  • 某些服务系预装了 MySQL,但是版本是5.1,避免客户端版本差异带来的影响,应该卸载这类rpm包.
  • 如系统中存在perl-DBD-MySQL-4.013-3.el6.x86_64mysql-libs-5.1.73-3.el6_5.x86_64可保留不卸载.
[root@db ~]# rpm -qa|grep mysql -i 
[root@db ~]# rpm -e --nodeps mysql-xxx-5.1..x86_64 
[root@db ~]# mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d`
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

正在输入中…………

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值