目录:
架构图
Mysql主从
- 使用yum安装Lamp架构在192.168.197.11、192.168.197.12上
[root@localhost ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# yum install httpd httpd-devel mysql mysql-server mysql-devel php php-devel php-mysql -y
- 重启mysql
[root@localhost ~]# service mysqld restart
- 修改mysql配置文件,并重启mysqld服务
192.168.197.11主
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 使用binlog功能
log-bin=mysql-bin
server-id=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
192.168.197.12从
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=2
- 授权同步用户
mysql> grant replication slave on *.* to 'tongbu'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,Password,Host from mysql.user;
+--------+-------------------------------------------+-----------------------+
| User | Password | Host |
+--------+-------------------------------------------+-----------------------+
| root | | localhost |
| root | | localhost.localdomain |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | localhost.localdomain |
| tongbu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % |
+--------+-------------------------------------------+-----------------------+
7 rows in set (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 399 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
197.12从
mysql> change master to master_host='192.168.197.11',master_port=3306,master_user='tongbu',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=399;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.197.11
Master_User: tongbu
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 399
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
LAP discuz、wordpress代码发布
先查看php是否整合
[root@localhost conf]# cat /var/www/html/index.php
<?php
phpinfo();
?>
- Discuz
[root@localhost html]# cd /var/www/html/
[root@localhost html]# mkdir discuz
[root@localhost html]# unzip /tmp/Discuz_X3.2_SC_UTF8.zip -d /var/www/html/discuz/
[root@localhost html]# mv discuz/upload/* discuz/
[root@localhost html]# cd discuz/
[root@localhost discuz]# chmod -R 757 config/ data/ uc_server/ uc_client/
[root@localhost discuz]# ls
admin.php archiver cp.php favicon.ico home.php member.php portal.php search.php template upload
api config crossdomain.xml forum.php index.php misc.php readme source uc_client userapp.php
api.php connect.php data group.php install plugin.php robots.txt static uc_server utility
- Wordpress
[root@localhost html]# unzip /tmp/WordPress-master.zip -d /var/www/html/wordpress/
[root@localhost html]# cd wordpress/
[root@localhost wordpress]# mv WordPress-master/* .
- 修改apache虚拟主机
[root@localhost html]# cd /etc/httpd/conf
[root@localhost conf]# echo "Include conf/domains/*" >> httpd.conf
[root@localhost conf]# mkdir domains
[root@localhost conf]# vim domains/test.discuz.com
<VirtualHost *:80>
ServerAdmin jeffding1993@outlook.com
DocumentRoot "/var/www/html/discuz"
ServerName test.discuz.com
ErrorLog "logs/test.discuz.com_error_log"
CustomLog "logs/test.discuz.com_access_log" common
</VirtualHost>
[root@localhost conf]# cp domains/test.discuz.com domains/test.wordpress.com
[root@localhost conf]# vim domains/test.wordpress.com
<VirtualHost *:80>
ServerAdmin jeffding1993@outlook.com
DocumentRoot "/var/www/html/wordpress"
ServerName test.wordpress.com
ErrorLog "logs/test.wordpress.com_error_log"
CustomLog "logs/test.wordpress.com_access_log" common
</VirtualHost>
[root@localhost conf]# systemctl restart httpd
修改主机hosts文件
192.168.197.11 test.discuz.com
192.168.197.11 test.wordpress.com
新版本wordpress php版本过低,直接继续用discuz模拟
- 修改LAP hosts文件
[root@localhost discuz]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.197.11 mysql.discuz.com
- 数据库授权:
mysql> create database discuz default charset utf8;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on discuz.* to 'discuz'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> select User, Password, Host from mysql.user;
+--------+-------------------------------------------+-----------------------+
| User | Password | Host |
+--------+-------------------------------------------+-----------------------+
| root | | localhost |
| root | | localhost.localdomain |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | localhost.localdomain |
| tongbu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % |
| discuz | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % |
+--------+-------------------------------------------+-----------------------+
8 rows in set (0.00 sec)
将197.11的代码与197.12同步
[root@localhost discuz]# cd /etc/httpd/conf/
[root@localhost conf]# echo "Include conf/domains/*" >> httpd.conf
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# rsync -aP discuz root@192.168.197.12:/var/www/html/
[root@localhost html]# rsync -aP /etc/httpd/conf/ root@192.168.197.12:/etc/httpd/conf/
Nginx 负载均衡
主机hosts修改为
192.168.197.10 test.discuz.com
192.168.197.10 test.wordpress.com
197.10
[root@localhost ~]# sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# cd /etc/nginx/conf.d/
[root@localhost nginx]# cd conf.d/
[root@localhost conf.d]# cp default.conf test.discuz.conf
[root@localhost conf.d]# vim test.discuz.conf
upstream discuz {
server 192.168.197.11:80;
server 192.168.197.12:80;
}
server {
listen 80;
server_name test.discuz.com;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
proxy_set_header Host $host;
proxy_pass http://discuz;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
[root@localhost nginx]# nginx -s reload
最终结果:
当关闭一台LAP的httpd时,不会影响访问。只有当全部LAP服务关闭时才会影响