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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web服务器(LAMP)通过DNS轮询功能和nfs共享实现负载均衡相关的知识,希望对你有一定的参考价值。

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. [email protected] (
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

以上是关于web服务器(LAMP)通过DNS轮询功能和nfs共享实现负载均衡的主要内容,如果未能解决你的问题,请参考以下文章

NFS共享关系型数据库利用DNS轮询提供Web负载均衡

NFS共享web资源,DNS轮询实现Web负载均衡的小实验

基于NFS实现lamp的负载均衡之一: 实验拓扑

LAMP配置NFS页面共享,autofs实现挂载,DNS实现名称解析,纯手动操作

Nginx+NFS+LAMP主从架构

十四.nginx,web,反向代理,调用加权轮询算法,nfs服务