Host (192.168.199.0) | Features |
---|---|
243 | DNS |
126 | httpd1 |
174 | httpd2 |
157 | NFS-server |
175 | mariadb-server |
123 | client |
Configure DNS server
1) Configure named.conf
listen-on port 53 {
any; };
# allow-query { localhost; }; 注释掉这一行,允许所有人都可以访问
2) Define an area
[root@DNS ~]# cat /etc/named.rfc1912.zones
zone "ydong.com" IN {
type master;
file "ydong.com.zone";
allow-update {
none; }; # 不允许自动更新
};
3) Define the regional database file
[root@DNS ~]# cat /var/named/ydong.com.zone
$TTL 1D
ydong.com. IN SOA ns1.ydong.com. admin.ydong.com. (
0
1D
1H
1W
1D
)
ydong.com. NS ns1.ydong.com.
ns1 A 192.168.199.243
www A 192.168.199.126
www A 192.168.199.174
4) Test DNS work
[root@client ~]# dig www.ydong.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> www.ydong.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45161
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.ydong.com. IN A
;; ANSWER SECTION:
www.ydong.com. 86400 IN A 192.168.199.126
www.ydong.com. 86400 IN A 192.168.199.174
;; AUTHORITY SECTION:
ydong.com. 86400 IN NS ns1.ydong.com.
;; ADDITIONAL SECTION:
ns1.ydong.com. 86400 IN A 192.168.199.243
;; Query time: 2 msec
;; SERVER: 192.168.199.243#53(192.168.199.243)
;; WHEN: 日 3月 22 13:31:49 CST 2020
;; MSG SIZE rcvd: 108
Configure httpd virtual host
Both hosts have the same operation, only one is shown here.
1) Create a directory to place the homepage
[root@httpd1 ~]# mkdir /data/ldamp/
2) Configure the virtual machine
[root@httpd1 ~]# cat /etc/httpd/conf.d/ydong.conf
<VirtualHost *:80>
DocumentRoot "/data/ldamp/"
ServerName www.ydong.com
<Directory "/data/ldamp">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
3) Restart the service test
[root@NFS ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search lan
nameserver 192.168.199.243
[root@NFS ~]# curl http://www.ydong.com
174.ydong.com
[root@localhost ~]# curl http://www.ydong.com
126.ydong.com
#两台不同的机器访问,可以产生轮询效果
Install php-fpm
php-fpm is placed on the httpd host. The two hosts are the same, but the ip addresses are changed to different ones.
1) Modify the php-fpm address
[root@httpd1 ~]# cat /etc/php-fpm.d/www.conf
listen = 192.168.199.126:9000 #监听的地址和端口
;listen.allowed_clients = 127.0.0.1 # 允许哪个客户端可以访问,注释默认是允许全部
2) Start php-fpm
[root@httpd1 ~]# systemctl start php-fpm
3) Add dynamic analysis in the virtual machine
[root@httpd2 ~]# cat /etc/httpd/conf.d/ydong.conf
<VirtualHost *:80>
DocumentRoot "/data/ldamp/"
ServerName www.ydong.com
<Directory "/data/ldamp">
Options none
Allowoverride none
Require all granted
</Directory>
DirectoryIndex index.php
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.199.174:9000/data/ldamp/$1
</VirtualHost>
4) Test
Install mariadb
1) Install php-mysql on all httpd servers.
[root@httpd1 ~]# yum install -y php-mysql
2) Install mariadb
[root@mariadb ~]# yum install -y mariadb-server
3) Create the required libraries and authorized users for WordPress
MariaDB [(none)]> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wordpress.* TO wpuser@'192.168.199.%' IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
4) Test that httpd can connect to mysql
[root@httpd1 ~]# cat /data/ldamp/index.php
<?php
$conn=mysql_connect('192.168.199.175','wpuser','centos');
if($conn)
echo "Mariadb connect OK";
else
echo "Mariadb connect FAIL";
?>
Build NFS service
1) Install nfs service
[root@NFS-serv ~]# yum install -y nfs-utils.x86_64
2) Create a directory to store WordPress
[root@NFS-serv ~]# ls /app
wordpress
3) Modify the configuration file
[root@NFS-serv wordpress]# cat wp-config.php
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wpuser' );
/** MySQL database password */
define( 'DB_PASSWORD', 'centos' );
/** MySQL hostname */
define( 'DB_HOST', '192.168.199.175' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
4) Share out
[root@NFS-serv wordpress]# cat /etc/exports
/app/wordpress *()
5) httpd host mount
[root@httpd2 ~]# cat /etc/fstab
192.168.199.157:/app/wordpress /data/ldamp/ nfs defaults 0 0
test