###
本次实验共计6台机器Centos8
A:10.0.0.15 - DNS服务器
B:10.0.0.16 - web1 - www.noise.org
C:10.0.0.17 - web2 - www.noise.org
D:10.0.0.18 - NFS,wordpress
E:10.0.0.19 - Mysql
F:测试机器
###
1> 配置Mysql服务器,建立web1和web2 访问数据库的账号密码,及权限
[18:51:03 root@centos8 ~]#yum -y install mysql-server [18:55:30 root@centos8 ~]#systemctl enable --now mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service. [18:55:46 root@centos8 ~]#systemctl start mysqld [18:55:54 root@centos8 ~]#mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> create database wordpress; Query OK, 1 row affected (0.00 sec) mysql> create user wordpress@‘10.0.0.16‘ identified by ‘123456‘; Query OK, 0 rows affected (0.00 sec) mysql> mysql> create user wordpress@‘10.0.0.17‘ identified by ‘123456‘; Query OK, 0 rows affected (0.00 sec) mysql> grant all on wordpress.* to wordpress@‘10.0.0.16‘; Query OK, 0 rows affected (0.00 sec) mysql> grant all on wordpress.* to wordpress@‘10.0.0.17‘; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
2> 配置NFS和wordpress
# 下载wordpress
288 wget https://cn.wordpress.org/latest-zh_CN.zip 289 unzip latest-zh_CN.zip 290 yum -y install unzip 291 unzip latest-zh_CN.zip 292 ll
# 安装nfs服务 293 yum -y install nfs-utils 294 mkdir /data/wordpress 295 ss -ntl 296 rmp -ql nfs-utils 297 rpm -ql nfs-utils
# nfs有多个服务,只需要其中的nfs-server 298 systemctl enable --now nfs-server 299 systemctl start nfs-server
# 下面是定义nfs文件访问规则,把所有访问者都压缩成为UID和GID为80的用户,可读可写 [21:11:27 root@centos8 ~]#cat /etc/exports /data/wordpress 10.0.0.0/24(rw,all_squash,anonuid=80,anongid=80)
# 生效上面规则 302 exportfs -v 303 exportfs -r
# 除了NFS自身规则,还需要给linux文件系统赋予权限 306 chmod 777 /data/wordpress/ 307 ll /data/wordpress/ 308 mv wordpress/* /data/wordpress/
# 给与所有访问NFS的用户都压缩成为www 311 useradd -u 80 -s /sbin/nologin -r www 319 chown -R www.www /data/wordpress/wp-content # 等待web1和web2安装完毕以后再进行copy,此目的为了把除了wp-content的其他文件放到web服务器,NFS就单纯用来存放upload上来的文件 331 scp -r /data/wordpress/* 10.0.0.16:/var/www/html/ 332 scp -r /data/wordpress/* 10.0.0.17:/var/www/html/
3> WEB服务器,两台web服务器设置一样,不做过多展示
[18:38:26 root@centos8 ~]#yum -y install nfs-utils [19:12:46 root@centos8 ~]#yum -y install httpd php-fpm php-mysqlnd php-xml php-json [19:38:08 root@centos8 ~]#systemctl enable --now httpd php-fpm Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service. [19:38:18 root@centos8 ~]#systemctl start httpd php-fpm
# 此步是因为wp-contents是存放用户上传的数据,所以并不需要放在web
服务器,是放在NFS服务器 [21:00:31 root@centos8 ~]#rm -rf /var/www/html/wp-content/*
# 挂载NFS的wp-content [21:04:38 root@centos8 ~]#cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Apr 11 10:31:16 2021 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk/‘. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run ‘systemctl daemon-reload‘ to update systemd # units generated from this file. # UUID=7bed8fe9-cddc-4ca6-b6de-ad1124b86e91 / xfs defaults 0 0 UUID=cdc87b20-b709-4814-90b6-86104157d571 /boot xfs defaults 0 0 UUID=be152368-cd54-4dd9-b0ff-3a3873fdc795 /data xfs defaults 0 0 UUID=a5fd20dc-0f17-4bb0-83fc-85cecc89b77e none swap defaults 0 0 10.0.0.18:/data/wordpress/wp-content /var/www/html/wp-content nfs _netdev 0 0 [21:21:34 root@centos8 ~]#df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 979352 0 979352 0% /dev tmpfs 998100 0 998100 0% /dev/shm tmpfs 998100 8872 989228 1% /run tmpfs 998100 0 998100 0% /sys/fs/cgroup /dev/sda2 104806400 2940996 101865404 3% / /dev/sda5 52403200 398504 52004696 1% /data /dev/sda1 2086912 196468 1890444 10% /boot tmpfs 199620 0 199620 0% /run/user/0 10.0.0.18:/data/wordpress/wp-content 52403200 460288 51942912 1% /var/www/html/wp-content
[21:04:30 root@centos8 ~]#mount -a #挂载生效
4> DNS 服务器
[18:38:11 root@centos8 ~]#yum -y install bind [21:25:27 root@centos8 ~]#cat /etc/named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { // listen-on port 53 { 127.0.0.1; }; 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"; secroots-file "/var/named/data/named.secroots"; recursing-file "/var/named/data/named.recursing"; // allow-query { localhost; }; [20:56:57 root@centos8 ~]#cat /etc/named.rfc1912.zones // named.rfc1912.zones: // // Provided by Red Hat caching-nameserver package // // ISC BIND named zone configuration for zones recommended by // RFC 1912 section 4.1 : localhost TLDs and address zones // and https://tools.ietf.org/html/rfc6303 // (c)2007 R W Franks // // See /usr/share/doc/bind*/sample/ for example named configuration files. // // Note: empty-zones-enable yes; option is default. // If private ranges should be forwarded, add // disable-empty-zone "."; into options // zone "noise.org" { type master; file "noise.org.zone"; }; [21:25:58 root@centos8 ~]#cat /var/named/noise.org.zone $TTL 1D @ IN SOA ns1 admin ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum ns ns1 ns1 A 10.0.0.15 www A 10.0.0.16 www A 10.0.0.17
#当时我是从named.localhost复制出来改,但是所属者和所属组是属于root,所以dns解析会失败 [20:05:39 root@centos8 named]#ll total 20 drwxrwx--- 2 named named 23 Jun 30 19:27 data drwxrwx--- 2 named named 60 Jun 30 20:01 dynamic -rw-r----- 1 root named 2253 May 28 04:49 named.ca -rw-r----- 1 root named 152 May 28 04:49 named.empty -rw-r----- 1 root named 152 May 28 04:49 named.localhost -rw-r----- 1 root named 168 May 28 04:49 named.loopback -rw-r----- 1 root root 200 Jun 30 19:59 noise.org.zone drwxrwx--- 2 named named 6 May 28 04:49 slaves # 注意加权
[20:06:22 root@centos8 named]#chown -R named.named noise.org.zone [20:00:57 root@centos8 named]#systemctl restart named
5> 测试机(注意配置测试机自身网卡的DNS)
20:17:42 root@centos7 ~]#nslookup www.noise.org Server: 10.0.0.15 Address: 10.0.0.15#53 Name: www.noise.org Address: 10.0.0.16 Name: www.noise.org Address: 10.0.0.17 [20:17:46 root@centos7 ~]#curl www.noise.org [20:25:50 root@centos7 ~]#curl -v www.noise.org * About to connect() to www.noise.org port 80 (#0) * Trying 10.0.0.17... * Connected to www.noise.org (10.0.0.17) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: www.noise.org > Accept: */* > < HTTP/1.1 302 Found < Date: Wed, 30 Jun 2021 12:25:53 GMT < Server: Apache/2.4.37 (centos) < X-Powered-By: PHP/7.2.24 < Location: http://www.noise.org/wp-admin/setup-config.php < Content-Length: 0 < Content-Type: text/html; charset=UTF-8 < * Connection #0 to host www.noise.org left intact
# 结果:无论web服务器中间哪一部机器停掉,都不会影响用户访问,会自动切换到另一台机器,并且数据都是存放在NFS服务器的wp-content
原文:https://www.cnblogs.com/noise/p/14956477.html