成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Puppe根據節點機器名推送并自動執行SHELL腳本

原創
運維 系統運維
本文介紹了Puppe根據節點機器名推送并自動執行SHELL腳本的方法。puppet服務器和客戶端都已下載了epel的外部yum源,都已通過yum程序自動安裝了puppet程序,機器都放置在同一局域網內,cn7788.com的域名,內部有內網DNS環境,沒有用LDP作為域控,局域網還有其它客戶端,所以就不再贅述了。

【51CTO原創稿件】puppet的基礎環境介紹:puppet服務器和客戶端都已下載了epel的外部yum源,都已通過yum程序自動安裝了puppet程序,過程比較簡單,這里就不一一介紹了,機器都放置在同一局域網內,cn7788.com的域名,內部有內網DNS環境,沒有用LDP作為域控,局域網還有其它客戶端,由于不需要使用puppet環境,所以就不再贅述了。

  • server.cn7788.com 192.168.1.124  puppet-master
  • client.cn7788.com 192.168.1.125  puppet-client
  • lamp.cn7788.com 192.168.1.126  puppet-client
  • xen.cn7788.com  192.168.1.144  puppet-client

  大家可以將上面的域名對應關系可將其都寫在各自機器的/etc/hosts文件里,在各個puppet客戶端上建議ntpdate精準對時(因為puppet的證書對時間要求嚴格),不然puppet-client連接時會報如下錯誤:

warning: peer certificate won't be verified in this SSL session
info: Caching certificate for client.cn7788.com
info: Caching certificate_revocation_list for ca
err: Could not retrieve catalog from remote server: certificate verify failed.  This is often because the time is out of sync on the server or client
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
err: Could not send report: certificate verify failed.  This is often because the time is out of sync on the server or client

  需求如下:客戶機機器xen.cn7788.com和lamp.cn7788.com沒有安裝nagios客戶端程序,這時想過通過puppet-server推送SHELL腳本自動安裝,其它的客戶端暫時沒這么需求,這個應該如何實現呢?

  由于客戶端節點機器比較多,所以這里需要用到節點和模塊的概念,這里我們先建立名為nagioscli的模塊,如下所示:

mkdir -p /etc/puppet/modules/nagioscli/{manifests,files,templates}

  files目錄下的nagioscli.sh文件內容如下所示:

#!/bin/bash
useradd nagios
cd /usr/local/src
wget wget  http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz
wget http://syslab.comsenz.com/downloads/linux/nrpe-2.12.tar.gz
tar zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure
make
make install
chown nagios:nagios /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios/libexec
cd ../
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
sed -i 's@allowed_hosts=127.0.0.1@allowed_hosts=114.112.11.11@'/usr/local/nagios/etc/nrpe.cfg
#114.112.11.11為nagios服務器的IP地址,這個可以根據實際需求更改。
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

  site.pp文件內容如下:

import "node.pp"

  這里擴展了site.pp文件內容,它會載入node.pp文件,這樣puppet-master在啟動的時候,就會自動截入并處理node.pp文件了。

  node.pp文件內容如下所示:

node 'lamp.cn7788.com'{
file
{"/usr/local/src/nagioscli.sh":
source => "puppet://server.cn7788.com/modules/nagioscli/nagioscli.sh",
group => root,
owner => root,
mode  => 755,
}
exec {
"auto install naigios client":
command =>"sh /usr/local/src/nagioscli.sh ",
user =>"root",
path => ["/usr/bin","/usr/sbin","/bin","/bin/sh"],
}
}
node 'xen.cn7788.com'{
file
{"/usr/local/src/nagioscli.sh":
source => "puppet://server.cn7788.com/modules/nagioscli/nagioscli.sh ",
group => root,
owner => root,
mode  => 644,
}
exec {
"auto install naigios client":
command =>"sh /usr/local/src/nagioscli.sh ",
user =>"root",
path => ["/usr/bin","/usr/sbin","/bin","/bin/sh"],
}
}
node 'client.cn7788.com'{
}

  client.cn7788.com節點機器后面什么都沒有,則表示沒有任何操作在此節點機器上面,因為client機器也在puppet環境里,并配置成了自動連接,配置成如此,是防止自動連接時puppet頻繁報錯。

  這里以xen.cn7788.com為例,在其主機上輸入如下命令:

puppetd --test --server server.cn7788.com

  xen.cn7788.com上命令顯示結果如下所示:

