web服务器(LAMP)通过DNS轮询功能和nfs共享实现负载均衡

本文介绍了一种利用LAMP架构实现Discuz论坛负载均衡的方法,包括通过DNS轮询分散访问请求,以及使用NFS共享存储确保数据一致性。具体步骤涉及安装配置Mariadb、Apache、PHP-FPM等组件。
摘要由CSDN通过智能技术生成

web服务器(LAMP)通过DNS轮询功能和nfs共享实现负载均衡,部署discuz论坛

拓扑思路:

服务器1:mariadb+nfs;172.20.120.40

服务器2:apache+php-fpm;172.20.120.41

服务器3:apache+bind;172.20.120.42

服务器1:mariadb+nfs;172.20.120.40

yum install mariadb-server nfs-utils

部署nfs共享;分别使用lvm当做数据库目录/mydata、网页文件目录/vhosts;

yum install mariadb-server nfs-utils -y

fdisk -l /dev/sda

partx -a /dev/sda

pvcreate /dev/sda3

vgcreate vg01 /dev/sda3

lvcreate -L 8G -n mydata vg01

lvcreate -L 8G -n myhtdoc vg01

mkfs -t xfs /dev/vg01/mydata

mkfs -t xfs/dev/vg01/myhtdoc

mkdir /mydata

mkdir /vhosts

vim /etc/fstab 添加如下

/dev/vg01/mydata /mydata xfs defaults 0 0
/dev/vg01/myhtdoc /vhosts xfs defaults 0 0

mount -a

vim /etc/exports

/vhosts 172.20.120.41(rw,no_root_squash) 172.20.120.42(rw,no_root_squash)

cp /usr/share/mysql/my-large.cnf /etc/my.cnf

vim /etc/my.cnf

innodb_file_per_table = on
skip_name_resolv = on
datadir = /mydata/data

mkdir -pv /mydata/data

chown mysql:mysql /mydata/data

systemctl enable nfs mariadb

systemctl start nfs mariadb

mysql_secure_installation

下载discuz并上传网页文件到/vhosts/web1目录下

服务器2:apache+php-fpm;172.20.120.41

yum install httpd php-fpm php-mysql nfs-utils -y

vim /etc/fstab

172.20.120.40:/vhosts /vhosts nfs defaults,_netdev 0 0

mount -a

vim /etc/httpd/conf/htttpd.conf

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.html

<VirtualHost :80>
ServerName bbs.lewis.com
DocumentRoot /vhosts/web1
ProxyRequests off
ProxyPassMatch ^/(.
.php(/.*)?)$ fcgi://172.20.120.41:9000/vhosts/web1/$1
<Directory "/vhosts">
Require all granted
Options none
AllowOverride none
</Directory>
</VirtualHost>

vim /etc/php-fpm.d/www.conf

listen = 172.20.120.41:9000

listen.allowed_clients = 172.20.120.41,172.20.120.42

systemctl enable httpd php-fpm

systemctl start httpd php-fpm

服务器3:apache+bind;172.20.120.42

yum install httpd bind nfs-utils -y

vim /etc/fstab

172.20.120.40:/vhosts /vhosts nfs defaults,_netdev 0 0

mount -a

vim /etc/httpd/conf/htttpd.conf

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.html

<VirtualHost :80>
ServerName bbs.lewis.com
DocumentRoot /vhosts/web1
ProxyRequests off
ProxyPassMatch ^/(.
.php(/.*)?)$ fcgi://172.20.120.41:9000/vhosts/web1/$1
<Directory "/vhosts">
Require all granted
Options none
AllowOverride none
</Directory>
</VirtualHost>

vim /etc/named.conf

options {
listen-on port 53 { 172.20.120.42; };
// listen-on-v6 port 53 { ::1; };
allow-query { 172.20.120.0/16; };

vim /etc/named.rfc1912.zones

zone "lewis.com" IN {
type master;
file "lewis.com.zone";
allow-update { none; };
};

vim /var/named/lewis.com.zone

$TTL 1D
@ IN SOA ns.lewis.com. root@localhost (
2018060501
2H
20M
1W
1D
)
IN NS ns.lewis.com.
ns IN A 172.20.120.42
bbs IN A 172.20.120.41
bbs IN A 172.20.120.42
lewis.com. IN A 172.20.120.42
lewis.com. IN A 172.20.120.41

systemctl enable httpd named

systemctl start httpd named

转载于:https://blog.51cto.com/11476314/2159913

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值