In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
There is an important saying in operation and maintenance: unmonitored services are not allowed to go online.
Zabbix is a third-party open source software that provides distributed system monitoring and network monitoring based on web interface. It is mainly composed of two parts: zabbix-server and zabbix-agent.
Zabbix has a variety of features:
1. Support network automatic discovery mechanism.
2. Support custom detection mechanism UserParamenter
3. Support real-time drawing and display the data in a graphical way.
4. The alarm function is supported, and the alarm can be given by email or SMS.
5. Support the use of templates, which is of great help when there are multiple agent hosts.
The process realized in this paper:
1. Push ansible through shell to achieve batch deployment of agent.
2. Realize the automatic discovery function of zabbix-server and add the monitored end in batch.
3. Call the template and add an auto-discovery rule to the template to monitor all tcp ports.
4. Realize email alarm based on postfix.
5. Realize SMS alarm based on API of China Network Construction.
Prepare the environment
Hostnam
Ip
Deployment servic
Node1
192.168.1.22
Zabbix-server 、 zabbix-agent 、 ansible
Node2
192.168.1.23
Zabbix-agent
Node3
192.168.1.24
Zabbix-agent
Implementation premise: LAMP environment
I. full deployment of zabbix system
1. Yum installs zabbix service (node1)
# yum source of zabbix: [root@node1 ~] # yum install zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql zabbix-agent
2. Let mysql authorize its users and import three sql files of zabbix
[root@node1 ~] # mysql-e "create database zabbix charset='utf8'" [root@node1 ~] # mysql-e "grant all on *. * to 'zabbix'@'localhost' identified by' zabbix'" [root@node1 ~] # mysql-e "grant all on *. * to 'zabbix'@'127.0.0.1' identified by' zabbix'" [root@node1 ~] # mysql-uzabbix-h227.0.0.1-p zabbix
< /usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql [root@node1 ~]# mysql -uzabbix -h227.0.0.1 -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/p_w_picpaths.sql [root@node1 ~]# mysql -uzabbix -h227.0.0.1 -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql ###导入完成后可查看mysql中的数据库zabbix是否生成相关的表 3、修改zabbix-server配置文件,启动并安装 [root@node1 zabbix]# pwd/etc/zabbix[root@node1 zabbix]# vim zabbix_server.conf DBhost=localhost ###指明数据库地址DBname:zabbix ###数据库名称DBUser:zabbix ###数据库用户DBpassword:zabbix ###数据库用户密码DBSocket=/var/lib/mysql/mysql.sock ###指明mysql数据库的套接字文件,如果zabbix和mysql在不同主机上可不用修改[root@node1 zabbix]# service zabbix-server start[root@node1 zabbix]# netstat -an | grep 10051tcp 0 0 :::10051 :::* LISTEN [root@node1 ~]# service httpd start ##启动httpd服务 ##访问zabbix页面进行安装:http://$IP/zabbix注意:安装时报的错"timezone"这个参数可在"/etc/php.ini"或者是"/etc/httpd/conf.d/zabbix.conf"文件中修改 4、修改zabbix-agent的配置文件并启动,让Server端监控自己 [root@node1 zabbix]# pwd/etc/zabbix[root@node1 zabbix]# vim zabbix_agentd.conf Server=10.10.73.148 ##Agent端允许那个服务器过来拉取数据ServerActive=10.10.73.148 ##开启Agent端的主动模式,主动向服务端传输数据[root@node1 zabbix]# service zabbix-agent starttcp 0 0 :::10050 :::* LISTEN 5、通过脚本实现agent端批量部署 #!/bin/bash#Author:wtc##############[ Ansible Install ]###############if ! 'rpm -q ansible' &>/ dev/null Then # # install the ansible service yum install ansible-y & > / dev/null [[$?-eq 0]] & & echo "Install Ansible Success" | | echo "Install Ansible Failed" fi# [Add Roles] # cat > / etc/ansible/hosts # # add the agent host ipzabbix 192.168.1 to ansible's hosts. 23192.168.1.24END# [Scp Zabbix.repo to Agent] # ansible zabbix-m copy-a "src=/etc/yum.repos.d/zabbix.repo dest=/etc/yum.repos.d/" # # send zabbix's yum warehouse to ansible zabbix-m shell-a "yum clean all" ansible zabbix-m shell-a "yum repolist" # # [Mkdir Zabbix Directorys] Dir=/etc/ansible/roles/zabbix [[- d $Dir]] | | mkdir-pv $Dir/ {files Templetes,tasks,handles,vars,meta Default} # # create the directory corresponding to the zabbix role cp / etc/zabbix/zabbix_agentd.conf / etc/ansible/roles/zabbix/templetes/zabbix_agentd.conf.j2# [Zabbix taska/main.yml] # cat / etc/ansible/roles/zabbix/tasks/main.yml # # write the yml file-name: install zabbix yum: name=zabbix-agent state=present- name: conf File template: src=/etc/ansible/roles/zabbix/templetes/zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf- name: service: name=zabbix-agent state=started enabled=trueEND# [yaml file] # cat / root/zabbix.yaml- hosts: all remote_user: root roles:-zabbixENDansible-playbook-- check / root/zabbix.yamlansible-playbook / root/zabbix.yaml
6. Define automatic discovery rules in the web interface of zabbix, and automatically add the monitored end.
(a) Configuration--- > Discovery--- > Create discovery rule
(B) after the definition is saved, wait a few seconds to see if the server is automatically added; Monitoring--- > Discovery
# the above process is to deploy the entire zabbix system, but you still need to add monitoring items after deployment!
Second, define the monitoring items on the monitoring side
1. Call the "Template OS Linux" template
(a) Configuration--- > Avtions--- > Discovery--- > Create action, defining Action and conditions
(C) define operation Operations
(e) after the above operations are completed, you can check whether the template is called on the agent side.
2. There is no tcp port listening item in "Template OS Linux". In this case, we need to customize the detection mechanism "UserParamenter" in the template.
(a) Edit the configuration file for zabbix, add "UserParameter", and restart zabbix-agent
[root@node1 zabbix] # pwd/etc/zabbix [root@node1 zabbix] # vim zabbix_agentd.conf # # add the following two lines of UnsafeUserParameters=1UserParameter=portlisten,/opt/app/zabbix/sbin/port.sh # # "portlisten" custom key The port.sh script is based on json format to filter out all tcp ports [root@node1 ~] # vim / optUniq` length=$ {# portarray [@]} printf "{\\ n" printf "\\" data\\ ": ['NF~/ ^ [0-9] * $/) print $NF}' | sort | uniq`) length=$ {# portarray [@]} printf" {\ n "printf"\\ "data\\": [ ITemplates-- > Template OS Linux-- > DIscovery-- > Create discovery rule
(C) define 1, 2 and 3 in the figure above, respectively
Item_prototypes--- > Create item protopyte
Trigger_prototypes--- > Create trigger prototype
Graph prototypes--- > Create graph prototype
(d) check to see if tcp ports are added
Configuration--- > Hosts--- > Items
Third, trigger email alarm
1. Deploy postfix service and send test SMS messages.
[root@node1 ~] # yum install postfix-y # # install the mail server postfix [root@node1 ~] # vim / etc/postfix/main.cf # # Edit the configuration file on node1 Add the following lines myhostname = mail.umpay.commyorigin = umpay.commydomain = umpay.commydestination = localhostmynetworks = 127.0.0.0 mail.umpay.com umpay.com 8 [root@node1 ~] # echo "127.0.0.1 mail.umpay.com umpay.com" & > > / etc/hosts [root@node1 ~] # service postfix start [root@node1 ~] # echo "Hello, New World" | mail-s "wtc" 1362365xxxx@163.com # # send test SMS [root@node1 ~] # tialf / var/log/maillog
2. Define zabbix server media
Administration- >-> Media types-- > Create media type
3. Then define Actions, Conditions, Operations
Configuration--- > Actions--- > Tirggers--- > Create action
4. Define mail recipients
Administration--- > Users--- > Zabbix administrators--- > Users--- > Admin--- > Media
# email alarm is completed after the above operations are completed
5. Install nginx, monitor tcp808 port, and test mailbox alarm
[root@node1 nginx] # nginx [root@node1 nginx] # netstat-tnlp | grep nginxtcp 00 0.0.0.0 netstat 808 0.0.0.0 tnlp * A new tcp listening port appears in LISTEN 16984/nginx###, and zabbix will be automatically added to items. There is no screenshot here [root@node1 nginx] # nginx-s stop
Fourth, realize SMS alarm.
1. Place the script under the default calling script path of zabbix
[root@node1 ~] # cat / etc/zabbix/zabbix_server.conf | grep AlertScriptsPathAlertScriptsPath=/usr/lib/zabbix/alertscripts [root@node1 ~] # vim / usr _ (..\) /%\ 1Universe g' | tr-d'\ n') # Uid= "ch, madman" Uid= "linkage advantage" # Key= "8c1604e2eb0d66dxxxxx" cfcc13b087aaee114c8e "URL=" http://utf8.sms.webchinese.cn/?Uid=${Uid}&Key=${Key}&smsMob=${MOBILE_NUMBER}&smsText=${MESSAGE_ENCODE}"set-x ${CURL}-s-connect-timeout ${TIMEOUT} "${URL}" [root@node1 ~] # chmod-R + x / usr/lib/zabbix/alertscripts/sms.sh [root@node1 ~] # chown-R zabbix.zabbix / usr/lib/zabbix/alertscripts/sms.sh
2. Configure SMS alarm media
Administration--- > Media types--- > Create media types
3. Configure SMS Actions
Configuration--- > Actions--- > Tirggers--- > Create action
(a) configure SMS content
(B) configure alarm conditions
(C) define the alarm recipient
4. Configure the recipient of SMS
Administration--- > Users--- > Zabbix administrators--- > Users--- > Admin--- > Media
5. Test nginx SMS tcp port alarm
[root@node1 alertscripts] # nginx-s stop
Summary of questions:
1. If "value should not json project" appears in the Discover of the host in host, the solution is as follows
[root@node1 ~] # ansible zabbix-m shell-a "sed-I'/ Defaults requiretty/c\\ # Defaults requiretty' / etc/sudoers" [root@node1 ~] # ansible zabbix-m shell-a "echo 'zabbix ALL= (ALL) ALL' & > > / etc/sudoers" # ansible zabbix-m shell-a "sed-I' / AllowRoot=0/c\\ AllowRoot=1' / etc/zabbix/zabbix_agentd.conf"
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.