實(shí)驗(yàn)環(huán)境品洛,同步所有主機(jī)的時(shí)間、設(shè)置主機(jī)名并修改hosts文件使能互相解析
主機(jī)名舅世、實(shí)現(xiàn)能互相基于秘鑰的驗(yàn)證髓梅、在node1着饥、node2篓冲、node3寒锚、node4節(jié)點(diǎn)安裝好puppet
1、創(chuàng)建keepadlived的puppet資源清單文件
[root@node1 app]#vim keepalived.pp
class keepalived { #創(chuàng)建一個(gè)父類
package {'keepalived':
ensure => present
}-> #表示此資源優(yōu)先于后面的service資源
service {'keepalived':
ensure => running,
hasrestart => true,
restart => 'systemctl restart keepalived'
}
}
class keepalived::master inherits keepalived { #創(chuàng)建一個(gè)子類乓旗,子類的名字為父類名::子類名府蛇,inherits表示從哪個(gè)父類繼承
file {'/etc/keepalived/keepalived.conf':
ensure => file,
source => '/app/keepalived-master.conf',
require => Package['keepalived'] #要想運(yùn)行此資源需要先運(yùn)行package資源
}
Service['keepalived'] { #在子類中調(diào)用父類中的資源service
subscribe => File['/etc/keepalived/keepalived.conf'] #在子類中對父類的資源新增加一個(gè)屬性,屬性為訂閱file資源屿愚,也就是只有file資源運(yùn)行了才會(huì)運(yùn)行此資源汇跨,也可以在file資源中notify此資源
}
}
class keepalived::backup inherits keepalived {
file {'/etc/keepalived/keepalived.conf':
source => '/app/keepalived-backup.conf',
ensure => file,
require => Package['keepalived']
}
Service['keepalived'] {
subscribe => File['/etc/keepalived/keepalived.conf']
}
}
include keepalived::master #在node1上調(diào)用此子類
在node2上調(diào)用include keepalived::backup子類
2务荆、在node1上keepalived的配置文件
[root@node1 app]#vim /app/keepalived-master.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from node1@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.21.21.21#注意要加上這個(gè)多播地址,配置文件中原來是沒有的穷遂,需要后加上
}
vrrp_script chk_down {
script "[ -f /etc/keepalived/down ] && exit 1 || exit 0" #返回結(jié)果為1則優(yōu)先級減20
interval 1
weight -20
}
vrrp_script chk_nginx {
script "killall -0 nginx &>/dev/null &&exit 0||exit 1" #監(jiān)控nginx服務(wù)的腳本
interval 1
weight -20
fall 2
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface ens37
virtual_router_id 88
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.18.21.88 dev ens37
}
track_script { #調(diào)用前面的腳本
chk_down
chk_nginx
}
}
3蛹含、在node2上keepalived的配置文件
[root@node3 app]#vim /app/keepalived-backup.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from node3@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node3
vrrp_mcast_group4 224.21.21.21
}
vrrp_script chk_down {
script "[ -f /etc/keepalived/down ] && exit 1 || exit 0"
interval 1
weight -20
}
vrrp_script chk_nginx {
script "killall -0 nginx &>/dev/null &&exit 0||exit 1"
interval 1
weight -20
fall 2
rise 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 88
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.18.21.88 dev ens33
}
track_script {
chk_down
chk_nginx
}
}
4、node1和node3上nginx的puppet清單文件和配置文件
[root@node1 app]#vim nginx.pp #nginx的puppet清單文件
class nginx {
package {'nginx':
ensure => present
}->
file {'nginx.conf':
path => '/etc/nginx/nginx.conf',
source => '/app/nginx.conf',
ensure => file,
notify => Service['nginx']
}
service {'nginx':
ensure => running,
hasrestart => true,
restart => 'systemctl reload nginx',
require => Package['nginx']
}
}
include nginx
[root@node1 app]#vim /app/nginx.conf #nginx的配置文件
upstream varnishsrvs {
server 172.18.21.7:6081;
server 172.18.21.200:6081;
}
location / {
proxy_pass http://varnishsrvs;
}
5塞颁、在node2浦箱、node4上varnish的puppet清單文件和varnish配置文件
[root@node2 app]#vim varnish.pp
class varnish {
package {'varnish':
ensure => present
}->
file {'default.vcl':
path => '/etc/varnish/default.vcl',
source => '/app/default.vcl',
ensure => file,
notify => Service['varnish']
}
service {'varnish':
ensure => running,
hasrestart => true,
restart => 'systemctl restart varnish',
require => Package['varnish']
}
}
include varnish
[root@node2 app]#vim /app/default.vcl
backend default {
.host = "172.18.21.6";
.port = "80";
}
sub vcl_deliver {
if (obj.hits>0) {
set resp.http.x-cache = "HIT via" + server.ip; #表示如果命中率大于0,則在返回給客戶端的響應(yīng)報(bào)文中增加一個(gè)首部x-cache祠锣,這個(gè)首部的值為 "HIT via" + server.ip(varnish的ip地址酷窥,說明命中來自哪個(gè)緩存服務(wù)器)
}else {
set resp.http.x-cache = "MISS from" + server.ip;
}
}
6、在node5上安裝好httpd并啟動(dòng)服務(wù)
7伴网、測試
11月26日 用puppet的standalone模式實(shí)現(xiàn)nginx高可用調(diào)度至后端的varnish集群訪問web網(wǎng)站
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門姆另,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人坟乾,你說我怎么就攤上這事迹辐。” “怎么了甚侣?”我有些...
- 文/不壞的土叔 我叫張陵明吩,是天一觀的道長。 經(jīng)常有香客問我殷费,道長印荔,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任宗兼,我火速辦了婚禮躏鱼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘殷绍。我一直安慰自己染苛,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著茶行,像睡著了一般躯概。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上畔师,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼腔寡!你這毒婦竟也來了焚鲜?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬榮一對情侶失蹤放前,失蹤者是張志新(化名)和其女友劉穎忿磅,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體凭语,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡葱她,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了叽粹。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片览效。...
- 正文 年R本政府宣布,位于F島的核電站螃诅,受9級特大地震影響啡氢,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜术裸,卻給世界環(huán)境...
- 文/蒙蒙 一倘是、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧袭艺,春花似錦搀崭、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽升敲。三九已至,卻和暖如春轰传,著一層夾襖步出監(jiān)牢的瞬間驴党,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓恕曲,卻偏偏與公主長得像攘轩,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子码俩,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- keepalived+nginx proxy 直接開始做實(shí)驗(yàn)吧度帮。跟著下面一步步做,基本不會(huì)出問題稿存。 準(zhǔn)備五臺(tái)設(shè)備 ...
- 一笨篷、項(xiàng)目目標(biāo) 搭建一個(gè)高可用web集群網(wǎng)站 二、項(xiàng)目規(guī)劃 2.1 ip地址規(guī)劃 2.2 拓?fù)鋱D 2.3 相關(guān)說明 ...
- 上面的拓?fù)鋱D瓣履,LB1和LB2是兩個(gè)Nginx反向代理率翅,后端RS1和RS2是兩個(gè)Web服務(wù)器。接下來我們通過keep...
- 風(fēng)口過去有一家客棧袖迎,客棧后面是一座青山冕臭,山上有一個(gè)禪寺,久無人煙燕锥。 客棧沒有老板辜贵,只有一個(gè)白面細(xì)皮的賬房先生;一個(gè)...