一、LVS
1.角色
主机名 | ip地址 | 功能 |
---|---|---|
web01 | 192.168.2.101 | rs |
web02 | 192.168.2.102 | realservee |
nat | 内网:192.168.2.103 外网:192.168.2.120 | directorserver,ntp |
dns | 192.168.2.105 | dns |
2..web服务器
[root@web01 ~]# yum -y install nginx
[root@web01 ~]# echo "web===01" > /usr/share/nginx/html/index.html
[root@web01 ~]# nginx
[root@web02 ~]# yum -y install nginx
[root@web02 ~]# echo "web===02" > /usr/share/nginx/html/index.html
[root@web02 ~]# nginx
2.nat
配置两个网卡和两个ip地址,一个对内ip,一个对外ip
内网:192.168.2.103
外网:192.168.2.120
3.dns:192.168.2.105
[root@localhost ~]# yum -y install bind
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { 127.0.0.1;any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { localhost;any;};
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "haha" IN {
type master;
file "haha.zone";
allow-update { none; };
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# ll
总用量 16
drwxrwx---. 2 named named 6 6月 11 22:40 data
drwxrwx---. 2 named named 6 6月 11 22:40 dynamic
-rw-r-----. 1 root named 2253 4月 5 2018 named.ca
-rw-r-----. 1 root named 152 12月 15 2009 named.empty
-rw-r-----. 1 root named 152 6月 21 2007 named.localhost
-rw-r-----. 1 root named 168 12月 15 2009 named.loopback
drwxrwx---. 2 named named 6 6月 11 22:40 slaves
[root@localhost named]# cp -p named.localhost haha.zone
[root@localhost named]# vim haha.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
nat A 192.168.2.103
ds A 192.168.2.120
web01 A 192.168.2.101
web02 A 192.168.2.102
检查文件
[root@localhost named]# named-checkconf /etc/named.conf
[root@localhost named]# named-checkconf /etc/named.rfc1912.zones
[root@localhost named]# named-checkzone haha.zone haha.zone
zone haha.zone/IN: loaded serial 0
OK
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl enable named
4.客户端
将配置DNS服务的IP重定向到/etc/resolv中
[root@client ~]# echo "nameserver 192.168.2.105" > /etc/resolv
[root@client ~]# ping nat.haha
PING nat.haha (192.168.2.103) 56(84) bytes of data.
64 bytes from 192.168.2.103 (192.168.2.103): icmp_seq=1 ttl=64 time=0.216 ms
64 bytes from 192.168.2.103 (192.168.2.103): icmp_seq=2 ttl=64 time=0.624 ms
^C
--- nat.haha ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.216/0.420/0.624/0.204 ms
[root@client ~]# ping ds.haha
PING ds.haha (192.168.2.120) 56(84) bytes of data.
64 bytes from 192.168.2.120 (192.168.2.120): icmp_seq=1 ttl=64 time=0.445 ms
64 bytes from 192.168.2.120 (192.168.2.120): icmp_seq=2 ttl=64 time=0.408 ms
^C
--- ds.haha ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.408/0.426/0.445/0.027 ms
5.nat:设置时间同步服务器
[root@nat ~]# yum -y install ntpdate.x86_64
[root@nat ~]# crontab -e
* 2 * * * /usr/sbin/ntpdate cn.ntp.org.cn
[root@nat ~]# systemctl start ntpdate.service
[root@nat ~]# systemctl enable ntpdate.service
6.dns:设置时间同步
[root@dns ~]# crontab -e
30 3 * * * /usr/sbin/ntpdate 192.168.2.103(时间服务器的地址)
7.web01
[root@web01 ~]# crontab -e
30 3 * * * /usr/sbin/ntpdate 192.168.2.103(时间服务器的地址)
8.web02
[root@web02 ~]# crontab -e
30 3 * * * /usr/sbin/ntpdate 192.168.2.103(时间服务器的地址)
9.nat
[root@nat ~]# yum -y install ipvsadm.x86_64
二、基于gtids的主从复制搭建
实践步骤
1.修改配置⽂件⽀持GTIDs
1.master
[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
gtid-mode=on
log-slave-updates=1
enforce-gtid-consistency
2.slave
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/err.log
relay-log=/usr/local/mysql/data/relaylog
character_set_server=utf8mb4
server-id=11
log-bin=/usr/local/mysql/data/binlog
gtid-mode=on
log-slave-updates=1
enforce-gtid-consistency
skip-slave-start
2.重新启动mysql服务
[root@master ~]# service mysql8 start
Starting MySQL SUCCESS!
[root@slave ~]# service mysql8 start
Starting MySQL SUCCESS!
3.主从设置只读模式
mysql> set @@global.read_only=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> set @@global.read_only=ON;
Query OK, 0 rows affected (0.00 sec)
4.slave重新配置change master to
mysql> stop slave;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> reset slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to
-> master_host='192.168.2.38',
-> master_user='slave',
-> master_password='slave_123;',
-> master_port=3306,
-> master_auto_position=1;
Query OK, 0 rows affected, 8 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> show slave status\G
5.关闭主从服务只读模式
mysql> set @@global.read_only=OFF;
Query OK, 0 rows affected (0.00 sec)
mysql> set @@global.read_only=OFF;
Query OK, 0 rows affected (0.01 sec)
6.获得公钥
[root@slave ~]# mysql -uslave -h192.168.2.38 -P3306 --get-server-public-key -p
Enter password: