来讲讲:集群运维主动化工具ansible之利用playbook安装zabbix客户端
要多google,因为我不可能,也不可以给你解答所有内容,我只能告诉你一些关键点,甚至我会故意隐瞒答案,因为在寻找答案的过程中。之前先容了关于ansible的安装与利用,明天先容一下怎样利用playbook来部署zabbix客户端。
ansible服务真个情况为centos6.5x86_64体系
ansible客户端情况为centos6.3x86_64体系
今朝我的playbook只同意centos或redhat6系列体系来安装zabbix客户端,而且客户真个版本是2.0.6.
上面是playbook的布局
14:29:30#pwd/etc/ansible/rolesroot@ip-10-10-10-10:/etc/ansible/roles14:29:37#treezabbix_client_*zabbix_client_delete删除已安装的zabbix客户端├──files寄存文件的├──handlers重启的东东├──metagalaxy_info的信息│└──main.yml├──tasks操纵的义务流程│├──delete.yml│└──main.yml├──templates模板└──vars变量└──main.ymlzabbix_client_install├──files│└──zabbix-2.0.6.tar.gz├──handlers├──meta│└──main.yml├──tasks│├──copy.yml│├──delete.yml│├──install.yml│└──main.yml├──templates│├──zabbix_agentd│└──zabbix_agentd.conf└──vars└──main.yml12directories,13files
上面是先先容一下安装方面zabbix_client_install的内容
1、galaxy_info的信息
14:32:15#cat/etc/ansible/roles/zabbix_client_install/meta/main.ymlgalaxy_info:author:DengLeidescription:InstallZabbixClientlicense:MITmin_ansible_version:1.6platforms:-name:CentOSversions:-6categories:-Monitordependencies:[]
2、task里的copy.xml信息
14:33:35#cat/etc/ansible/roles/zabbix_client_install/tasks/copy.yml-name:StopExistZabbixClientServiceInRedhatClientshell:ps-ef|grepzabbix|grep-vgrep|awk{print$2}|xargskill-9>>/dev/null2>&1ignore_errors:yeswhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:DeleteExistZabbixClientDirInRedhatClientshell:rm-rf{{zabbix_dir}}/zabbixignore_errors:yeswhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:InstallBaseRequireSoftwareInRedhatClientyum:name={{item}}state=latestwith_items:-telnet-dmidecode-tar-name:CreateZabbixUserInRedhatClientuser:name={{zabbix_user}}state=presentcreatehome=noshell=/sbin/nologinwhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:CopyZabbixClientSoftwareToRedhatClientcopy:src=zabbix-{{zabbix_version}}.tar.gzdest=/tmp/zabbix-{{zabbix_version}}.tar.gzowner=rootgroup=rootwhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:UncompressionZabbixClientSoftwareToRedhatClientshell:tarzxf/tmp/zabbix-{{zabbix_version}}.tar.gz-C{{zabbix_dir}}/when:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:CopyZabbixStartScriptToRedhatClienttemplate:src=zabbix_agentddest=/etc/init.d/zabbix_agentdowner=rootgroup=rootmode=0755when:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:CopyZabbixConfigToRedhatClienttemplate:src=zabbix_agentd.confdest={{zabbix_dir}}/zabbix/conf/zabbix_agentd.confowner={{zabbix_user}}group={{zabbix_user}}mode=0644when:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6
此文件是复制对应的文件到客户端
3、task的install.yml信息
14:34:26#cat/etc/ansible/roles/zabbix_client_install/tasks/install.yml-name:ModifyZabbixDirPermissionInRedhatClientfile:path={{zabbix_dir}}/zabbixowner={{zabbix_user}}group={{zabbix_user}}mode=0755when:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:CheckZabbixUserSudoPermissionInRedhatClientshell:grep"{{zabbix_user}}"/etc/sudoers|wc-lregister:zabbix_sudoerignore_errors:Truewhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:GiveSudoPermissionToZabbixUserInRedhatClientshell:echo"{{zabbix_user}}ALL=(root)NOPASSWD:/bin/netstat,/usr/bin/omreport">>/etc/sudoerswhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6andzabbix_sudoer|int==0-name:StartZabbixServiceInRedhatClientshell:/etc/init.d/zabbix_agentdstartwhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6-name:AddBootStartZabbixServiceInRedhatClientshell:chkconfig--level345zabbix_agentdonwhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6
此文件次要是安装
4、tasks的delete.yml信息
14:35:08#cat/etc/ansible/roles/zabbix_client_install/tasks/delete.yml-name:DeleteZabbixcompressionSoftwareInRedhatClientshell:rm-rf/tmp/zabbix-{{zabbix_version}}.tar.gzwhen:ansible_os_family=="RedHat"andansible_lsb.major_release|int==6
此文件是安装完成后,删除安装前的文件
5、tasks的mail.yml
14:35:37#cat/etc/ansible/roles/zabbix_client_install/tasks/main.yml-include:copy.yml-include:install.yml-include:delete.yml
此文件是同意运转哪一个文件
6、templates的zabbix_agentd
15:15:45#cat/etc/ansible/roles/zabbix_client_install/templates/zabbix_agentd#!/bin/bash##chkconfig:-8515#description:Zabbixclientscript.#processname:Zabbix./etc/profileSERVICE="Zabbixagent"DAEMON={{zabbix_dir}}/zabbix/sbin/zabbix_agentdPIDFILE=/tmp/zabbix_agentd.pidCONFIG={{zabbix_dir}}/zabbix/conf/zabbix_agentd.confzabbix_agent_status=`psaux|grepzabbix_agentd.conf|grep-vgrep|wc-l`zabbix_agent_pid=`psaux|grepzabbix_agentd|grep-vgrep|awkNR==1{print$2}`#Sourcefunctionlibrary../etc/rc.d/init.d/functions#Sourcenetworkingconfiguration../etc/sysconfig/networkfunctioncheck(){if[$?-eq0];thenaction$"Operatingis:"/bin/trueelseaction$"Operatingis:"/bin/falsefi}case$1instart)if[-x${DAEMON}]then$DAEMON-c$CONFIG#Errorcheckingherewouldbegood...echo"${SERVICE}started."elseecho"Cantfindfile${DAEMON}."echo"${SERVICE}NOTstarted."ficheck;;stop)if[-s${PIDFILE}]thenifkill`cat${PIDFILE}`>/dev/null2>&1thenecho"${SERVICE}terminated."rm-f${PIDFILE}fificheck;;restart)/bin/bash$0stopsleep5/bin/bash$0start;;status)if[$zabbix_agent_status-ne0];thenecho"ZabbixAgentdisrunning($zabbix_agent_pid)"elseecho"ZabbixAgentdisnotrunning!"fi;;*)echo"Usage:$0{start|stop|status|restart}";;esacexit0
这个文件是启动客户真个剧本
7、templates的zabbix_agentd.conf
15:16:36#cat/etc/ansible/roles/zabbix_client_install/templates/zabbix_agentd.conf#ThisisaconfigfilefortheZabbixagentdaemon(Unix)#TogetmoreinformationaboutZabbix,visithttp://www.ckuyun.com############GENERALPARAMETERS####################Option:PidFile#NameofPIDfile.##Mandatory:no#Default:#PidFile=/tmp/zabbix_agentd.pid###Option:LogFile#Nameoflogfile.#Ifnotset,syslogisused.##Mandatory:no#Default:#LogFile=LogFile=/tmp/zabbix_agentd.log###Option:LogFileSize#MaximumsizeoflogfileinMB.#0-disableautomaticlogrotation.##Mandatory:no#Range:0-1024#Default:#LogFileSize=1###Option:DebugLevel#Specifiesdebuglevel#0-nodebug#1-criticalinformation#2-errorinformation#3-warnings#4-fordebugging(produceslotsofinformation)##Mandatory:no#Range:0-4#Default:#DebugLevel=3###Option:SourceIP#SourceIPaddressforoutgoingconnections.##Mandatory:no#Default:#SourceIP=###Option:EnableRemoteCommands#WhetherremotecommandsfromZabbixserverareallowed.#0-notallowed#1-allowed##Mandatory:no#Default:#EnableRemoteCommands=0###Option:LogRemoteCommands#Enableloggingofexecutedshellcommandsaswarnings.#0-disabled#1-enabled##Mandatory:no#Default:#LogRemoteCommands=0#####Passivechecksrelated###Option:Server#ListofcommadelimitedIPaddresses(orhostnames)ofZabbixservers.#Incomingconnectionswillbeacceptedonlyfromthehostslistedhere.#Nospacesallowed.#IfIPv6supportisenabledthen127.0.0.1,::127.0.0.1,::ffff:127.0.0.1aretreatedequally.##Mandatory:no#Default:#Server=zabbix-server-external.autoclouds.netServer={{zabbix_server_ip}}###Option:ListenPort#Agentwilllistenonthisportforconnectionsfromtheserver.##Mandatory:no#Range:1024-32767#Default:ListenPort={{zabbix_port}}###Option:ListenIP#ListofcommadelimitedIPaddressesthattheagentshouldlistenon.#FirstIPaddressissenttoZabbixserverifconnectingtoittoretrievelistofactivechecks.##Mandatory:no#Default:#ListenIP=0.0.0.0###Option:StartAgents#Numberofpre-forkedinstancesofzabbix_agentdthatprocesspassivechecks.#Ifsetto0,disablespassivechecksandtheagentwillnotlistenonanyTCPport.##Mandatory:no#Range:0-100#Default:#StartAgents=3#####Activechecksrelated###Option:ServerActive#ListofcommadelimitedIP:port(orhostname:port)pairsofZabbixserversforactivechecks.#Ifportisnotspecified,defaultportisused.#IPv6addressesmustbeenclosedinsquarebracketsifportforthathostisspecified.#Ifportisnotspecified,squarebracketsforIPv6addressesareoptional.#Ifthisparameterisnotspecified,activechecksaredisabled.#Example:ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,##Mandatory:no#Default:#ServerActive=###Option:Hostname#Unique,casesensitivehostname.#Requiredforactivechecksandmustmatchhostnameasconfiguredontheserver.#ValueisacquiredfromHostnameItemifundefined.##Mandatory:no#Default:#Hostname=Hostname={{ansible_hostname}}###Option:HostnameItem#ItemusedforgeneratingHostnameifitisundefined.#IgnoredifHostnameisdefined.##Mandatory:no#Default:#HostnameItem=system.hostname###Option:RefreshActiveChecks#Howoftenlistofactivechecksisrefreshed,inseconds.##Mandatory:no#Range:60-3600#Default:#RefreshActiveChecks=120###Option:BufferSend#DonotkeepdatalongerthanNsecondsinbuffer.##Mandatory:no#Range:1-3600#Default:#BufferSend=5###Option:BufferSize#Maximumnumberofvaluesinamemorybuffer.Theagentwillsend#allcollecteddatatoZabbixServerorProxyifthebufferisfull.##Mandatory:no#Range:2-65535#Default:#BufferSize=100###Option:MaxLinesPerSecond#MaximumnumberofnewlinestheagentwillsendpersecondtoZabbixServer#orProxyprocessinglogandlogrtactivechecks.#Theprovidedvaluewillbeoverriddenbytheparametermaxlines,#providedinlogorlogrtitemkeys.##Mandatory:no#Range:1-1000#Default:#MaxLinesPerSecond=100###Option:AllowRoot#Allowtheagenttorunasroot.Ifdisabledandtheagentisstartedbyroot,theagent#willtrytoswitchtouserzabbixinstead.Hasnoeffectifstartedunderaregularuser.#0-donotallow#1-allow##Mandatory:no#Default:#AllowRoot=0############ADVANCEDPARAMETERS####################Option:Alias#Setsanaliasforparameter.Itcanbeusefultosubstitutelongandcomplexparameternamewithasmallerandsimplerone.##Mandatory:no#Range:#Default:###Option:Timeout#SpendnomorethanTimeoutsecondsonprocessing##Mandatory:no#Range:1-30#Default:Timeout=20###Option:Include#Youmayincludeindividualfilesorallfilesinadirectoryintheconfigurationfile.#InstallingZabbixwillcreateincludedirectoryin/usr/local/etc,unlessmodifiedduringthecompiletime.##Mandatory:no#Default:#Include=#Include=/usr/local/etc/zabbix_agentd.userparams.conf#Include=/usr/local/etc/zabbix_agentd.conf.d/#######USER-DEFINEDMONITOREDPARAMETERS##########Option:UnsafeUserParameters#Allowallcharacterstobepassedinargumentstouser-definedparameters.#0-donotallow#1-allow##Mandatory:no#Range:0-1#Default:#UnsafeUserParameters=0###Option:UserParameter#User-definedparametertomonitor.Therecanbeseveraluser-definedparameters.#Format:UserParameter=<key>,<shellcommand>#Seezabbix_agentddirectoryforexamples.##Mandatory:no#Default:#UserParameter=UserParameter=memcached_stats
[*],(echostats;sleep1)|telnet{{ansible_default_ipv4.address}}$12>&1|awk/STAT$2/{print$NF}UserParameter=mysql
[*],mysql-h{{ansible_default_ipv4.address}}-P3306-uzabbix-pzabbix-e"showglobalstatus"|grep"<$1>"|cut-f2UserParameter=redis_stats
[*],(echoinfo;sleep1)|telnet{{ansible_default_ipv4.address}}$12>&1|grep$2|cut-d:-f2UserParameter=custom.vfs.dev.read.ops
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$4}UserParameter=custom.vfs.dev.read.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$7}UserParameter=custom.vfs.dev.write.ops
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$8}UserParameter=custom.vfs.dev.write.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$11}UserParameter=custom.vfs.dev.io.active
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$12}UserParameter=custom.vfs.dev.io.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$13}UserParameter=custom.vfs.dev.read.sectors
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$6}UserParameter=custom.vfs.dev.write.sectors
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$10}UserParameter=MongoDB.Status
[*],/bin/echo"db.serverStatus().$1"|/usr/bin/mongoadmin|grep"$2"|awk-F:{print$$2}|awk-F,{print$$1}UserParameter=check_lvm
[*],/usr/bin/sudo/usr/local/zabbix/bin/check_lvm.sh$1UserParameter=TCP_ESTABLISHED,ss-s|awkNR==2{print$4}|cut-d,-f1UserParameter=TCP_CLOSED,ss-s|awkNR==2{print$6}|cut-d,-f1UserParameter=TCP_TIMEWAIT,ss-s|awkNR==2{print$12}|cut-d/-f1UserParameter=zabbix_low_discovery
[*],/bin/bash/usr/local/zabbix/bin/zabbix_low_discovery.sh$1UserParameter=mysql_stats
[*],mysql-h{{ansible_default_ipv4.address}}-P$1-uzabbix-pzabbix-e"showglobalstatus"|grep"<$2>"|cut-f2UserParameter=mysql_stats_slave
[*],mysql-h{{ansible_default_ipv4.address}}-P$1-uzabbix-pzabbix-e"showslavestatusG"|grep"<$2>"|awk{if($NF=="Yes"){print1}else{print0}}UserParameter=check_platform,dmidecode|grepVendor|awk-F{if($2=="Dell"){print1}else{print0}}#followishardwaremonitorUserParameter=hardware_battery,omreportchassisbatteries|awk/^Status/{if($NF=="Ok"){print1}else{print0}}UserParameter=hardware_cpu_model,awk-vhardware_cpu_crontol=`sudoomreportchassisbiossetup|awk/CState/{if($NF=="Enabled"){print0}else{print1}}`-vhardware_cpu_c1=`sudoomreportchassisbiossetup|awk/C1[-|E]/{if($NF=="Enabled"){print0}else{print1}}`BEGIN{if(hardware_cpu_crontol==0&&hardware_cpu_c1==0){print0}else{print1}}UserParameter=hardware_fan_health,awk-vhardware_fan_number=`omreportchassisfans|grep-c"^Index"`-vhardware_fan=`omreportchassisfans|awk/^Status/{if($NF=="Ok")count+=1}END{printcount}`BEGIN{if(hardware_fan_number==hardware_fan){print1}else{print0}}UserParameter=hardware_memory_health,awk-vhardware_memory=`omreportchassismemory|awk/^Health/{print$NF}`BEGIN{if(hardware_memory=="Ok"){print1}else{print0}}UserParameter=hardware_nic_health,awk-vhardware_nic_number=`omreportchassisnics|grep-c"InterfaceName"`-vhardware_nic=`omreportchassisnics|awk/^ConnectionStatus/{print$NF}|wc-l`BEGIN{if(hardware_nic_number==hardware_nic){print1}else{print0}}UserParameter=hardware_cpu,omreportchassisprocessors|awk/^Health/{if($NF=="Ok"){print1}else{print0}}UserParameter=hardware_power_health,awk-vhardware_power_number=`omreportchassispwrsupplies|grep-c"Index"`-vhardware_power=`omreportchassispwrsupplies|awk/^Status/{if($NF=="Ok")count+=1}END{printcount}`BEGIN{if(hardware_power_number==hardware_power){print1}else{print0}}UserParameter=hardware_temp,omreportchassistemps|awk/^Status/{if($NF=="Ok"){print1}else{print0}}|head-n1UserParameter=hardware_physics_health,awk-vhardware_physics_disk_number=`omreportstoragepdiskcontroller=0|grep-c"^ID"`-vhardware_physics_disk=`omreportstoragepdiskcontroller=0|awk/^State/{if($NF=="Online")count+=1}END{printcount}`BEGIN{if(hardware_physics_disk_number==hardware_physics_disk){print1}else{print0}}UserParameter=hardware_virtual_health,awk-vhardware_virtual_disk_number=`omreportstoragevdiskcontroller=0|grep-c"^ID"`-vhardware_virtual_disk=`omreportstoragevdiskcontroller=0|awk/^State/{if($NF=="Ready")count+=1}END{printcount}`BEGIN{if(hardware_virtual_disk_number==hardware_virtual_disk){print1}else{print0}}UserParameter=pyora
[*],/usr/local/zabbix/bin/pyora.py--username$1--password$2--address$3--database$4$5$6$7$8
此文件是客户真个设置文件
8、vars的main.yml
15:17:06#cat/etc/ansible/roles/zabbix_client_install/vars/main.ymlzabbix_dir:/usr/local客户端平安目次zabbix_version:2.0.6客户端软件版本zabbix_user:zabbix客户端用户zabbix_port:10050客户真个端口zabbix_server_ip:192.168.1.10zabbix_server的ip
此文件是设置变量的
9、ansible安装zabbix客户真个playbook设置文件zabbix_client_install.yml
15:20:02#cat/etc/ansible/zabbix_client_install.yml----hosts:"{{host}}"remote_user:"{{user}}"gather_facts:Trueroles:-zabbix_client_install
10、利用playbook安装zabbix客户端
我的测试客户端情况是centos6.3,ip是192.168.240.17,利用key上岸
15:22:01#cd/etc/ansible/root@ip-10-10-10-10:/etc/ansible15:22:04#timeansible-playbookzabbix_client_install.yml--extra-vars"host=192.168.240.17user=root"--private-key=/root/test.pemPLAY*********************************************************GATHERINGFACTS***************************************************************ok:TASK:***failed:=>{"changed":true,"cmd":"ps-ef|grepzabbix|grep-vgrep|awk{print$2}|xargskill-9>>/dev/null2>&1","delta":"0:00:00.018213","end":"2014-07-1007:22:34.793910","item":"","rc":123,"start":"2014-07-1007:22:34.775697"}...ignoringTASK:***changed:TASK:***ok:=>(item=telnet,dmidecode,tar)TASK:***********changed:TASK:***changed:TASK:***changed:TASK:*****changed:TASK:***********changed:TASK:***ok:TASK:***changed:TASK:***changed:TASK:*********changed:TASK:***changed:TASK:***changed:PLAYRECAP********************************************************************192.168.240.17:ok=15changed=12unreachable=0failed=0real0m39.888suser0m1.547ssys0m0.197s
能够看到39秒就安装完成,次要消费工夫对照长的中央是fact搜集、yum安装、文件传输。
11、测试安装情形
#ifconfigeth0Linkencap:EthernetHWaddrFA:16:3E:34:62:D0inetaddr:10.10.240.21Bcast:10.10.240.255Mask:255.255.255.0inet6addr:fe80::f816:3eff:fe34:62d0/64Scope:LinkUPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1RXpackets:542391errors:0dropped:0overruns:0frame:0TXpackets:77391errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:142341119(135.7MiB)TXbytes:6451154(6.1MiB)loLinkencap:LocalLoopbackinetaddr:127.0.0.1Mask:255.0.0.0inet6addr:::1/128Scope:HostUPLOOPBACKRUNNINGMTU:16436Metric:1RXpackets:10errors:0dropped:0overruns:0frame:0TXpackets:10errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:0RXbytes:700(700.0b)TXbytes:700(700.0b)#ps-ef|grepzabbixzabbix269911007:22?00:00:00/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.confzabbix2699326991007:22?00:00:00/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.confzabbix2699426991007:22?00:00:00/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.confzabbix2699526991007:22?00:00:00/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.confzabbix2699626991007:22?00:00:00/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/conf/zabbix_agentd.confroot2710213773007:24pts/000:00:00grepzabbix#grep-Ev^$|^#/usr/local/zabbix/conf/zabbix_agentd.confLogFile=/tmp/zabbix_agentd.logServer=192.168.1.10ListenPort=10050Hostname=ip-10-10-240-21Timeout=20UserParameter=memcached_stats
[*],(echostats;sleep1)|telnet10.10.240.21$12>&1|awk/STAT$2/{print$NF}UserParameter=mysql
[*],mysql-h10.10.240.21-P3306-uzabbix-pzabbix-e"showglobalstatus"|grep"<$1>"|cut-f2UserParameter=redis_stats
[*],(echoinfo;sleep1)|telnet10.10.240.21$12>&1|grep$2|cut-d:-f2UserParameter=custom.vfs.dev.read.ops
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$4}UserParameter=custom.vfs.dev.read.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$7}UserParameter=custom.vfs.dev.write.ops
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$8}UserParameter=custom.vfs.dev.write.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$11}UserParameter=custom.vfs.dev.io.active
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$12}UserParameter=custom.vfs.dev.io.ms
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$13}UserParameter=custom.vfs.dev.read.sectors
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$6}UserParameter=custom.vfs.dev.write.sectors
[*],cat/proc/diskstats|grep$1|head-1|awk{print$$10}UserParameter=MongoDB.Status
[*],/bin/echo"db.serverStatus().$1"|/usr/bin/mongoadmin|grep"$2"|awk-F:{print$$2}|awk-F,{print$$1}UserParameter=check_lvm
[*],/usr/bin/sudo/usr/local/zabbix/bin/check_lvm.sh$1UserParameter=TCP_ESTABLISHED,ss-s|awkNR==2{print$4}|cut-d,-f1UserParameter=TCP_CLOSED,ss-s|awkNR==2{print$6}|cut-d,-f1UserParameter=TCP_TIMEWAIT,ss-s|awkNR==2{print$12}|cut-d/-f1UserParameter=zabbix_low_discovery
[*],/bin/bash/usr/local/zabbix/bin/zabbix_low_discovery.sh$1UserParameter=mysql_stats
[*],mysql-h10.10.240.21-P$1-uzabbix-pzabbix-e"showglobalstatus"|grep"<$2>"|cut-f2UserParameter=mysql_stats_slave
[*],mysql-h10.10.240.21-P$1-uzabbix-pzabbix-e"showslavestatusG"|grep"<$2>"|awk{if($NF=="Yes"){print1}else{print0}}UserParameter=check_platform,dmidecode|grepVendor|awk-F{if($2=="Dell"){print1}else{print0}}UserParameter=hardware_battery,omreportchassisbatteries|awk/^Status/{if($NF=="Ok"){print1}else{print0}}UserParameter=hardware_cpu_model,awk-vhardware_cpu_crontol=`sudoomreportchassisbiossetup|awk/CState/{if($NF=="Enabled"){print0}else{print1}}`-vhardware_cpu_c1=`sudoomreportchassisbiossetup|awk/C1[-|E]/{if($NF=="Enabled"){print0}else{print1}}`BEGIN{if(hardware_cpu_crontol==0&&hardware_cpu_c1==0){print0}else{print1}}UserParameter=hardware_fan_health,awk-vhardware_fan_number=`omreportchassisfans|grep-c"^Index"`-vhardware_fan=`omreportchassisfans|awk/^Status/{if($NF=="Ok")count+=1}END{printcount}`BEGIN{if(hardware_fan_number==hardware_fan){print1}else{print0}}UserParameter=hardware_memory_health,awk-vhardware_memory=`omreportchassismemory|awk/^Health/{print$NF}`BEGIN{if(hardware_memory=="Ok"){print1}else{print0}}UserParameter=hardware_nic_health,awk-vhardware_nic_number=`omreportchassisnics|grep-c"InterfaceName"`-vhardware_nic=`omreportchassisnics|awk/^ConnectionStatus/{print$NF}|wc-l`BEGIN{if(hardware_nic_number==hardware_nic){print1}else{print0}}UserParameter=hardware_cpu,omreportchassisprocessors|awk/^Health/{if($NF=="Ok"){print1}else{print0}}UserParameter=hardware_power_health,awk-vhardware_power_number=`omreportchassispwrsupplies|grep-c"Index"`-vhardware_power=`omreportchassispwrsupplies|awk/^Status/{if($NF=="Ok")count+=1}END{printcount}`BEGIN{if(hardware_power_number==hardware_power){print1}else{print0}}UserParameter=hardware_temp,omreportchassistemps|awk/^Status/{if($NF=="Ok"){print1}else{print0}}|head-n1UserParameter=hardware_physics_health,awk-vhardware_physics_disk_number=`omreportstoragepdiskcontroller=0|grep-c"^ID"`-vhardware_physics_disk=`omreportstoragepdiskcontroller=0|awk/^State/{if($NF=="Online")count+=1}END{printcount}`BEGIN{if(hardware_physics_disk_number==hardware_physics_disk){print1}else{print0}}UserParameter=hardware_virtual_health,awk-vhardware_virtual_disk_number=`omreportstoragevdiskcontroller=0|grep-c"^ID"`-vhardware_virtual_disk=`omreportstoragevdiskcontroller=0|awk/^State/{if($NF=="Ready")count+=1}END{printcount}`BEGIN{if(hardware_virtual_disk_number==hardware_virtual_disk){print1}else{print0}}UserParameter=pyora
[*],/usr/local/zabbix/bin/pyora.py--username$1--password$2--address$3--database$4$5$6$7$8#ll/tmp/total12-rw-------1rootroot197Jul909:35yum_save_tx-2014-07-09-09-35ibcBiO.yumtx-rw-rw-r--1zabbixzabbix320Jul1007:22zabbix_agentd.log-rw-rw-r--1zabbixzabbix5Jul1007:22zabbix_agentd.pid#chkconfig--list|grepzabbix_agentdzabbix_agentd0:off1:off2:off3:on4:on5:on6:off#grepzabbix/etc/sudoerszabbixALL=(root)NOPASSWD:/bin/netstat,/usr/bin/omreport#ll/etc/init.d/zabbix_agentd-rwxr-xr-x1rootroot1444Jul1007:22/etc/init.d/zabbix_agentd
能够看到安装后的客户端,完整是依照我的请求来做的。
12、删除已安装的客户端
15:22:54#timeansible-playbookzabbix_client_delete.yml--extra-vars"host=192.168.240.17user=root"--private-key=/root/test.pemPLAY*********************************************************GATHERINGFACTS***************************************************************ok:TASK:***********changed:TASK:***changed:TASK:************changed:TASK:*************changed:TASK:****changed:TASK:***changed:TASK:***changed:PLAYRECAP********************************************************************192.168.240.17:ok=8changed=7unreachable=0failed=0real0m25.497suser0m0.847ssys0m0.159s
13、测试删除情形
#ll/tmp/total4-rw-------1rootroot197Jul909:35yum_save_tx-2014-07-09-09-35ibcBiO.yumtx#ps-ef|grepzabbixroot2766513773007:27pts/000:00:00grepzabbix#ll/usr/local/total40drwxr-xr-x.2rootroot4096Sep232011bindrwxr-xr-x.2rootroot4096Sep232011etcdrwxr-xr-x.2rootroot4096Sep232011gamesdrwxr-xr-x.2rootroot4096Sep232011includedrwxr-xr-x.2rootroot4096Sep232011libdrwxr-xr-x.2rootroot4096Sep232011lib64drwxr-xr-x.2rootroot4096Sep232011libexecdrwxr-xr-x.2rootroot4096Sep232011sbindrwxr-xr-x.5rootroot4096May122013sharedrwxr-xr-x.3rootroot4096May132013src#grepzabbix/etc/sudoers#ll/etc/init.d/zabbix_agentdls:cannotaccess/etc/init.d/zabbix_agentd:Nosuchfileordirectory#chkconfig--list|grepzabbix_agentd#
能够看到已完整删除。
假如人人想利用我的例子,能够从附件里下载,然后放到/etc/ansible目次里,上面是紧缩包里的内容
-rw-r--r--root/root1082014-07-1015:20zabbix_client_install.yml-rw-r--r--root/root1212014-07-0918:09zabbix_client_delete.ymldrwxr-xr-xroot/root02014-07-0116:38roles/zabbix_client_install/drwxr-xr-xroot/root02014-07-0814:30roles/zabbix_client_install/meta/-rw-r--r--root/root2072014-07-0814:30roles/zabbix_client_install/meta/main.ymldrwxr-xr-xroot/root02014-07-1014:07roles/zabbix_client_install/tasks/-rw-r--r--root/root1992014-07-1014:02roles/zabbix_client_install/tasks/delete.yml-rw-r--r--root/root652014-07-1014:02roles/zabbix_client_install/tasks/main.yml-rw-r--r--root/root17892014-07-1014:02roles/zabbix_client_install/tasks/copy.yml-rw-r--r--root/root11102014-07-1014:07roles/zabbix_client_install/tasks/install.ymldrwxr-xr-xroot/root02014-06-1913:30roles/zabbix_client_install/handlers/drwxr-xr-xroot/root02014-07-0917:54roles/zabbix_client_install/vars/-rw-r--r--root/root1152014-07-0917:54roles/zabbix_client_install/vars/main.ymldrwxr-xr-xroot/root02014-07-0917:53roles/zabbix_client_install/templates/-rw-r--r--zabbix/zabbix104652014-07-0917:53roles/zabbix_client_install/templates/zabbix_agentd.conf-rwxr-xr-xroot/root14562014-07-0815:20roles/zabbix_client_install/templates/zabbix_agentddrwxr-xr-xroot/root02014-07-0917:13roles/zabbix_client_install/files/-rw-r--r--root/root2922932014-07-0917:13roles/zabbix_client_install/files/zabbix-2.0.6.tar.gzdrwxr-xr-xroot/root02014-06-2314:03roles/zabbix_client_delete/drwxr-xr-xroot/root02014-07-0918:08roles/zabbix_client_delete/meta/-rw-r--r--root/root2052014-07-0918:08roles/zabbix_client_delete/meta/main.ymldrwxr-xr-xroot/root02014-07-1014:28roles/zabbix_client_delete/tasks/-rw-r--r--root/root15182014-07-1014:08roles/zabbix_client_delete/tasks/delete.yml-rw-r--r--root/root222014-07-1014:08roles/zabbix_client_delete/tasks/main.ymldrwxr-xr-xroot/root02014-06-2414:14roles/zabbix_client_delete/handlers/drwxr-xr-xroot/root02014-07-0313:16roles/zabbix_client_delete/vars/-rw-r--r--root/root1152014-07-0917:55roles/zabbix_client_delete/vars/main.ymldrwxr-xr-xroot/root02014-07-0918:08roles/zabbix_client_delete/templates/drwxr-xr-xroot/root02014-06-2413:53roles/zabbix_client_delete/files/
后续我会持续先容利用playbook安装其他软件的例子。
常常有些朋友在Linux论坛问一些问题,不过,其中大多数的问题都是很基的。 下面笔者在论坛看到的一个好问题: “安装红旗4.0后,系统紫光输入法自带的双拼方案和我的习惯不一样,如何自定义双拼方案解决?谢谢?”这个问题很简练。 Windows有MS-DOS?方式,在该方式下通过输入DOS命令来操作电脑;Linux与Windows类似,也有命令方式,Linux?启动后如果不执行?X-WINDOWS,就会处于命令方式下,必须发命令才能操作电脑。? 掌握硬件配置,如显卡,声卡,网卡等,硬件只要不是太老或太新一般都能被支持,作为一名Linux系统管理员建议多阅读有关硬件配置文章,对各种不支持或支持不太好的硬件有深刻的了解。 不同于Windows?系统需要花钱购买,因为Linux的核心是免费的,自由使用的,核心源代码是开放的。 查阅经典工具书和Howto,特别是Howto是全球数以万计的Linux、Unix的经验总结非常有参考价值通常40%的问题同样可以解决。 当然你不需搭建所有服务,可以慢慢来。自己多动手,不要非等着别人帮你解决问题。 对Linux命令熟悉后,你可以开始搭建一个小的Linux网络,这是最好的实践方法。Linux是网络的代名词,Linux网络服务功能非常强大,不论是邮件服务器、Web服务器、DNS服务器等都非常完善。 我们这一代90后,从小接触的是windows98,家里条件好的自己有电脑装的是2000,后来又有了XP,上大学时又有了win7。
页:
[1]