其他分享
首页 > 其他分享> > LVS综合实验

LVS综合实验

作者:互联网

LVS综合实验

1、环境准备

提前准备:Mysql8.0.30安装包、Mysql安装脚本、shopxo2.3.0安装包、DNS脚本

image

服务器 IP地址 作用 系统版本
Mysql-master 10.0.0.103 shopxo网站主数据库 Ubuntu2004
Mysql-slave 10.0.0.104 shopxo网站备份数据库 Ubuntu2004
NFS-data 10.0.0.105 shopxo图片视频等多媒体大文件存放NFS Ubuntu2004
NFS-backup 10.0.0.106 NFS备份服务器 Ubuntu2004
shopxo1 10.0.0.101 shopxo1网站 Ubuntu2004
shopxo2 10.0.0.102 shopxo1备份网站 Ubuntu2004
LVS eth0:10.0.0.100
eth1:192.168.0.100
LVS 负载网站访问调度 Ubuntu2004
client Route eth0:192.168.0.88
eth1:192.168.10.88
客户端路由器 rocky8.6
DNS 192.168.10.100 域名解析 rocky8.6

2、搭建Mysql主服务器

# mysql-master:(提前脚本安装好mysql)
[root@mysql-master ~]#vim /etc/my.cnf      #更改配置文件
[mysqld]
server-id=104
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
default_authentication_plugin=mysql_native_password      
gtid_mode=ON
enforce_gtid_consistency
[client]
socket=/data/mysql/mysql.sock
[root@mysql-master ~]#systemctl restart mysql
[root@mysql-master ~]#mysql -p123456
mysql> create user repluser@'10.0.0.%' identified by '123456';      #创建主从同步账号并授权
mysql> grant replication slave on *.* to repluser@'10.0.0.%';

mysql> create user shopxo@'10.0.0.%' identified by '123456';       #创建主从同步账号并授权
mysql> grant all on shopxo.* to shopxo@'10.0.0.%';

image

3、搭建Mysql从服务器

# mysql-slave: (提前脚本安装好mysql)
[root@ubuntu2004 ~]#vim /etc/my.cnf
[mysqld]
server-id=104
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
default_authentication_plugin=mysql_native_password
gtid_mode=ON
enforce_gtid_consistency
[client]
socket=/data/mysql/mysql.sock
[root@ubuntu2004 ~]#systemctl restart mysql
[root@ubuntu2004 ~]#mysql -p123456
CHANGE MASTER TO
  MASTER_HOST='10.0.0.103',
  MASTER_USER='repluser',
  MASTER_PASSWORD='123456',
  MASTER_PORT=3306,
  MASTER_AUTO_POSITION=1;
  
mysql> start slave;

image

4、搭建nfs-backup服务器

## nfs-backup:
[root@nfs-backup ~]#apt install -y rsync
[root@nfs-backup ~]#vim /etc/rsyncd.conf
uid = root
gid = root  
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no
[backup] 
path = /data/backup/  
comment = backup dir
read only = no 
auth users = rsyncuser  
secrets file = /etc/rsync.pas


[root@nfs-backup ~]#echo rsyncuser:123456 > /etc/rsync.pas
[root@nfs-backup ~]#chmod 600 /etc/rsync.pas
[root@nfs-backup ~]#mkdir /data/backup -p
[root@nfs-backup ~]#setfacl -m u:nobody:rwx /data/backup
[root@nfs-backup ~]#systemctl restart rsync.service 

# 105服务器nfs-data验证:
[root@nfs-data ~]#rsync rsyncuser@10.0.0.106::backup
Password: 
drwxr-xr-x          4,096 2022/09/07 20:18:38 .

image

5、搭建nfs-data服务器

# 105服务器nfs-data:

