nat模型的特性
1、Rs应该是私有地址,Rs网关必须指向DIP
2、DIP和RIP必须在同一个网段内
3、请求和响应报文都应该经过
准备两台web机器,安装nginx
对于nat主机
配置两个网卡和两个主机,正常来说应该配置两个不同的网段ip,一个对外的vip,
一个对内的dip,现在主要使用nat的网络模式,可以配置桥接模式对外,nat对内,教师机
不方便配置桥接模式,所以都是配置的nat模式,要分清楚vip和dip,且二者在物理主机上
都能ping通,
主机名 | IP地址 | 功能 |
web1 | 192.168.1.17 | rs reslserver |
web2 | 192.168.1.18 | rs.Realserver |
nat | 内网:192.168.1.102 外网:192.168.1.16 | directorserver.ntp |
dns | 192.168.1.12 | dns |
client | 192.168.1.11 |
mysql主从 (先搞从,再搞主)
用脚本更方便,因为有脚本
先把安装包下载好,然后用脚本实现安装mysql
从:
[root@sql ~]# cat mysql.sh
#!/bin/bash
yum list installed | grep rsync
if [ $? -ne 0 ];then
yum -y install rsync
fi
echo rsync yes
yum list installed | grep ntpdate
if [ $? -ne 0 ];then
yum -y install ntpdata
fi
echo ntpdate yes
ntpdate cn.ntp.org.cn
yum list installed |grep libaio
if [ $? -ne 0 ]; then
yum -y install libaio
fi
echo libaio yes
rm -rf /etc/my.cnf
echo remo my.cnf yes
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
echo tar zx yes
cp -r ~/mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
echo copy file to /usr/local/mysql yes
mkdir /usr/local/mysql/mysql-files
echo mysql-files yes
grep mysql /etc/passwd
if [ $? -ne 0 ];then
useradd -r -s /sbin/nologin mysql
fi
chown mysql:mysql /usr/local/mysql/mysql-files
chmod 750 /usr/local/mysql/mysql-files
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile
source /etc/profile
#编辑配置文件
cat >> /usr/local/mysql/my.cnf << EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3310
log-error=/usr/local/mysql/data/db01-slave.err
relay-log=/usr/local/mysql/data/relaylog
server-id=11
character_set_server=utf8mb4
EOF
echo "不要启动服务,等主服务器传过来data目录之后,再启动服务"
echo "进入mysql进行相关配置"
主:
[root@C ~]# cat mysql.sh
#!/bin/bash
yum list installed |grep ntpdate
if [ $? -ne 0 ]; then
yum -y install ntpdate
fi
echo ntpdate yes
ntpdate cn.ntp.org.cn
yum list installed |grep rsync
if [ $? -ne 0 ]; then
yum -y install rsync
fi
echo rsync yes
yum list installed |grep libaio
if [ $? -ne 0 ]; then
yum -y install libaio
fi
echo libaio yes
rm -rf /etc/my.cnf
echo remo my.cnf yes
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
echo tar zx yes
cp -r ~/mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
echo copy file to /usr/local/mysql yes
mkdir /usr/local/mysql/mysql-files
echo mysql-files yes
grep mysql /etc/passwd
if [ $? -ne 0 ];then
useradd -r -s /sbin/nologin mysql
fi
chown mysql:mysql /usr/local/mysql/mysql-files
chmod 750 /usr/local/mysql/mysql-files
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
sleep 3
/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile
source /etc/profile
#编辑配置文件
cat >> /usr/local/mysql/my.cnf << EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/db01-master.err
log-bin=/usr/local/mysql/data/binlog
server-id=10
character_set_server=utf8mb4
EOF
#启动服务
service mysql8 start
if [ $? -ne 0 ];then
echo "mysql启动失败"
else
echo "mysql启动成功"
fi
#设置开机启动
chkconfig --add mysql8
chkconfig mysql8 on
#关闭服务
service mysql8 stop
#删除/data/auto.cnf,并把data目录同步给从服务器
rm -rf /usr/local/mysql/data/auto.cnf
rsync -av /usr/local/mysql/data root@192.168.118.30:/usr/local/mysql/
if [ $? -ne 0 ];then
echo "data目录同步失败"
else
echo "data目录同步成功"
fi
service mysql8 start
echo "进入数据库配置相关内容"
#设置开机启动(主)
[root@C ~]# chkconfig --add mysql8
[root@C ~]# chkconfig mysql8 on
[root@C ~]# chkconfig
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysql8 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
#修改配置文件(从)
[root@sql ~]# cat /usr/local/mysql/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3310
log-error=/usr/local/mysql/data/db01-slave.err
relay-log=/usr/local/mysql/data/relaylog
server-id=11
character_set_server=utf8mb4
主从复制之数据同步
# rsync -av /usr/local/mysql/data root@192.168.1.20:/usr/local/mysql/