前言:由于服务器资源有限,keepalived未配主主、只配了一个VIP。本人在香港机房生产环境部署的实际案例,从2013年9月开始运行,服务从未挂过。由于涉及到生产环境,系统展示就不贴出来了。希望大家给予意见!Webserver部署的是lnmp环境,采用我自己写的一键编译安装脚本,安装目录在/data/webserver/。如大家想借鉴我的编译安装脚本,请留言向我索取。
一、架构规划
1、服务器IP地址规划 VIP:192.168.1.6 real_server1:192.168.1.7 real_server2:192.168.1.8 WebServer1:192.168.1.9 WebServer2:192.168.1.10 memcache: 192.168.1.11 mysql主:192.168.1.12 mysql从:192.168.1.2 2、服务器操作系统 所使用的操作系统均为CentOS 6.4 3、网络拓扑图
二、负载服务器配置
1.LVS主服务器配置 安装yum install keepalived ipvsadm
chkconfig keepalived on vim /etc/ keepalived/keepalived.conf 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| global_defs {
notification_email {
yunwei@admin.com
}
notification_email_from
smtp_server 127.0.0.1
#smtp_connect_timeout 30
router_id LVS_DEVEL_1
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.6
}
}
virtual_server 192.168.1.6 80 {
delay_loop 6
#lb_algo wrr
lb_algo rr
lb_kind DR
#persistence_timeout 300
protocol TCP
real_server 192.168.1.7 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.8 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
|
2.LVS前端服务器配置(real_server)
2.1 vim /usr/local/bin/lvs_real
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| VIP=192.168.1.6
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
|
2.2 编译安装nginx,此处省略(使用我自己写的一键编译安装脚本安装)
2.3 LVS前端服务器nginx配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| server {
listen 80;
server_name sandy.com;
location / {
proxy_redirect off;
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 ;
}
location /coocaa_status {
stub_status on;
access_log /data/log/nginx_status.log;
auth_basic "NginxStatus";
allow 192.168.0.58;
deny all;
}
access_log /data/log/access.log access;
error_log /data/log/error.log warn;
}
upstream sandy {
sticky;
server 192.168.1.9:80; #后端webserver1内网IP
server 192.168.1.10:80; #后端webserver2内网IP
}
}
|
三、Webserver服务器配置
1.编译安装nginx、php,此处省略(使用我自己写的一键编译安装脚本安装)
2.webserver服务器nginx配置,如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
| user nginx;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log /data/log/error.log debug;
pid /data/webserver/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 3000;
fastcgi_read_timeout 3000;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
log_format access '\$remote_addr - \$remote_user [\$time_local] "\$request" ' '\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for" - "\$http_soapaction"';
server
{
listen 80;
server_name 0.0.0.0; #webserver外网ip
index index.html index.php;
root /data/www/cloudservice/;
#autoindex on;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location /Framework/tvos/ {
try_files \$uri \$uri/ /Framework/tvos/index.php?\$args;
}
# nginx status
location /coocaa_status {
stub_status on;
access_log /data/log/nginx_status.log;
auth_basic "NginxStatus";
allow 192.168.0.58;
deny all;
}
location ~ \.php$ {
root /data/www/cloudservice;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/cloudservice/$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$
{
expires 30d;
}
location ~ .*\.(js|css)?\$
{
expires 1h;
}
access_log /data/log/access.log access;
}
}
|
3.PHP-fpm配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| [global]
pid = /data/webserver/php/var/run/php-fpm.pid
error_log = /data/log/php-fpm.error.log
log_level = error
[www]
listen = 127.0.0.1:9000
user = nginx
group = nginx
pm = dynamic
;pm= static
pm.max_children = 200
pm.start_servers = 32
pm.min_spare_servers = 32
pm.max_spare_servers = 200
pm.max_requests = 10240
request_terminate_timeout = 900
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /tmp
catch_workers_output = yes
access.log = /data/log/php-fpm.access.log
request_slowlog_timeout = 5
slowlog = /data/log/www-slow.log
pm.status_path = /status
rlimit_files = 65535
|
四、Memcache服务器部署
1.安装memcached
1
2
3
4
5
6
7
8
9
10
| yum -y install libevent libevent-devel make gcc gcc-c++ build-essential make
memcached (){
pwd
wget -c http://42.120.20.242/memcached-1.4.15.tar.gz
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15/
./configure --with-libevent=/usr/local --prefix=/usr/local/memcached
make &&make install
cd ../
|
2.开启memcached实例,本项目中开了两个实例。如下
memcached -d -m 2500 -u root -l 192.168.1.13 -p 11211 -c 20480 -P /tmp/memcached.pid –v memcached -d -m 2500 -u root -l 192.168.1.13 -p 11212 -c 20480 -P /tmp/memcached2.pid –v
五、Mysql服务器配置
后续整理
|