业务需求
1.nginx服务器负责调度2台web服务器(两台服务器都配备了discuz和wordpress服务)。
2.NFS服务器存储两个网络服务器的网页文件。
3.mysql服务器存储两个web服务器的数据文件。
4.他们的域名分别是:d.zjzd.cn(discuz)和w.zjzd.cn(wordpress)
1.IP地址规划
172.16.30.1Nginx
NFS
灯(Mysql主)
172.16.30.4灯(Mysql从属)
窗户
2.mysql主从配置
灯(Mysql主)
#/etc/init.d/iptables stop #setenforce 0 #vim /etc/my.cnf [mysqld] server-id = 1 log-bin=mysql-bin #/etc/init.d/mysqld restart #mysql mysql> grant replication slave on *.* to 'tongbu'@'%' identified by 'sa123456'; Query OK, 0 rows affected (0.02 sec) mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 252 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)172.16.30.4灯(Mysql从属)
#/etc/init.d/iptables stop #setenforce 0 #vim /etc/my.cnf [mysqld] server-id = 2 #/etc/init.d/mysqld restart #mysql mysql> change master to master_host='172.16.30.3',master_user='tongbu',master_password='sa123456',master_log_file='mysql-bin.000001',master_log_pos=252; Query OK, 0 rows affected (0.07 sec) mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.16.30.3 Master_User: tongbu Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 252 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 251 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 252 Relay_Log_Space: 407 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: 1 row in set (0.00 sec)注意:如果IO和SQL进程都为是,则主从配置成功。
3.设置NFS服务
NFS
(1)创建一个装载和共享目录。
#/etc/init.d/iptables stop #setenforce 0 #fdisk /dev/sda n p 回车 +200G p w #因为我的主分区已经使用了三个,所以这里默认新建的主分区是第四个分区(建议将第四个分区分为扩展分区,而不是主分区,输入e即可) #mkfs.ext4 /dev/sda4 #mkdir /data #blkid /dev/sda4 /dev/sda4: UUID="520d6185-1545-4ee2-87c4-84c535a4a534" TYPE="ext4" #vim /etc/fstab UUID=520d6185-1545-4ee2-87c4-84c535a4a534 /data ext4 defaults 0 0 #mount -a #df -Th /dev/sda4 ext4 197G 188M 187G 1% /data #mkdir /data/www #mkdir /data/www/{discuz,wordpress}(2)下载并解压discuz
#wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip #cd /data/www #unzip /root/Discuz_X3.2_SC_UTF8.zip -d discuz/ #cd discuz #mv upload/* . #ll(3)下载并解压wordpress
#wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz #tar xf wordpress-4.5.3-zh_CN.tar.gz -C /data/www/wordpress/ #cd /data/www/wordpress/wordpress #mv * ../ #cd .. #rm -fr wordpress(4)配置nfs服务
#vim /etc/exports /data/www/discuz *(rw,sync) /data/www/wordpress *(rw,sync) #/etc/init.d/nfs restart4.分别在两个LAMP服务器上挂载Discuz和Wordpress目录。
(1)172.16.30.3 Mysql Master #yum install nfs-utils #cd /var/www/html/ #mount -t nfs 172.16.30.2:/data/www/ . 或者 #mount -t nfs 172.16.30.2:/data/www/discuz . #mount -t nfs 172.16.30.2:/data/www/wordpress .注意:挂载后需要退出当前目录,然后重新进入挂载的目录才能看到挂载的内容。
(Mysql从服务器
#yum install nfs-utils #cd /var/www/html/ #mount -t nfs 172.16.30.2:/data/www/ . 或者 #mount -t nfs 172.16.30.2:/data/www/discuz . #mount -t nfs 172.16.30.2:/data/www/wordpress .5.在两台LAMP服务器上配置同一个虚拟主机,并通过向导进行安装。
(1)配置虚拟主机
#cd /etc/httpd/conf #vim vhosts.conf NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin fengzq@gnnt.com.cn DocumentRoot "/var/www/html/discuz" ServerName d.zjzd.cn <Directory "/var/www/html/discuz"> AllowOverride All Options -Indexes FollowSymLinks Order allow,deny Allow from all </Directory> ErrorLog logs/error_log CustomLog logs/access_log common </VirtualHost> <VirtualHost *:80> ServerAdmin fengzq@gnnt.com.cn DocumentRoot "/var/www/html/wordpress" ServerName w.zjzd.cn <Directory "/var/www/html/wordpress"> AllowOverride All Options -Indexes FollowSymLinks Order allow,deny Allow from all </Directory> ErrorLog logs/error_log CustomLog logs/access_log common </VirtualHost> #vim httpd.conf Include conf/vhosts.conf #/etc/init.d/httpd restart(2)配置主机解析。
首先找到C:\Windows\System32\drivers\etc\hosts文件,然后右键选择“用notepad++编辑”添加以下内容,最后通过浏览器访问进行测试。
d.zjzd.cn
w.zjzd.cn
d.zjzd.cn
w.zjzd.cn
(3)创建数据库和授权用户。
Mysql主服务器
#mysql mysql> create database discuz; Query OK, 1 row affected (0.01 sec) mysql> create database wordpress; Query OK, 1 row affected (0.00 sec) mysql> grant all on discuz.* to discuz@'172.16.30.%' identified by 'discuz'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on wordpress.* to wps@'172.16.30.%' identified by 'wordpress'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye(4)将数据库服务器配置为域名地址。
Mysql主服务器
#vim /etc/hosts 172.16.30.3 mysql.zjzd.cn #注意:在LAP环境下,解析是配置在web服务器上的,并非是数据库服务器,这里LAP+Mysql是同一台服务器,所以才这样配置Mysql从服务器
#vim /etc/hosts 172.16.30.3 mysql.zjzd.cn(5)网页向导安装Discuz服务(略)
步骤:检查安装环境->:设置运行环境->:创建数据库->;固定
窗户
#http://d.zjzd.cn//检查安装环境时,个别目录会提示不存在或未写状态,只需做以下 *** 作
NFS
#cd /data/www/discuz #chmod -R 777 data/ uc_* config/(6)网页向导安装Wordpress服务(略)
如果安装过程中出现警告提示,只需遵循以下步骤
NFS
#vim /data/www/wordpress/wp-config.php #根据提示复制框中的内容6.配置nginx负载平衡
(1)安装1)nginx
#/etc/init.d/iptables stop #setenforce 0 #useradd www #yum install pcre pcre-devel openssl openssl-devel #wget http://nginx.org/download/nginx-1.10.2.tar.gz #tar -xf nginx-1.10.2.tar.gz #cd nginx-1.10.2.tar.gz #./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre #make && make install #/usr/local/nginx/sbin/nginx -t #/usr/local/nginx/sbin/nginx #netstat -tunlp | grep 80(2)配置nginx负载均衡虚拟主机
#cd /usr/local/nginx/conf #mkdir domains #cd domains #vim d.zjzd.cn upstream discuz_web { server 172.16.30.3:80 weight=1 max_fails=2 fail_timeout=30s; server 172.16.30.4:80 weight=1 max_fails=2 fail_timeout=30s; } server { listen 80; server_name d.zjzd.cn; #注:这里的域名可以和apache中虚拟主机的域名不一致 location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://discuz_web; } } #vim w.zjzd.cn upstream wordpress_web { server 172.16.30.3:80 weight=1 max_fails=2 fail_timeout=30s; server 172.16.30.4:80 weight=1 max_fails=2 fail_timeout=30s; } server { listen 80; server_name w.zjzd.cn; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://wordpress_web; } } #/usr/local/nginx/sbin/nginx -s reload(3)配置nginx.conf文件。
#vim /usr/local/nginx/conf/nginx.conf worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; include domains/*; #主要是添加这一行内容,导入vhosts文件 }(4)配置主机解析。
窗户
首先找到C:\Windows\System32\drivers\etc\hosts文件,然后右键选择“用notepad++编辑”添加以下内容,最后通过浏览器访问进行测试。
72.16.30.1w.zjzd.cn,d.zjzd.cn//What被要求在这里是nginx服务器的内容。
(5)测试
停止所有后端服务器,然后访问网站,最后查询nginx错误日志。
灯(Mysql主)
#/etc/init.d/httpd stop172.16.30.4灯(Mysql从属)
#/etc/init.d/httpd stop窗户
http://d.zjzd.cn
http://w.zjzd.cn
172.16.30.1nginx
#tail /usr/local/nginx/logs/error.log 2016/11/23 17:11:47 [error] 71293#0: *339 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /forum.php HTTP/1.1", upstream: "http://172.16.30.3:80/forum.php", host: "d.zjzd.cn" 2016/11/23 17:11:47 [error] 71293#0: *339 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /forum.php HTTP/1.1", upstream: "http://172.16.30.4:80/forum.php", host: "d.zjzd.cn" 2016/11/23 17:11:47 [error] 71293#0: *339 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.16.30.4:80/favicon.ico", host: "d.zjzd.cn", referrer: "http://d.zjzd.cn/forum.php" 2016/11/23 17:11:47 [error] 71293#0: *339 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.16.30.3:80/favicon.ico", host: "d.zjzd.cn", referrer: "http://d.zjzd.cn/forum.php" 2016/11/23 17:11:50 [error] 71293#0: *349 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: w.zjzd.cn, request: "GET / HTTP/1.1", upstream: "http://172.16.30.3:80/", host: "w.zjzd.cn" 2016/11/23 17:11:50 [error] 71293#0: *349 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: w.zjzd.cn, request: "GET / HTTP/1.1", upstream: "http://172.16.30.4:80/", host: "w.zjzd.cn" 2016/11/23 17:13:51 [error] 71293#0: *355 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /forum.php HTTP/1.1", upstream: "http://172.16.30.3:80/forum.php", host: "d.zjzd.cn" 2016/11/23 17:13:51 [error] 71293#0: *355 connect() failed (111: Connection refused) while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /forum.php HTTP/1.1", upstream: "http://172.16.30.4:80/forum.php", host: "d.zjzd.cn" 2016/11/23 17:13:51 [error] 71293#0: *355 no live upstreams while connecting to upstream, client: 172.16.0.25, server: d.zjzd.cn, request: "GET /favicon.ico HTTP/1.1", upstream: "http://discuz_web/favicon.ico", host: "d.zjzd.cn", referrer: "http://d.zjzd.cn/forum.php"欢迎分享,转载请注明来源:内存溢出
评论列表(0条)