[root@nfs-data ~]#apt install -y rsync
[root@nfs-data ~]#tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local
[root@nfs-data ~]#cd /usr/local
[root@nfs-data local]#mv GNU-Linux-x86/ sersync2
[root@nfs-data local]#cd sersync2/
[root@nfs-data sersync2]#vim confxml.xml
    <rsync>
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="false"/>
    <filter start="false">
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="true"/>
    <modify start="true"/>
    </inotify>

    <sersync>
    <localpath watch="/data/www/">
        <remote ip="10.0.0.106" name="backup"/>                    #更改为备份服务器的ip地址
        <!--<remote ip="192.168.8.39" name="tongbu"/>-->
        <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    </localpath>
    <rsync>
        <commonParams params="-artuz"/>
        <auth start="true" users="rsyncuser" passwordfile="/etc/rsync.pas"/>
        <userDefinedPort start="false" port="874"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="600"><!--600mins-->
        <crontabfilter start="false">
        <exclude expression="*.php"></exclude>
        <exclude expression="info/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>

    <plugin name="command">
    <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
    <filter start="false">
        <include expression="(.*)\.php"/>
        <include expression="(.*)\.sh"/>
    </filter>
    </plugin>

    <plugin name="socket">
    <localpath watch="/opt/tongbu">
        <deshost ip="192.168.138.20" port="8009"/>
    </localpath>
    </plugin>
    <plugin name="refreshCDN">
    <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
        <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
        <sendurl base="http://pic.xoyo.com/cms"/>
        <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
    </localpath>
    </plugin>
</head>

[root@nfs-data sersync2]#mkdir /data/www -p
[root@nfs-data sersync2]#echo 123456 > /etc/rsync.pas
[root@nfs-data sersync2]#chmod 600 /etc/rsync.pas
[root@nfs-data sersync2]#screen                           
[root@nfs-data sersync2]#./sersync2 -dro ./confxml.xml

[root@nfs-data sersync2]#vim /etc/exports
/data/www 10.0.0.0/24(rw,all_squash,anonuid=33,anongid=33)
[root@nfs-data sersync2]#exportfs -r
[root@nfs-data sersync2]#exportfs -v

image

image

6、搭建shopxo1主服务器

101服务器shopxo1
[root@shopxo1 ~]#apt -y install apache2 php7.4-fpm libapache2-mod-php7.4 php7.4-mysql php7.4-json php7.4-xml php7.4-mbstring php7.4-zip php7.4-gd php7.4-curl

[root@shopxo1 ~]#rm -f /var/www/html/index.html
[root@shopxo1 ~]#unzip shopxo-v2.3.0.zip
[root@shopxo1 ~]#mv shopxo-v2.3.0/* /var/www/html/
[root@shopxo1 ~]#chown -R www-data. /var/www/html
[root@shopxo1 ~]#systemctl restart apache2.service 

[root@shopxo1 ~]#scp -r /var/www/html/public/static/upload/* 10.0.0.105:/data/www

[root@shopxo1 ~]#vim /etc/fstab
10.0.0.105:/data/www /var/www/html/public/static/upload/      nfs   _netdev 0 0
[root@ubuntu2004 ~]#apt install -y nfs-common 
[root@shopxo1 ~]#mount -a

7、搭建shopxo1备服务器

102服务器shopxo2
[root@shopxo2 ~]#apt -y install apache2 php7.4-fpm libapache2-mod-php7.4 php7.4-mysql php7.4-json php7.4-xml php7.4-mbstring php7.4-zip php7.4-gd php7.4-curl
[root@shopxo2 ~]#rm -f /var/www/html/index.html
[root@shopxo2 ~]#unzip shopxo-v2.3.0.zip
[root@shopxo2 ~]#mv shopxo-v2.3.0/* /var/www/html/
[root@shopxo2 ~]#chown -R www-data. /var/www/html
[root@shopxo2 ~]#systemctl restart apache2.service 

[root@shopxo2 ~]#vim /etc/fstab
10.0.0.105:/data/www /var/www/html/public/static/upload/      nfs   _netdev 0 0
[root@shopxo2 ~]#mount -a

8、ClientRoute

[root@Route ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j MASQUERADE
[root@Route ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

9、搭建DNS服务器

[root@DNS ~]# yum install -y bind bind-utils
[root@DNS ~]# vim /etc/named.conf

#注释下面三行
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
//  allow-query     { localhost; };

[root@DNS ~]# vim /etc/named.rfc1912.zones
zone "dayu.org" IN {
    type master;
    file "dayu.org.zone";
};

[root@DNS ~]# cp -p /var/named/named.localhost /var/named/dayu.org.zone
[root@DNS ~]# vim /var/named/dayu.org.zone
$TTL 1D
@   IN SOA wang rname.invalid. (
                    0   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  wang
wang    A   192.168.10.100
www     A   192.168.0.100

image

10、客户机测试

[root@client ~]# vim /etc/resolv.conf          #指向dns服务器
nameserver 192.168.10.100
[root@client ~]# curl www.dayu.org             #测试

image-20220909215901418

标签:10.0,www,LVS,data,实验,mysql,nfs,root,综合
来源: https://www.cnblogs.com/wdy001/p/16674097.html