info: Caching catalog for xen.cn7788.com 
info: Applying configuration version '1382622383' 
--- /usr/local/src/nagioscli.sh 2013-10-24 22:35:36.000000000 +0800 
+++ /tmp/puppet-file.22857.0    2013-10-24 22:39:08.000000000 +0800 
@@ -1,4 +1,5 @@ 
#!/bin/bash 
+yum -y install httpd gcc gcc-c++ glibc glibc-common gd gd-devel 
useradd nagios 
cd /usr/local/src 
wget wget  http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz 
info: FileBucket adding {md5}f75e9aa3fc301c8e9c85f2677feaa9b5 
info: /Stage[main]//Node[xen.cn7788.com]/File[/usr/local/src/nagioscli.sh]: Filebucketed /usr/local/src/nagioscli.sh to puppet with sum f75e9aa3fc301c8e9c85f2677feaa9b5 
notice: /Stage[main]//Node[xen.cn7788.com]/File[/usr/local/src/nagioscli.sh]/content: content changed '{md5}f75e9aa3fc301c8e9c85f2677feaa9b5' to '{md5}a1ed4dc2b98450e3144530f32677f736' 
notice: /Stage[main]//Node[xen.cn7788.com]/Exec[auto install naigios client]/returns: executed successfully 
notice: Finished catalog run in 283.11 seconds 

  執行時間比較長,總共耗時283.11秒,我們要檢查下xen.cn7788.com的節點機器上是否開啟了nrpe 進程,輸入命令如下所示:

ps aux | grep nrpe | grep -v grep

  命令顯示結果如下所示:

nagios   22331  0.0  0.1   5108   924 ?        Ss   22:35   0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

  我們檢查下/etc/rc.local,看此命令有沒有添加進去,命令如下:

grep -v "^#" /etc/rc.local

  命令執行結果顯示如下所示:

touch /var/lock/subsys/local
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

檢查結果說明puppet-master的nagioscli模塊是正常的,lamp.cn7788.com的結果類似,這里就不再貼出檢測結果了,我們主要看下lamp.cn7788.com總共耗時多少,如下所示:

25 Oct 17:18:20 ntpdate[1095]: step time server 61.153.197.226 offset 59846.166767 sec
[root@lamp src]# puppetd --test --server server.cn7788.com
info: Caching catalog for lamp.cn7788.com
info: Applying configuration version '1382622383'
notice: /Stage[main]//Node[lamp.cn7788.com]/Exec[auto install naigios client]/returns: executed successfully
notice: Finished catalog run in 169.08 seconds

  執行時間比較長,總共耗時169.08秒。

  其實工作中像這種推送腳本執行的需求還是很多的,類似在各種不同名字的節點上執行的優化服務器命令、批量清除varnish緩存加速服務器緩存、根據機器名推送文件,我們只需要將此案例稍為變通下即可在工作中投入應用了。

個人博客:http://andrewyu.blog.51cto.com

微博地址:http://weibo.com/yuhongchun027

【聲明】本文作者:余洪春(撫琴煮酒),英文名Andrew.Yu。在51CTO系統頻道首發,轉載請注明作者和出處。

責任編輯:黃丹 來源: 51CTO.com
相關推薦

2009-12-03 10:06:33

Ubuntushell腳本

2017-07-03 12:19:46

LinuxShell交換文件

2019-11-13 08:31:43

Oracle數據庫腳本

2017-08-30 17:21:05

LinuxShell超時現象

2020-12-14 06:57:37

shell

2016-12-20 09:30:22

shell腳本linux

2021-01-12 10:10:41

shell腳本Linux命令

2021-01-08 08:06:19

腳本Shell文件

2017-01-18 20:38:36

LinuxShell腳本命令

2020-04-01 15:11:36

Shell命令Linux

2024-11-27 09:19:25

2019-08-09 13:50:08

shellLinux

2021-03-11 10:48:33

機器學習數據清理

2022-09-09 08:51:42

ShellLinux

2016-08-23 10:00:28

LinuxPython腳本

2025-06-05 08:20:00

Shell腳本Linux系統管理

2022-10-17 15:59:40

Shell腳本終端

2022-06-09 08:07:15

Shell腳本Linux

2025-05-08 09:05:00

Shell腳本磁盤日志

2011-09-27 13:52:41

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产亚洲一级 | 天天操天天天干 | 国内精品视频在线 | 亚洲第一天堂 | 超碰在线国产 | 日韩精品视频在线 | 懂色av蜜桃av | 婷婷丁香在线视频 | 精品免费国产 | 精品国偷自产在线 | 一区二区在线 | 免费视频一区二区 | 亚洲一区二区精品视频 | 久久蜜桃av一区二区天堂 | 亚洲 欧美 精品 | 国产精品高潮呻吟久久aⅴ码 | 精品免费国产一区二区三区 | 久久精品久久久 | 毛片毛片毛片毛片毛片 | 欧美精品乱码99久久影院 | 99久久婷婷国产亚洲终合精品 | 欧美在线 | 色播av| 亚洲日韩中文字幕一区 | 亚洲视频在线一区 | 国内精品久久久久久 | 草草视频在线观看 | 极品国产视频 | 欧美一区二区三区在线 | 特级黄一级播放 | 91亚洲精选 | 欧美一区二区成人 | 成人精品在线观看 | 久久亚洲一区二区三区四区 | 欧美久久久久久久久 | 91一区二区三区在线观看 | 亚洲免费视频一区二区 | 欧美视频在线播放 | 天天弄天天操 | 羞羞羞视频 | 久久精品国产免费一区二区三区 |