关键词环境部署:
############## 测试环境机器架构 #########
【1】策划
【1.1】linux服务器A组 8台
192.168.1.200~192.168.1.207,主机名db,db1~db7
【1.2】负载均衡服务器 2台
192.168.1.211~192.168.1.212,主机名,fz1,fz2
【1.3】中间件
192.168.1.221~192.168.1.222,主机名,xm1,xm2
【1.4】mysql服务器B组 8台
#拷贝的【1.1】中的虚拟机文件,所以是同样的IP和主机名
192.168.1.200~192.168.1.207,主机名db,db1~db7
############## 样板机部署 #########
【2】虚拟机,样板机centos7
#IP地址
IP地址,192.168.1.200
#修改主机名
hostname db1#直接修改本地主机名
vi /etc/sysconfig/network #修改网络上的主机名
#磁盘分布
/ 50G
softvg:30G
appvg:51
datavg:52
logvg:53
bakvg:54
lvm磁盘系统构建
#PV
pvcreate /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf
#VG
vgcreate softvg /dev/sdf
vgcreate appvg /dev/sdb
vgcreate datavg /dev/sdc
vgcreate logvg /dev/sdd
vgcreate bakvg /dev/sde
#LV
lvcreate -n softlv -L 30000M softvg
lvcreate -n mysqllv -L 50000M appvg
lvcreate -n datalv -L 50000M datavg
lvcreate -n loglv -L 50000M logvg
lvcreate -n baklv -L 49998M bakvg
#格式化
mkfs.xfs /dev/softvg/softlv
mkfs.xfs /dev/appvg/mysqllv
mkfs.xfs /dev/datavg/datalv
mkfs.xfs /dev/logvg/loglv
mkfs.xfs /dev/bakvg/baklv
#创建目录
mkdir -p /soft
mkdir -p /mysql/app
mkdir -p /mysql/data
mkdir -p /mysql/log
mkdir -p /mysql/backup
#挂载
mount /dev/softvg/softlv /soft
mount /dev/appvg/mysqllv /mysql/app
mount /dev/datavg/datalv /mysql/data
mount /dev/logvg/loglv /mysql/log
mount /dev/bakvg/baklv /mysql/backup
#修改 /etc/fstab 以便可以重启自动挂载
echo '/dev/softvg/softlv /soft xfs defaults 0 0'>>/etc/fstab
echo '/dev/appvg/mysqllv /mysql/app xfs defaults 0 0'>>/etc/fstab
echo '/dev/datavg/datalv /mysql/data xfs defaults 0 0'>>/etc/fstab
echo '/dev/logvg/loglv /mysql/log xfs defaults 0 0'>>/etc/fstab
echo '/dev/bakvg/baklv /mysql/backup xfs defaults 0 0'>>/etc/fstab
#本地host
echo '192.168.1.200 db' >>/etc/hosts
echo '192.168.1.201 db1' >>/etc/hosts
echo '192.168.1.202 db2' >>/etc/hosts
echo '192.168.1.203 db3' >>/etc/hosts
echo '192.168.1.204 db4' >>/etc/hosts
echo '192.168.1.205 db5' >>/etc/hosts
echo '192.168.1.206 db6' >>/etc/hosts
echo '192.168.1.207 db7' >>/etc/hosts
echo '192.168.1.211 fz1' >>/etc/hosts
echo '192.168.1.212 fz2' >>/etc/hosts
echo '192.168.1.221 xm1' >>/etc/hosts
echo '192.168.1.222 xm2' >>/etc/hosts
#配置字符集
echo "export LANG=en_US.UTF8">>~/.bash_profile
echo "export LANG=en_US.UTF8">>/etc/profile
#挂载光驱
mount /dev/cdrom /mnt
#配置本地yum源
cd /etc/yum.repos.d/
mkdir bk
mv CentOS-Base.repo bk/
touch base.repo
echo "[base]">>base.repo
echo "name=centos7.5_cdrom">>base.repo
echo "baseurl=file:///mnt">>base.repo
echo "gpgcheck=0">>base.repo
echo "enabled=1">>base.repo
yum list #核验yum源
#设置默认启动方式为3,多用户模式
systemctl get-default multi-user.target
systemctl get-default #核验
#参数优化(1)
echo "* soft memlock 300000">>/etc/security/limits.cnf #内存锁 300M
echo "* hard memlock 300000">>/etc/security/limits.cnf
echo "vm.nr_hugepages=150">>/etc/sysctl.conf
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,建议给生产环境
sysctl -p#核验
#参数优化(2)
echo "* soft nproc 65535" >>/etc/security/limits.conf #nproc 用户创建进程数限制
echo "* hard nproc 65535" >>/etc/security/limits.conf
echo "* soft nofile 65535" >>/etc/security/limits.conf #nofile 进程打开文件次数限制
echo "* hard nofile 65535" >>/etc/security/limits.conf
echo "* soft stack 65535" >>/etc/security/limits.conf #存放变量的指针
echo "* hard stack 65535" >>/etc/security/limits.conf
systemctl stop avahi-daemon.socket avahi-daemon.service
systemctl disable avahi-daemon.socket avahi-daemon.service
#selinux关闭
echo "* - nproc 16384">/etc/security/limits.d/90-nproc.conf #nproc 进程数限制
echo "SELINUX=disable">/etc/selinux/config #关闭selinux
echo "#SELINUXTYPE=targeted">>/etc/selinux/config
cat /etc/selinux/config
setenforce 0
getenforce
#防火墙关闭
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
#IO调度算法
#一共4种,默认是CFQ(完全随机访问,相对来说这种算法对于mysql来说不是很好,会造成小IO的延时增加,msql官网建议算法换成deadline算法,这种IO比较稳定)。一共4种,默认是CFQ(完全随机访问,相对来说这种算法对于mysql来说不是很好,会造成小IO的延时增加,msql官网建议算法换成deadline算法,这种IO比较稳定)。
#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
echo 'deadline' > /sys/block/sdf/queue/scheduler
#ssd用这个
echo 'NOOP' > /sys/block/sd*/scheduler
#减少预读(默认128)
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
echo '16'>/sys/block/sdf/queue/read_ahead_kb
#增大队列
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
echo '512'>/sys/block/sdf/queue/nr_requests
#x修改时区为上海
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#更换内存模式,不使用NUMA模式
vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet numa=off" #把这行改成这样
grub2-mkconfig -o /etc/grub2.cfg
numastat
numactl --show
numactl --hardware
shutdown -r now
############## 克隆机器调整 ################################
#【1】记录每台机器的MAC
192.168.1.201 00:0c:29:65:8c:19
192.168.1.202
192.168.1.203
192.168.1.204
192.168.1.205
192.168.1.206
192.168.1.207
#【2】直接删除/etc/udev/rules.d下的70-persistent-net.rules文件,然后reboot次系统
#【3】配置mac地址,首先ifconfig -a 命令看一下hwaddr的值和文件/etc/sysconfig/network-scripts/ifcfg-ens34
#改MAC、IP、删UUID
(1)vi /etc/sysconfig/network-scripts/ifcfg-ens34 #修改IP信息,删除UUID
(2)rm -f /etc/udev/rules.d/70-persistent-ipoib.rules #修改mac地址,重启会生成
(3)#修改主机名
hostnamectl set-hostname db1
echo "db1">/etc/hostname
reboot
############ 安装mysql ################
【1】利用scp传输文件到8台服务器
scp 192.168.1.200:/soft/*
【2】install the base lib
mount /dev/cdrom /mnt
yum remove mariadb* -y
yum install gcc gcc-c++ perl-DBD-MySQL ncurses-devl.x86_64 cmake.x86_64 libaio.x86_64 bison.x86_64 gcc-c++.x86_64 bind-utils wget curl curl-devel -y
# perl-DBD-MySQL 这个lib包很重要
yum search rz -y
yum install -y lrzsz.x86_64
【3】install mysql
#(1)uncompress file,create user and usergroup mysql
groupadd mysql
useradd -r -g mysql -s /bin/falsh mysql
cd /mysql/app
tar -zxvf /soft/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.7.24-linux-glibc2.12-x86_64 mysql
echo "export PATH=\$PATH:$HOME/bin:/mysql/app/mysql/bin">>/etc/profile
source /etc/profile
#(2)create dir,and change privileges to mysql user
mkdir -p /mysql/data/3306/data
mkdir -p /mysql/log/3306/binlog
mkdir -p /mysql/log/3306/relaylog
mkdir -p /mysql/backup/backup-db
mkdir -p /mysql/backup/backup-tmp
mkdir -p /mysql/backup/backup-binlog
chown -R mysql:mysql /mysql
#(3)init database mysql
rm -rf /mysql/data/3306/data
cp /soft/my.cnf /mysql/data/3306/
/mysql/app/mysql/bin/mysqld --defaults-file=/mysql/data/3306/my.cnf --initialize --user=mysql
ln -s /mysql/data/3306/mysql.sock /tmp/mysql.sock
#(4) remove default my.cnf
rm -f /etc/my.cnf
rm -rf /etc/my.cnf.d
#(5)set the default password
mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --skip-grant-tables --skip-networking &
mysql -uroot --socket='/mysql/data/3306/mysql.sock' -e"update mysql.user set authentication_string=password('123456') where user='root' and host='localhost';flush privileges;"
mysql -uroot -p123456 --connect-expired-password -S /mysql/data/3306/mysql.sock -e"alter user 'root'@'localhost' identified by '123456';"
mysql -uroot -p123456 -S /mysql/data/3306/mysql.sock -e"create user 'root'@'%' identified by '123456';grant all privileges on *.* to 'root'@'%' with grant option;flush privileges;"
mysql -uroot --password='123456' -S /mysql/data/3306/mysql.sock -e"create database t;use t;create table t1 select 1 as id;select * from t1;drop database t;"
--connect-expired-password 使用过期密码连接
#(6)set the mysql.start shell
echo "mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --user=mysql &">>/mysql/data/3306/mysql.start
chown mysql:mysql /mysql
chmod +x /mysql/data/3306/mysql.start
mysqladmin -uroot -p123456 -S /mysql/data/3306/mysql.sock shutdown
sh /mysql/data/3306/mysql.start
#(7)把mysql配置成服务
ln -s /mysql/data/3306/my.cnf /etc/my.cnf
cp -r /mysql/app/mysql/support-files/mysql.server /usr/lib/systemd/system/
cp -r /mysql/app/mysql/support-files/mysql.server /etc/init.d/mysql
systemctl daemon-reload #重载系统进程,才能让上面的cp起作用把mysql.server封装成服务
#(8)设置成开机自启
systemctl daemon-reload #重载系统进程,才能让上面的cp起作用把mysql.server封装成服务
systemctl status mysql #查看mysql服务状态
systemctl start mysql #启动mysql
systemctl enable mysql #设置mysql服务开机自启
chkconfig --add mysql #设置mysql服务开机自启