四.配置DNS服务器,实现轮询
#安装DNS服务器,并配置named.conf
shell> vim /etc/named.conf
options {
listen-on port 53 { any; };
allow-query { any; };
recursion yes;
#rrset-order表明对bbs.CentOS.com域中的IN记录使用轮询
rrset-order {
class IN typeA name "bbs.centos.com"order cyclic;
};
};
zone "."IN {
typehint;
file"named.ca";
};
zone "centos.com"IN {
typemaster;
file"named.lij.com";
};
zone "54.16.172.in-addr.arpa"IN {
typemaster;
file"named.172.16.54";
};
#配置正解域
shell> vim /var/named/named.centos.com
$TTL 600
@ IN SOA centos.com. ftp. (
2011080404
3H
15M
1W
1D)
@ IN NS ceontos.com.
centos.com. IN A 10.10.54.150
@ IN MX 10 mail.ceontos.com.
mail.centos.com. IN A 10.10.54.151
bbs.centos.com. IN A 172.16.54.150
bbs.centos.com. IN A 172.16.54.151
#重启
shell> /etc/init.d/named restart
#测试DNS轮询是否生效,通过两次ping
shell> ping bbs.centos.com
PING bbs.centos.com (172.16.54.151) 56(84) bytes of data.
64 bytes from 172.16.54.151: icmp_seq=1 ttl=64 time=0.441 ms
#再次ping
shell> ping bbs.centos.com
PING bbs.centos.com (172.16.54.150) 56(84) bytes of data.
64 bytes from 172.16.54.150: icmp_seq=1 ttl=64 time=0.019 ms
#上面可以看到两次ping的IP并不相同
注意:测试机的DNS服务器需要配置为10.10.54.150这台
3.配置两台squid服务器
#编译安装squid
yum install gcc wget perl gcc-c++ make
cd /tmp
wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.19.tar.gz
tar xzf squid-3.1.19.tar.gz
cd squid-3.1.19
./configure --prefix=/usr/local/squid --enable-gnuregex --disable-carp --enable-async-io=240 --with-pthreads --enable-storeio=ufs,aufs,diskd --disable-wccp --enable-icmp --enable-kill-parent-hack --enable-cachemgr-hostname=localhost --enable-default-err-language=Simplify_Chinese --with-maxfd=65535 --enable-poll --enable-linux-netfilter --enable-large-cache-files --disable-ident-lookups --enable-default-hostsfile=/etc/hosts --with-dl --with-large-files --enable-delay-pools --enable-snmp --disable-internal-dns --enable-underscore -enable-arp-acl
make && make install
#创建squid缓存目录,和日志目录
groupadd squid
useradd -g squid -s /sbin/nologin squid
mkdir /squid/data -p
mkdir /squid/log
chown -R squid.squid /squid
#编辑squid配置文件
#用户和用户组
cache_effective_user squid
cache_effective_group squid
#主机名
visible_hostname squid1.lij.com
#配置squid为反向代理模式
http_port 172.16.54.150:80 accel vhost vport
#配置squid2为其邻居,当 squid1 在其缓存中没有找到请求的资源时,通过 ICP查询去其邻居中取得缓存
icp_port 3130
cache_peer 172.16.54.151 sibling 80 3130
#配置squid1的两个父节点(web server),originserver参数指明是源服务器, round-robin参数指明squid通过轮询方式将请求分发到其中一台父节点; squid 同时会对这些父节点的健康状态进行检查,如果父节点 down 了,那么 squid 会从剩余的 origin 服务器中抓取数据
cache_peer 172.16.54.200 parent 80 0 originserver round-robin
cache_peer 172.16.54.201 parent 80 0 originserver round-robin
#下面是一些访问控制、日志和缓存目录的设置
cache_mem 128 MB
maximum_object_size_in_memory 4096 KB
maximum_object_size 10240 KB
cache_dir aufs /squid/data 4000 16 512
coredump_dir /squid/data
#日志路径
cache_access_log /squid/logs/access.log
cache_log /squid/logs/cache.log
cache_store_log /squid/logs/store.log
acl localnet src 10.10.54.0/24
http_access allow all
icp_access allow localnet
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
注意:
1.squid2上配置和squid1上配置完全一样,只需要修改相关IP,如下
visible_hostname squid2.lij.com
http_port 172.16.54.151:80 accel vhost vport
icp_port 3130
cache_peer 172.16.54.150 sibling 80 3130
2.两台squid上都要添加hosts记录
vim /etc/hosts
172.16.54.200 squid1.lij.com
172.16.54.201 squid2.lij.com
四.配置nginx服务器
user apache apache;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log;
sendfile off;
keepalive_timeout 65;
# gzip on;
server {
listen 80;
server_name bbs.centos.com;
root /var/www/bbs/upload;
charset utf-8;
index index.php index.html;
access_log logs/bbs.access.log;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
location /server-status {
stub_status on;
allow all;
access_log off;
}
}
五.配置论坛数据库
1.这个web架构为clients-->DNS轮询-->squid加速-->web-->mysql主从
2.负载均衡除了使用DNS轮询之外,也可以使用LVS+keepalieve实现,两台realserver配置为squid1和squid2
3.这篇文章对于两台web之间的数据同步没有提及,但是实际环境中必须要保证数据同步
4.在两台server上安装Discuz_X3.0_SC_UTF8.zip论坛工具,论坛数据库放在master主机上,两台slave实现数据同步。
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
相关阅读:
CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3下Nginx性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx搭建视频点播服务器(仿真专业流媒体软件) http://www.linuxidc.com/Linux/2012-08/69151.htm
更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14