实验目的:为了减轻后端服务器的承载量,使用HAProxy做动静分离,将动态资源放在动态web组中,静态资源放在static组中,图片放在image server中,数据库单独用一台服务器。
网络拓扑图
配置HAProxy服务器
~]# yum -y install haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend main *:80 acl url_web path_end -i .html .css .js .htm use_backend websers if url_web acl url_static path_end -i .jpg .gif .png use_backend static if url_static default_backend app rspadd X-Via:\ HAProxy rspidel ^Server.* backend websers balance roundrobin rspadd X-Service:\ WEBServer server ws1 172.16.67.1:80 check rise 3 fall 5 weight 2 maxconn 10 cookie ws1 server ws2 172.16.67.2:80 check rise 3 fall 5 weight 3 maxconn 10 cookie ws1 backend static balance roundrobin rspadd X-Service:\ ImageServer server static 172.16.69.1:80 check backend app balance roundrobin rspidel ^Server.* rspadd X-Service:\ AppServer server app1 172.16.67.1:80 check rise 3 fall 5 weight 2 maxconn 10 cookie as1 server app2 172.16.67.2:80 check rise 3 fall 5 weight 3 maxconn 10 cookie as1
~]# service haproxy start
配置后端静态web组和images server
~]# yum install -y httpd ~]# service httpd start ~]# tar xf wordpress-4.8.1-zh_CN.tar.gz -C /var/www/html/
配置后端动态web组
~]# yum install -y httpd php php-mysql ~]# service httpd start ~]# tar xf wordpress-4.8.1-zh_CN.tar.gz -C /var/www/html/ ~]# cd /var/www/html/wordpress wordpress]# cp wp-config-sample.php wp-config.php wordpress]# vim wp-config.php
/** WordPress数据库的名称 */ define('DB_NAME', 'wpdb'); /** MySQL数据库用户名 */ define('DB_USER', 'wpadmin'); /** MySQL数据库密码 */ define('DB_PASSWORD', '123456'); /** MySQL主机 */ define('DB_HOST', '172.16.69.2'); /** 创建数据表时默认的文字编码 */ define('DB_CHARSET', 'utf8'); /** 数据库整理类型。如不确定请勿更改 */ define('DB_COLLATE', '');
配置MySQL数据库服务器
~]# yum install -y mysql mysql-server ~]# service mysqld start ~]# mysql mysql> create database wpdb; mysql> grant all on wpdb.* to 'wpadmin'@'172.16.%.%' identified by '123456'; mysql> flush privileges;
访问测试
http://172.16.72.1/wordpress/
到此,试验结束。
时间: 2024-10-11 12:12:40