Nginx 企业网站架构模拟

目录:

  1. 架构图
  2. Mysql主从
  3. LAP discuz、wordpress代码发布
  4. Nginx 负载均衡
架构图

在这里插入图片描述



Mysql主从
  1. 使用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
  1. 重启mysql
[root@localhost ~]# service mysqld restart
  1. 修改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
  1. 授权同步用户
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服务关闭时才会影响

回到目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值