背景
3台服务器
192.168.9.9 web1
192.168.8.8 web2 mysql
192.168.9.10 web3 Tengine
9.9和8.8配置是一样的 服务器上的程序文件也是一样的NGINX监听在9999端口 如下:
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
[root@localhost conf] # cat nginx.conf
user nginx nginx; worker_processes auto; worker_rlimit_nofile 65535; error_log logs /error .log;
#error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 204800;
use epoll;
multi_accept on;
} 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 main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
server_tokens off;
tcp_nopush on;
#tcp_nodelay on;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_conn addr 100;
gzip on;
gzip_min_length 1000;
gzip_comp_level 4;
gzip_types text /plain text /css application /json application /x-javascript text /xml application /xml application /xml +rss text /javascript ;
include /usr/local/nginx/conf/vhost/ *.conf;
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log off;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x .html;
location = /50x .html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
server { listen *:8890 default_server;
server_name 14.152.90.119;
location /ngx_status {
stub_status on;
access_log off;
# allow 127.0.0.1;
# deny all;
}
} server { listen 80 default_server;
server_name _;
return 500;
} } [root@localhost conf] #
|
Vhost文件配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
server { listen 192.168.8.8:9999;
access_log off;
server_name 192.168.8.8;
root /usr/local/nginx/html ;
index index.html index.php;
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index .php?s=$1 last;
}
}
location ~ \.php$ {
root /usr/local/nginx/html ;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} |
两台WEB都如上配置
MYSQL是默认安装my.cnf如下:
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
|
[root@localhost conf] # cat /etc/my.cnf
[mysqld] datadir= /var/lib/mysql
socket= /var/lib/mysql/mysql .sock
user=mysql max_connections=5000 bind-address=192.168.8.8 skip-name-resolve back_log=1024 key_buffer_size=1500M max_allowed_packet=10M thread_stack=256K table_cache=128K sort_buffer_size=64M read_buffer_size=64M join_buffer_size=64M myisam_sort_buffer_size=64M table_cache=4096 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
[root@localhost conf] #
|
有PHP 采用fastcgi模式 php-fpm配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 user = nginx group = nginx pm = dynamic pm.max_children = 2000 pm.start_servers = 50 pm.min_spare_servers = 50 pm.max_spare_servers = 1024 pm.max_requests = 204800 slowlog = /var/log/php-fpm/www-slow .log
rlimit_files = 51200 php_admin_value[error_log] = /var/log/php-fpm/www-error .log
php_admin_flag[log_errors] = on php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
|
Tengine负载均衡配置跟上面的NGINX配置差不多
在nginx.conf的http{段加上如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
upstream wwwoca { ip_hash;
server 192.168.9.10:9999 weight=10 max_fails=2 fail_timeout=60s;
server 192.168.8.8:9999 weight=5 max_fails=2 fail_timeout=60s;
server 192.168.9.9:9999 weight=10 max_fails=2 fail_timeout=60s;
check interval=5000 rise=2 fall=3 timeout=1000 type =http;
#check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
keepalive 128;
}
proxy_temp_path /usr/local/tengine/proxy_temp ;
proxy_cache_path /usr/local/tengine/proxy_cache levels=1:2 keys_zone=cache_one:1000m inactive=2d max_size=30g;
|
负载均衡虚拟主机配置如下:
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
|
server { listen 80;
access_log off;
server_name www.abc.com;
location / {
#root /usr/local/tengine/html;
index index.html index.php;
proxy_pass http: //wwwoca ;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
#proxy_cache cache_one;
#add_header Nginx-Cache $upstream_cache_status;
#proxy_cache_valid 200 304 301 302 8h;
#proxy_cache_valid 404 1m;
#proxy_cache_valid any 2d;
#proxy_cache_key $host$uri$is_args$args;
#expires 10d;
}
location /status {
check_status;
access_log off;
#allow 127.0.0.1;
#deny all;
}
#location ~ /purge(/.*) {
# allow 127.0.0.1;
# allow 59.39.178.130/32;
# deny all;
# proxy_cache_purge cache_one $host$1$is_args$args;
# error_page 405 =200 /purge$1;
#}
} |
Tengine版本如下:
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
|
[root@www sbin] # ./nginx -V
Tengine version: Tengine /2 .1.2 (nginx /1 .6.2)
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: --prefix= /usr/local/tengine --with-http_ssl_module --with-http_sub_module=shared --with-http_fastcgi_module=shared --with-http_rewrite_module=shared --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_upstream_check_module --with-http_upstream_ip_hash_module=shared --user=nginx --group=nginx
loaded modules: ngx_core_module (static)
ngx_errlog_module (static)
ngx_conf_module (static)
ngx_dso_module (static)
ngx_syslog_module (static)
ngx_events_module (static)
ngx_event_core_module (static)
ngx_epoll_module (static)
ngx_procs_module (static)
ngx_proc_core_module (static)
ngx_openssl_module (static)
ngx_regex_module (static)
ngx_http_module (static)
ngx_http_core_module (static)
ngx_http_log_module (static)
ngx_http_upstream_module (static)
ngx_http_static_module (static)
ngx_http_gzip_static_module (static)
ngx_http_autoindex_module (static)
ngx_http_index_module (static)
ngx_http_auth_request_module (static)
ngx_http_auth_basic_module (static)
ngx_http_access_module (static)
ngx_http_limit_conn_module (static)
ngx_http_limit_req_module (static)
ngx_http_geo_module (static)
ngx_http_map_module (static)
ngx_http_split_clients_module (static)
ngx_http_referer_module (static)
ngx_http_ssl_module (static)
ngx_http_fastcgi_module (shared, 3.1)
ngx_http_proxy_module (static)
ngx_http_uwsgi_module (static)
ngx_http_scgi_module (static)
ngx_http_memcached_module (static)
ngx_http_empty_gif_module (static)
ngx_http_browser_module (static)
ngx_http_upstream_ip_hash_module (shared, 3.1)
ngx_http_user_agent_module (static)
ngx_http_rewrite_module (shared, 3.1)
ngx_http_upstream_consistent_hash_module (static)
ngx_http_upstream_check_module (static)
ngx_http_upstream_least_conn_module (static)
ngx_http_upstream_keepalive_module (static)
ngx_http_upstream_dynamic_module (static)
ngx_http_stub_status_module (static)
ngx_http_write_filter_module (static)
ngx_http_header_filter_module (static)
ngx_http_chunked_filter_module (static)
ngx_http_range_header_filter_module (static)
ngx_http_gzip_filter_module (static)
ngx_http_postpone_filter_module (static)
ngx_http_ssi_filter_module (static)
ngx_http_charset_filter_module (static)
ngx_http_sub_filter_module (shared, 3.1)
ngx_http_gunzip_filter_module (static)
ngx_http_userid_filter_module (static)
ngx_http_footer_filter_module (static)
ngx_http_trim_filter_module (static)
ngx_http_headers_filter_module (static)
ngx_http_upstream_session_sticky_module (static)
ngx_http_reqstat_module (static)
ngx_http_copy_filter_module (static)
ngx_http_range_body_filter_module (static)
ngx_http_not_modified_filter_module (static)
[root@www sbin] #
|
基本完成!
本文转自flyingzf 51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1770321,如需转载请自行联系原作者