大佬教程收集整理的这篇文章主要介绍了CentOS 7安装部署zabbix3.4,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$ sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config $ sed -i ‘s/SELINUXTYPE=targeted/#&/‘ /etc/selinux/config $ setenforce 0 # 可以设置配置文件永久关闭 $ systemctl stop iptables.service $ systemctl stop firewalld.service $ reboot # 更改selinux需要重启系统才会生效
#修改字符集,否则可能报 input/output error的问题,因为日志里打印了中文
$ localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 $ export LC_ALL=zh_CN.UTF-8 $ echo ‘LANG=zh_CN.UTF-8‘ > /etc/locale.conf
3.安装配置zabbix
#安装 MysqL
本教程使用 MysqL 作为数据库,如果不使用 MysqL 可以跳过相关 MysqL 安装和配置
$ yum -y install mariadb mariadb-devel mariadb-server # centos7下安装的是mariadb $ systemctl enable mariadb $ systemctl start mariadb
#设置MysqL的root密码$ MysqLadmin -u root -h localhost password ‘xxxxxxxx‘
#创建数据库 zabbix 并授权
$ MysqL -uroot -pxxxxxx > create database zabbix character set utf8 collate utf8_bin; > grant all privileges on zabbix.* to [email protected] identified by ‘xxxxxxxx‘; > quit
#安装zabbix-server、zabbix-agent及相关组件
$ rpm -i http://repo.zabbix.com/zabbix/3.4/rHel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm $ yum install zabbix-server-MysqL zabbix-web-MysqL zabbix-agent
#导入zabbix初始化数据$ zcat /usr/share/doc/zabbix-server-MysqL*/create.sql.gz | MysqL -uzabbix -pxxxxxxxx zabbix
#修改zabbix-server配置文件$ vim /etc/zabbix/zabbix_server.conf
修改连接数据库的配置
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBpassword=xxxxxxxx
#修改PHP时区$ vim /etc/httpd/conf.d/zabbix.conf
将下面这行修改为亚洲上海
PHP_value date.timezone Asia/Shanghai
#启动zabbix-server、zabbix-agent、httpd
$ systemctl restart zabbix-server zabbix-agent httpd $ systemctl enable zabbix-server zabbix-agent httpd
4.配置zabbix前端
打开浏览器,访问http://192.168.2.205/zabbix,会看到如下页面
$ yum -y install iptables iptables-services
#配置iptables$ vim /etc/sysconfig/iptables # 添加允许访问80端口的策略
$ systemctl start iptables.service $ systemctl enable iptables.service
#查看iptables状态$ systemctl status iptables.service
二、监控Linux主机
2.1.安装zabbix-agent
$ rpm -i http://repo.zabbix.com/zabbix/3.4/rHel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm $ yum install -y zabbix-agent zabbix-get
2.2.配置zabbix-agent$ vim /etc/zabbix/zabbix_agentd.conf # 修改agent配置文件
Server=192.168.2.205 # zabbix服务端内网IP
ServerActive=192.168.2.205 # zabbix服务端内网IP,Active表示agent主动推送
Hostname=Jump Server # zabbix客户端主机名称,需要和web端添加的名称一致
Include=/etc/zabbix/zabbix_agentd.d/*.conf
2.3.配置iptables$ vim /etc/sysconfig/iptables # 添加允许访问10050端口的策略
-A INPUT -s 192.168.2.205 -p tcp -m multiport --dports 10050 -j ACCEPT$ systemctl restart iptables.service # 重启iptables
2.4.Web端添加Linux主机
配置-主机-创建主机,按下图配置好后点击“更新”
D:\zabbix_agents_3.4.6.win\bin\win64\zabbix_agentd.exe -c D:\zabbix_agents_3.4.6.win\conf\zabbix_agentd.win.conf -i #加载配置文件 D:\zabbix_agents_3.4.6.win\bin\win64\zabbix_agentd.exe -c D:\zabbix_agents_3.4.6.win\conf\zabbix_agentd.win.conf -s #添加windows自启动服务
netsh advfirewall firewall add rule name="Zabbix_Agent_tcp" dir=in protocol=tcp localport=10050 remoteip=192.168.2.205 action=allow
$ vim /etc/httpd/conf/httpd.conf
ExtendedStatus On <LOCATIOn /server-status> SetHandler server-status Order deny,allow Allow from 192.168.2.204 # apache主机IP </LOCATIOn>
#重启apache$ systemctl restart httpd
浏览器访问http://192.168.2.204/server-status,确认配置生效
$ wget https://github.com/lorf/zapache/archive/master.zip $ unzip master.zip
文件说明:
httpd-server-status.conf.sample 是用于配置server-status的上个步骤已经配置过了
userparameter_zapache.conf.sample 、zapache 关键的文件
zapache-template-active.xml zapache-template.xml模板文件,这两个文件需要导入到web端
#配置zapache$ cd zapache-master
将zapache配置文件放到相应目录下
$ cp userparameter_zapache.conf.sample /etc/zabbix/zabbix_agentd.d/ $ cd /etc/zabbix/zabbix_agentd.d/ $ mv userparameter_zapache.conf.sample userparameter_zapache.conf
查看配置userparameter_zapache.conf内容$ cat /etc/zabbix/zabbix_agentd.d/userparameter_zapache.conf
$ mkdir -p /var/lib/zabbixsrv/externalscripts/ $ cp zapache /var/lib/zabbixsrv/externalscripts/ $ chmod +x /var/lib/zabbixsrv/externalscripts/zapache
查看zabbix-agent配置文件,确保zabbix_agentd.d目录开启
Include=/etc/zabbix/zabbix_agentd.d/*.conf
4.3.web端导入模板
配置-模板-导入,点击“浏览”,选择模板文件点击“打开”,点击“导入”即可。
$ vim /etc/Nginx/Nginx.conf
LOCATIOn /Nginx-status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.2.204; # Nginx主机IP }
#使配置生效$ /usr/sbin/Nginx -t
$ /usr/sbin/Nginx -s reload
$ curl http://192.168.2.204/Nginx-status
$ vim /etc/zabbix/zabbix_agentd.d/Nginx_status.sh
#!/bin/bash ################################## # Zabbix monitoring script # # Nginx: # - anything available via Nginx stub-status module # ################################## # Contact: # [email protected] # Zabbix requested parameter ZBX_REQ_DATA="$1" ZBX_REQ_DATA_URL="$2" # Nginx defaults Nginx_STATUS_DEFAULT_URL="192.168.2.204/Nginx-status" #(这里写网站的域名) WGET_BIN="/usr/bin/wget" # # Error handling: # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) # - items need to be of type "float" (allow negative + float) # ERROR_NO_ACCESS_FILE="-0.9900" ERROR_NO_ACCESS="-0.9901" ERROR_WRONG_PARAM="-0.9902" ERROR_DATA="-0.9903" # either can not connect / bad host / bad port # Handle host and port if non-default if [ ! -z "$ZBX_REQ_DATA_URL" ]; then URL="$ZBX_REQ_DATA_URL" else URL="$Nginx_STATUS_DEFAULT_URL" fi # save the Nginx stats in a variable for future parsing Nginx_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null) # error during retrieve if [ $? -ne 0 -o -z "$Nginx_STATS" ]; then echo $ERROR_DATA exit 1 fi # # Extract data from Nginx stats # case $ZBX_REQ_DATA in active_connections) echo "$Nginx_STATS" | head -1 | cut -f3 -d‘ ‘;; accepted_connections) echo "$Nginx_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f2 -d‘ ‘;; handled_connections) echo "$Nginx_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f3 -d‘ ‘;; handled_requests) echo "$Nginx_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f4 -d‘ ‘;; reading) echo "$Nginx_STATS" | tail -1 | cut -f2 -d‘ ‘;; wriTing) echo "$Nginx_STATS" | tail -1 | cut -f4 -d‘ ‘;; waiTing) echo "$Nginx_STATS" | tail -1 | cut -f6 -d‘ ‘;; *) echo $ERROR_WRONG_PARAM; exit 1;; esac exit 0
给此脚本添加可执行权限$ chmod +x /etc/zabbix/zabbix_agentd.d/Nginx_status.sh
5.3.配置zabbix-agent$ vim /etc/zabbix/zabbix_agentd.conf
#编辑zabbix_agentd.conf文件,添加下面一行
UserParameter=Nginx[*],/etc/zabbix/zabbix_agentd.d/Nginx_status.sh "$1"
#重启zabbix-agent$ systemctl restart zabbix-agent
#在zabbix-server主机上测试,不报错说明测试OK$ zabbix_get -s 192.168.2.204 -p 10050 -k ‘Nginx[reading]‘
@H_673_503@
@H_618_532@
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>2.0</version> <date>2013-03-26T04:17:58Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template_Nginx</template> <name>Template_Nginx</name> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>Nginx</name> </application> </applications> <items> <item> <name>Nginx $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[waiTing,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[wriTing,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[active_connections,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[reading,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[handled_requests,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>1</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[accepted_connections,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>1</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>Nginx $1/sec</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>Nginx[handled_connections,{$Nginx_STATUS_URL}]</key> <delay>60</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>0</value_type> <allowed_hosts/> <units/> <delta>1</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>Nginx</name> </application> </applications> <valuemap/> </item> <item> <name>number of $1 process</name> <type>0</type> <snmp_community>public</snmp_community> <multiplier>0</multiplier> <snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid> <key>proc.num[Nginx]</key> <delay>300</delay> <history>30</history> <trends>365</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units/> <delta>0</delta> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authpassphrase/> <snmpv3_privpassphrase/> <formula>1</formula> <delay_flex/> <params/> <ipmi_sensor/> <data_type>0</data_type> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications/> <valuemap/> </item> </items> <discovery_rules/> <macros> <macro> <macro>{$Nginx_STATUS_URL}</macro> <value>http://127.0.0.1:10061/Nginx_status</value> </macro> </macros> <templates/> <screens/> </template> </templates> <triggers> <trigger> <expression>{Template_Nginx:proc.num[Nginx].last(0)}=0</expression> <name>Nginx is not running on {HOSTNAME}</name> <url/> <status>0</status> <priority>4</priority> <description>Nginx is not running. It has been stopped / shutdown or has crashed. check on the server for more details: - w / last - dmesg logs - /var/log/messages - Nginx error logs</description> <type>0</type> <dependencies/> </trigger> </triggers> <graphs> <graph> <name>Nginx - Connections and requests status</name> <width>900</width> <height>200</height> <yaxismin>0.0000</yaxismin> <yaxismax>100.0000</yaxismax> <show_work_period>0</show_work_period> <show_triggers>0</show_triggers> <type>0</type> <show_legend>1</show_legend> <show_3d>0</show_3d> <percent_left>0.0000</percent_left> <percent_right>0.0000</percent_right> <ymin_type_1>1</ymin_type_1> <ymax_type_1>0</ymax_type_1> <ymin_item_1>0</ymin_item_1> <ymax_item_1>0</ymax_item_1> <graph_items> <graph_item> <sortorder>0</sortorder> <drawtype>1</drawtype> <color>FF9999</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[accepted_connections,{$Nginx_STATUS_URL}]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>2</drawtype> <color>990000</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[handled_connections,{$Nginx_STATUS_URL}]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>0</drawtype> <color>009900</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[handled_requests,{$Nginx_STATUS_URL}]</key> </item> </graph_item> </graph_items> </graph> <graph> <name>Nginx - Threads status</name> <width>900</width> <height>200</height> <yaxismin>0.0000</yaxismin> <yaxismax>100.0000</yaxismax> <show_work_period>0</show_work_period> <show_triggers>0</show_triggers> <type>1</type> <show_legend>1</show_legend> <show_3d>0</show_3d> <percent_left>0.0000</percent_left> <percent_right>0.0000</percent_right> <ymin_type_1>1</ymin_type_1> <ymax_type_1>0</ymax_type_1> <ymin_item_1>0</ymin_item_1> <ymax_item_1>0</ymax_item_1> <graph_items> <graph_item> <sortorder>0</sortorder> <drawtype>1</drawtype> <color>990000</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[wriTing,{$Nginx_STATUS_URL}]</key> </item> </graph_item> <graph_item> <sortorder>1</sortorder> <drawtype>1</drawtype> <color>999900</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[reading,{$Nginx_STATUS_URL}]</key> </item> </graph_item> <graph_item> <sortorder>2</sortorder> <drawtype>1</drawtype> <color>009900</color> <yaxisside>0</yaxisside> <calc_fnc>4</calc_fnc> <type>0</type> <item> <host>Template_Nginx</host> <key>Nginx[waiTing,{$Nginx_STATUS_URL}]</key> </item> </graph_item> </graph_items> </graph> </graphs> </zabbix_export>
以上是大佬教程为你收集整理的CentOS 7安装部署zabbix3.4全部内容,希望文章能够帮你解决CentOS 7安装部署zabbix3.4所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。