目录
一、系统版本
1、操作系统
Oracle Linux 6/7/8.4 内存:8g(下述内存参数相关,是根据8G内存配置的,不同内存参数,配置不同)
二、系统配置
1、 hosts
echo "192.168.1.31 mysql31" >> /etc/hosts echo "192.168.1.32 mysql32" >> /etc/hosts echo "192.168.1.33 mysql33" >> /etc/hosts echo "192.168.1.61 mysql61" >> /etc/hosts echo "192.168.1.62 mysql62" >> /etc/hosts echo "192.168.1.71 mysql71" >> /etc/hosts echo "192.168.1.72 mysql72" >> /etc/hosts cat /etc/hosts
2、 配英文环境
echo "export LANG=en_US" >> ~/.bash_profile cat ~/.bash_profile
3、 修改资源限制参数
(1)limits配置
echo "* soft nproc 16384" >> /etc/security/limits.conf echo "* hard nproc 16384" >> /etc/security/limits.conf echo "* soft nofile 16384" >> /etc/security/limits.conf echo "* hard nofile 65536" >> /etc/security/limits.conf echo "* soft stack 16384" >> /etc/security/limits.conf echo "* hard stack 32768" >> /etc/security/limits.conf echo "* soft memlock 7000000" >> /etc/security/limits.conf ##内存锁8G的,可以设置为7G echo "* hard memlock 7000000" >> /etc/security/limits.conf ##内存锁8G的,可以设置为7G
--生效配置
#ulimit -a
(2)配合nproc.conf
cat /etc/security/limits.d/90-nproc.conf echo "* - nproc 65535" > /etc/security/limits.d/90-nproc.conf cat /etc/security/limits.d/90-nproc.conf
4、sysctl配置
(1)内存参数
echo "vm.nr_hugepages=2560" >> /etc/sysctl.conf ##开了内存大页,mysql就会用。 echo "vm.swappiness=10" >> /etc/sysctl.conf ##内存低于10%时使用交换页面 #echo "vm.min_free_kbytes=51200" >> /etc/sysctl.conf ##系统保留50m echo "vm.min_free_kbytes=512000" >> /etc/sysctl.conf ##生产机预留500m
(2)TCP/IP参数
vi /etc/sysctl.conf net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 1 net.core.somaxconn = 262144 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_max_orphans = 262144 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 30 net.ipv4.tcp_keepalive_probes = 6 net.ipv4.tcp_keepalive_intvl = 5 net.ipv4.tcp_timestamps = 0
(3)防火墙参数
sed -i 's/net.bridge.bridge-nf-call-ip6tables =0/#net.bridge.bridge-nf-call-ip6tables = 0/g' /etc/sysctl.conf sed -i 's/net.bridge.bridge-nf-call-iptables =0/#net.bridge.bridge-nf-call-iptables = 0/g' /etc/sysctl.conf sed -i 's/net.bridge.bridge-nf-call-arptables =0/#net.bridge.bridge-nf-call-arptables = 0/g' /etc/sysctl.conf
(4)生效:
sysctl -p
5、设置系统安全策略
(1)SELinux关闭
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config sed -i 's/SELINUXTYPE=mls/SELINUXTYPE=targeted/g' /etc/selinux/config cat /etc/selinux/config setenforce 0
(2) 关防火墙
--公网,建议要开防火墙,设置比较合理的安全规则,限制外网访问,这是 LINUX 系统管理的工作,但 DBA 也要会。
--linux6
service iptables stop
chkconfig --level 2345 iptables off
--Linux 7/8
systemctl stop firewalld systemctl disable firewalld
(3) 控制资源分配限制
echo "session required pam_limits.so" >> /etc/pam.d/login cat /etc/pam.d/login
6、关闭透明大页(大内存也开启的前提)
echo "if test -f /sys/kernel/mm/transparent_hugepage/enabled; then">>/etc/rc.d/rc.local echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled">>/etc/rc.d/rc.local echo "fi">> /etc/rc.d/rc.local echo "if test -f /sys/kernel/mm/transparent_hugepage/defrag; then">>/etc/rc.d/rc.local echo "echo never > /sys/kernel/mm/transparent_hugepage/defrag">>/etc/rc.d/rc.local echo "fi">> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local
7、yum 源环境配置
(1)Linux6/7
mount /dev/cdrom /mnt --下次重启手工挂 cd /etc/yum.repos.d mkdir -p bk mv * bk/ echo '[OEL67]'> OL67.repo echo 'name= linux 67' >>OL67.repo echo 'baseurl=file:///mnt' >>OL67.repo echo 'gpgcheck=0' >>OL67.repo echo 'enabled=1' >>OL67.repo yum list
(2)Linux8
mount /dev/cdrom /mnt --下次重启手工挂 cd /etc/yum.repos.d mkdir bk mv * bk/
echo "[EL8-1]" >> /etc/yum.repos.d/EL8.repo echo "name =Linux-8-DVD1" >> /etc/yum.repos.d/EL8.repo echo "baseurl=file:///mnt/AppStream" >> /etc/yum.repos.d/EL8.repo echo "gpgcheck=0" >> /etc/yum.repos.d/EL8.repo echo "enabled=1" >> /etc/yum.repos.d/EL8.repo echo "[EL8-2]" >> /etc/yum.repos.d/EL8.repo echo "name =Linux-8-DVD2" >> /etc/yum.repos.d/EL8.repo echo "baseurl=file:///mnt/BaseOS" >> /etc/yum.repos.d/EL8.repo echo "gpgcheck=0" >> /etc/yum.repos.d/EL8.repo echo "enabled=1" >> /etc/yum.repos.d/EL8.repo
yum list
8、MySQL/Memcached/Redis安装依赖包
(1)卸载mariadb包
yum remove mariadb-libs -y
(2)安装依赖包
yum install gcc -y yum install gcc-c++ -y yum install ncurses-devel.x86_64 -y yum install lrzsz.x86_64 -y yum install cmake.x86_64 -y yum install libaio.x86_64 -y yum install bison.x86_64 -y yum install gcc-c++.x86_64 -y yum install bind-utils -y yum install wget -y yum install curl -y yum install curl-devel -y yum install perl -y yum install openssh-clients -y yum install setuptool -y yum install sysstat -y yum install make -y yum install redhat-lsb* -y yum install numactl -y
9、关闭 NUMA 功能
(1)查看numa状态
numastat numactl --show numactl --hardware
(2)修改/etc/default/grub
在kenerl那行或者是两行后的quiet后添加numa=off
sed -i 's/quiet/quiet numa=off/g' /etc/default/grub
--重启系统生效(reboot),可以稍后重启
10、配置字符界面
systemctl set-default multi-user.target systemctl get-default
11、 IO 调度算法与 IO 优化
有四种算法:CFQ(不太适用mysql)、deadline(io比较稳定,适用于mysql)、kyber、none、noop
(1)查看硬盘的IO 调度算法
cat /sys/block/sd*/queue/scheduler
(2)修改硬盘的IO 调度算法(非sda)
----sas/stat硬盘
echo 'deadline' > /sys/block/sdb/queue/scheduler echo 'deadline' > /sys/block/sdc/queue/scheduler echo 'deadline' > /sys/block/sdd/queue/scheduler echo 'deadline' > /sys/block/sde/queue/scheduler
--ssd硬盘
echo 'NOOP' > /sys/block/sdb/queue/scheduler echo 'NOOP' > /sys/block/sdc/queue/scheduler echo 'NOOP' > /sys/block/sdd/queue/scheduler echo 'NOOP' > /sys/block/sde/queue/scheduler
--开启后生效
(3)配置预读和队列
vi /etc/rc.local (写入如下echo即可,每次重启后,会自动修改预读和队列的值)
--减少预读(只针对数据盘进行修改)
cat /sys/block/sd*/queue/read_ahead_kb
echo '16' > /sys/block/sdb/queue/read_ahead_kb echo '16' > /sys/block/sdc/queue/read_ahead_kb echo '16' > /sys/block/sdd/queue/read_ahead_kb echo '16' > /sys/block/sde/queue/read_ahead_kb
--增大队列(只针对数据盘进行修改)
cat /sys/block/sd*/queue/nr_requests
echo '512' > /sys/block/sdb/queue/nr_requests echo '512' > /sys/block/sdc/queue/nr_requests echo '512' > /sys/block/sdd/queue/nr_requests echo '512' > /sys/block/sde/queue/nr_requests
(4)重启生效
reboot
12、准备磁盘与分区--最规范的
(1)目录规划
安装目录:/mysql/app 数据目录:/mysql/data 日志目录:/mysql/log 备份目录:/backup
(2)创建目录
mkdir -p /mysql/app mkdir -p /mysql/data mkdir -p /mysql/log mkdir -p /backup
(3)硬盘情况:
/dev/sdb 30g /dev/sdc 10g
(4)LVM配置
pvcreate /dev/sdb /dev/sdc vgcreate vg_mysql /dev/sdb vgcreate vg_bak /dev/sdc lvcreate -n lv_mysql -L 10G vg_mysql lvcreate -n lv_data -L 14.9G vg_mysql lvcreate -n lv_log -L 5G vg_mysql lvcreate -n lv_bak -L 9.9G vg_bak pvs vgs vgdisplay lvs lvdisplay mkfs.xfs /dev/vg_mysql/lv_mysql mkfs.xfs /dev/vg_mysql/lv_data mkfs.xfs /dev/vg_mysql/lv_log mkfs.xfs /dev/vg_bak/lv_bak mount /dev/vg_mysql/lv_mysql /mysql/app mount /dev/vg_mysql/lv_data /mysql/data mount /dev/vg_mysql/lv_log /mysql/log mount /dev/vg_bak/lv_bak /backup df -h
(5)配置fstab
vi /etc/fstab /dev/vg_mysql/lv_mysql /mysql/app xfs defaults 0 0 /dev/vg_mysql/lv_data /mysql/data xfs defaults 0 0 /dev/vg_mysql/lv_log /mysql/log xfs defaults 0 0 /dev/vg_bak/lv_bak /backup xfs defaults 0 0
13、网络重启
Linux8中的Network服务已经没有了,可以使用两种网络管理方式:
(1)NetworkManager
systemctl restart NetworkManager
(2)nmcli
nmcli c reload --重载配置 nmcli c up ens160 --重启网络服务
二、硬盘配置
1、物理主机
(1)系统盘:
/dev/sda,不使用lvm格式,50G-100G即可
(2)数据盘:
mysql的库,一定要使用lvm。因为mysql数据库,后期可能增长比较快,使用lvm可以随意扩容数据库。