Haproxy+keepalivd+varnish+LAMP实验
来源:互联网 发布:tld算法opencv代码 编辑:程序博客网 时间:2024/06/08 19:40
来源URL:http://lxlxlx.blog.51cto.com/3363989/1897108?blog1
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
[root@node3 ~]
# cd /etc/httpd/conf.d/
[root@node3 conf.d]
# vim vhost.conf
<VirtualHost 172.16.76.30:8080>
DocumentRoot
/apps/www/html/
ServerNamewww.linuxinfo.
top
ErrorLoglogs
/bbs-8080
.error_log
Customloglogs
/bbs-8080
.access_log combined
<Directory
"/apps/www/html/"
>
Options None
AllowOverrideNone
Require allgranted
<
/Directory
>
<
/VirtualHost
>
<VirtualHost 172.16.76.30:80>
DocumentRoot
/var/www/html/
ServerNamewww.linuxinfo.
top
ErrorLoglogs
/bbs
.error_log
Customloglogs
/bbs
.access_log combined
#单独记录日志
<Directory
"/var/www/html/"
>
Options None
AllowOverrideNone
Require all granted
<
/Directory
>
<
/VirtualHost
>
[root@node3 conf.d]
# vim ../conf/httpd.conf
Listen 80
Listen 8080
#设置Httpd监听端口;
#DocumentRoot "/var/www/html" #将该行注释;
[root@node3 conf.d]
# systemctl restarthttpd.service
[root@node3 ~]
# mysql
MariaDB [(none)]>grantall on
test
.* to
test
@
'localhost'
identified by
"test"
;
MariaDB [(none)]> grant all on
test
.*to
test
@
'127.0.0.1'
identified by
"test"
;
MariaDB [(none)]> grant all on
test
.* totest@
'172.16.76.40'
identified by
"test"
;
#此处允许172.16.76.40访问。
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
[root@node4 ~]
# cd /etc/httpd/conf.d/
[root@node4 conf.d]
# vim vhost.conf
<VirtualHost 172.16.76.40:8080>
DocumentRoot
/apps/www/html/
ServerNamewww.linuxinfo.
top
ErrorLoglogs
/bbs-8080
.error_log
Customloglogs
/bbs-8080
.access_log combined
<Directory
"/apps/www/html/"
>
Options None
AllowOverrideNone
Require all granted
<
/Directory
>
<
/VirtualHost
>
<VirtualHost 172.16.76.40:80>
DocumentRoot
/var/www/html/
ServerNamewww.linuxinfo.
top
ErrorLoglogs
/bbs
.error_log
Customloglogs
/bbs
.access_log combined
<Directory
"/var/www/html/"
>
Options None
AllowOverrideNone
Require all granted
<
/Directory
>
<
/VirtualHost
>
[root@node4 conf.d]
# vim ../conf/httpd.conf
Listen 80
Listen 8080
#设置Httpd监听端口;
#DocumentRoot "/var/www/html" #将该行注释;
[root@node4 conf.d]
# systemctl restart httpd.service
1
2
3
[root@node3 ~]
#cd /var/www/html/
[root@node3 ~]
#unzip Discuz_X3.3_SC_UTF8_0101.zip -d html
[root@node3 ~]
# chown -Rapache.apache html/
1
2
3
4
root@node3 ~]
#cd /var/www/
[root@node3 ~]
#tar –cvf html.tar html/
[root@node3 ~]
#scp html.tar 172.16.76.40:/var/www/
[root@node3 ~]
#scp html.tar 172.16.76.40:/apps/www/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@node4 ~]
#cd /var/www/
[root@node4 www]
# tar –xvf html.tar
[root@node4 www]
# cd /apps/www
[root@node4 www]
# tar –xvf html.tar
注:因整个完整目录整体从172.16.76.30拷贝而来此处,所以需要修改mysql的连接地址;
[root@node4 ~]
#cd /var/www/
[root@node4 upload]
# vim config/config_global.php
$_config[
'db'
][
'1'
][
'dbhost'
] =
'172.16.76.30'
;
#此处设置mysql地址;
[root@node4 upload]
# vim config/config_ucenter.php
define(
'UC_DBHOST'
,
'172.16.76.30'
);
[root@node4 upload]
# vim uc_server/data/config.inc.php
define(
'UC_DBHOST'
,
'172.16.76.30'
);
即此处共计修改三个文件:
config
/config_global
.php
config
/config_ucenter
.php
uc_server
/data/config
.inc.php
同上: 172.16.76.40:8080 虚拟主机目录
/apps/www/
也需要修改以上三个文件。
至此LAMP全部配置完成;
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
[root@node1~]
# cd /etc/haproxy/
root@node1 haproxy]
# vim haproxy.cfg
global
log 127.0.0.1 local2 info
#日志配置
chroot
/var/lib/haproxy
pidfile
/var/run/haproxy
.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unixsocket
stats socket
/var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0
/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive10s
timeout check 10s
maxconn 3000
frontend www
bind *:80
mode http
option forwardfor header Client-IP
log global
配置:以.php结尾所有url调度至webser服务器组即:dyanamc-web组;
以.css .js等结尾与usrl中包含
/static/imagesd
等字符的请求调至webser-static
即:static-web服务器组中;
acl web url_end -i .php
acl url_static url_beg -i
/static
/images
/javascript
acl url_static url_reg -i .js.*$ .css.*$ .jpg.*$ .png.*$.gif.*$
use_backend webser
if
web
use_backend webser-static ifurl_static
default_backend webser
backend webser
mode http
option redispatch
option abortonclose
option forwardfor header Client-IP
#将真实ip转发至后端web;http日志设置
balance
source
#source调度算法;会话保持(注:看最后测试)
cookie SERVERID
option httpchk GET
/upload/forum
.php
server web1 172.16.76.30:80 cookie server1 weight 6 check inter 2000 \
rise 2 fall 3
server web2 172.16.76.30:8080 cookie server1 weight 6 check inter 2000 \
rise 2 fall 3
backend webser-static
server web1 172.16.76.60:80 check inter2000 rise 2 fall 3
listen admin_stats
bind *:9188
mode http
stats refresh 30s
stats uri
/haproxy-status
#配置监控页面url
stats realm welcomelogin\ Haproxy
stats authadmin:adminpass
#监控界面验证用户密码
stats hide-version
stats admin
if
TRUE
acl client src 172.16.250.186
block unless client
#此处配置除172.16.250.186ip之外其余ip禁止访问监控页面;
[root@node1haproxy]
# systemctl restart haproxy 重启haproxy;
因Haproxy配置高可用间此配置文件拷贝至node2即可;
[root@node1 haproxy]
#scp haproxy.cfg172.16.76.20:/etc/haproxy
1
2
3
4
5
6
[root@node1 ~]
# vim /etc/rsyslog.d/haprxoy.conf
$Modload imudp
$UDPServerRun 514
local2.*
/var/log/haproxy/haproxy_info
.log
[root@node1 ~]
# vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS=
"-c 2 -r -m 0"
#配置接收远程日志
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
[root@node1 ~]
# cd /etc/keepalived/
[root@node1 keepalived]
# cat keepalived.conf
! Configuration File
for
keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_fromkeepadmin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4224.0.76.100
}
vrrp_script check_haproxy {
script
"killall -0haproxy"
interval 2
weight 21
}
vrrp_instance HAporxy_VIP1 {
state MASTER
# haproxy2 即node2上为BACKUP
interface eth0
virtual_router_id 100
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass test1111
}
virtual_ipaddress {
172.16.76.100
/16
deveth0 label eth0:0
}
notify_master
"/etc/keepalived/notify.sh master VIP1 vrid100"
notify_backup
"/etc/keepalived/notify.sh backup VIP1 vrid100"
notify_fault
"/etc/keepalived/notify.sh fault VIP1 vrid100"
track_script {
check_haproxy
}
}
vrrp_instance HAprxoy_VIP2 {
state BACKUP
# haproxy2 即node2上为MASTER
interface eth0
virtual_router_id 110
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1111test
}
virtual_ipaddress {
172.16.76.110
/16
deveth0 label eth0:1
}
notify_master
"/etc/keepalived/notify.sh master VIP2 vrid110"
notify_backup
"/etc/keepalived/notify.sh backup VIP2 vrid110"
notify_fault
"/etc/keepalived/notify.sh fault VIP2 vrid110"
track_script {
check_haproxy
}
}
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
notify.sh 脚本
#!/bin/bash
#
info=
"$2$3"
contact=
'root@localhost'
notify(){
mailsubject=
"$(hostname) $info tobe $1, vip floating"
mailbody=
"$(date +'%F %T'): vrrptransition, $(hostname) $info changed to be $1"
echo
"$mailbody"
| mail -s
"$mailsubject"
$contact
}
case
$1
in
master)
notify master $2 $3
;;
backup)
notify backup $2 $3
;;
fault)
notify fault $2 $3
;;
*)
echo
"Usage: $(basename$0) {master|backup|fault}"
exit
1
;;
esac
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
[root@node6~]
# cd /etc/varnish/
[root@node6 varnish]
# cat default.vcl
vcl 4.0;
import
directors;
probe static {
.url =
"/upload/forum.php"
;
.interval = 5s;
.timeout = 1s;
}
backend web1 {
.host =
"172.16.76.50"
;
.port =
"8080"
;
.probe = static;
}
backend web2 {
.host =
"172.16.76.40"
;
.port =
"8080"
;
.probe = static;
}
sub vcl_init {
new webser =directors.round_robin();
webser.add_backend(web1);
webser.add_backend(web2);
}
acl purgers {
"172.16.76.30"
/32
;
"172.16.76.40"
/32
;
}
sub vcl_purge {
return
(synth(200,
"Purged"
));
}
sub vcl_recv {
if
(req.restarts == 0) {
if
(req.http.x-forwarded-
for
) {
setreq.http.X-Forwarded-For = req.http.X-Forwarded-For +
","
+client.ip;
}
else
{
setreq.http.X-Forwarded-For = client.ip;
}
}
set
req.backend_hint =webser.backend();
if
(req.url ~
"\.(html|jpg|png|bmp|jpeg|gif|js|ico|swf|css)$"
) {
unset
req.http.cookie;
}
if
(req.method ==
"PURGE"
) {
if
(!client.ip ~ purgers) {
return
(synth(405,
"Purgingnot allowed for "
+ client.ip));
}
return
(purge);
}
}
sub vcl_backend_response {
}
sub vcl_deliver {
if
(obj.hits>0) {
set
resp.http.X-Cache =
"Hit Via"
+
" "
+ server.ip;
}
else
{
set
resp.http.X-Cache =
"Miss Via"
+
" "
+server.ip;
}
}
0 0
- Haproxy+keepalivd+varnish+LAMP实验
- haproxy + varnish cache配置
- HAProxy+Varnish动静分离部署WordPress
- HAproxy+varnish动静分离部署wordpress
- HAproxy+varnish动静分离部署wordpress
- 基于Keepalived+Haproxy+Varnish+LNMP企业级架构
- lamp的架构之haproxy
- 简单的Haproxy实验
- 中小企业web集群方案 haproxy+varnish+LNMP+memcached配置
- 中小企业web集群方案 haproxy+varnish+LNMP+memcached配置
- Varnish
- Varnish
- Varnish
- varnish
- varnish
- Varnish
- varnish
- varnish
- Jetty和tomcat的比较
- 软件定义存储的定义与分类
- psftp的用法(超级详细)
- javascript 函数和作用域(函数,this)(六)
- React-Native之微信好友、朋友圈分享、支付
- Haproxy+keepalivd+varnish+LAMP实验
- Tomcat报 Exception in thread "http-bio-8080-exec-10" 错的解决方法
- andoid 逆向——两种不同的寄存器表示方法
- tracker-P2P服务器架设
- java并发编程实践学习(11)性能和可伸缩性
- sublime text3 本地服务器配置问题
- 视频会议H460防火墙穿越
- 题目1159:坠落的蚂蚁
- 不可改变位权限:chattr