接下来几篇文章是关于互联网行业常用运维监控软件的安装和使用,也是自己日常工作中接触并有实际使用体验的工具,欢迎感兴趣的小伙伴共同探讨与学习。
![6ba99d07f658b181136464bf4554c942.png](https://i-blog.csdnimg.cn/blog_migrate/52b6a338f8c8d9063f99e2b98b288619.jpeg)
server端安装脚本
#!/bin bash#判断是否是root用户执行脚本ROOTUSER_NAME=rootusername=`id -nu` #or username=`whoami`if [ "$username" == "$ROOTUSER_NAME" ]then echo "Go to next step."else echo "You are just a regular user,please switch to root." exit 0fi#安装服务包及相关依赖包cd /root/Zabbix_2.4.4/MysqlEditionRPMrpm -ivh --nodeps --force *.rpmcd ..#启动Mysql数据库service mysqld start#MySQL数据库信息HOSTNAME="localhost" #数据库URLPORT="3306" #数据库端口USERNAME="root" #数据库帐号PASSWORD="" #数据库密码(初始为空)# 查看服务端口# # less /etc/services |grep mysql# mysql 3306/tcp # MySQL# mysql 3306/udp # MySQL## 登陆数据库,设置root用户密码 ##mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p -e "set password for root@localhost=password('zabbixadmin');"#修改数据库密码#PASSWORD="zabbixadmin"#创建数据库mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "create database zabbix character set utf8 collate utf8_bin;"#授权zabbix系统访问Mysql数据库的用户和密码:mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "grant all privileges on zabbix.* to zabbixadmin@localhost identified by 'zabbixadmin';"#导入zabbix数据库表结构(${PASSWORD},可以使用变量)mysql -uroot -pzabboxadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/schema.sqlmysql -uroot -pzabboxadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/images.sqlmysql -uroot -pzabboxadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/data.sql#sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/' /etc/zabbix/zabbix_server.conf#zabbix的配置文件,连接mysql数据库cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.bak.confrm /etc/zabbix/zabbix_server.confcp /root/Zabbix_2.4.4/conf/zabbix_server.conf /etc/zabbix/#编辑PHP环境配置文件cp /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.bak.confrm /etc/httpd/conf.d/zabbix.confcp /root/Zabbix_2.4.4/conf/zabbix.conf /etc/httpd/conf.d/#添加固定服务端口,以便于后期监测和防火墙监控端口echo "zabbix-agent 10050/tcp # zabbix-agent-tcp" >> /etc/servicesecho "zabbix-agent 10050/udp # zabbix-agent-udp" >> /etc/servicesecho "zabbix-trapper 10051/tcp # zabbix-trapper-tcp" >> /etc/servicesecho "zabbix-trapper 10051/udp # zabbix-trapper-udp" >> /etc/services#开启防火墙端口(tcp8881,10050,10051 udp10050,10051) HTTP端口、zabbix-agent端口、zabbix-trapper端口#或者关闭防火墙# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT## service iptables save#关闭selinux#修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启cp /etc/selinux/config /etc/selinux/bakconfigrm /etc/selinux/configcp /root/Zabbix_2.4.4/conf/config /etc/selinux/#将自定义字体拷贝至字体存放文件夹目录下cp /root/Zabbix_2.4.4/conf/msyh.ttf /usr/share/zabbix/fontscp /root/Zabbix_2.4.4/conf/simkai.ttf /usr/share/zabbix/fonts#修改字体引用配置文件cp /usr/share/zabbix/include/defines.inc.php /usr/share/zabbix/include/defines.bak.inc.phprm /usr/share/zabbix/include/defines.inc.phpcp /root/Zabbix_2.4.4/conf/defines.inc.php /usr/share/zabbix/include/#修改Apache HTTP配置文件cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bak.confrm /etc/httpd/conf/httpd.confcp /root/Zabbix_2.4.4/conf/httpd.conf /etc/httpd/conf/## 设置所需服务自动启动(httpd,mysqld,snmpd,snmptrapd,zabbix-agent,zabbix-server) ##chkconfig httpd on # service httpd startchkconfig mysqld on # service mysqld start#chkconfig snmpd on # service snmpd start#chkconfig snmptrapd on # service snmptrapd startchkconfig zabbix-agent on # service zabbix-agent startchkconfig zabbix-server on # service zabbix-server startchkconfig --level 2345 zabbix-server onrebootservice httpd restartservice mysqld restartservice zabbix-server restart
Agent端安装脚本
#!/bin bash#判断是否是root用户执行脚本ROOTUSER_NAME=rootusername=`id -nu` #or username=`whoami`if [ "$username" == "$ROOTUSER_NAME" ]then echo "Go to next step."else echo "You are just a regular user,please switch to root." exit 0fi#安装服务包及相关依赖包cd /root/Zabbix_2.4.4/zabbixAgentrpm -ivh zabbix-2.4.5-1.el6.x86_64.rpmrpm -ivh zabbix-agent-2.4.5-1.el6.x86_64.rpmcd ..#修改配置文件/usr/local/zabbix_agent/etc/zabbix_agent.conf#修改Zabbix server的ip#Server=192.168.10.197 #server端IP地址,请修改cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.bak.confrm /etc/zabbix/zabbix_agentd.confcp /root/Zabbix_2.4.4/zabbixAgent/zabbix_agentd.conf /etc/zabbix/#启动#/usr/local/agent/sbin/zabbix_agentd -c /usr/local/agent/etc/zabbix_agentd.conf #Echo "/usr/local/agent/sbin/zabbix_agentd -c /usr/local/agent/etc/zabbix_agentd.conf" >>/etc/tc.local#添加到系统目录#ln -s /usr/local/zabbix_agent/sbin/* /usr/local/sbin/#ln -s /usr/local/zabbix_agent/bin/* /usr/local/bin/#测试,下面的命令需要在server端执行,其中192.168.10.199是agent的ip#/usr/local/zabbix/bin/zabbix_get -s192.168.10.199 -p10050 -k"system.uptime"#添加固定服务端口,以便于后期监测和防火墙监控端口echo "zabbix-agent 10050/tcp # zabbix-agent-tcp" >> /etc/servicesecho "zabbix-agent 10050/udp # zabbix-agent-udp" >> /etc/servicesecho "zabbix-trapper 10051/tcp # zabbix-trapper-tcp" >> /etc/servicesecho "zabbix-trapper 10051/udp # zabbix-trapper-udp" >> /etc/services#开启防火墙端口(tcp8881,10050,10051 udp10050,10051) HTTP端口、zabbix-agent端口、zabbix-trapper端口#或者关闭防火墙# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT## service iptables save## 设置所需服务自动启动(httpd,mysqld,snmpd,snmptrapd,zabbix-agent,zabbix-server) ###chkconfig httpd on # service httpd start#chkconfig mysqld on # service mysqld start#chkconfig snmpd on # service snmpd start#chkconfig snmptrapd on # service snmptrapd start#chkconfig zabbix-agent on # service zabbix-agent start#chkconfig zabbix-server on # service zabbix-server startservice zabbix-agent restartchkconfig --level 2345 zabbix-agent on#在监控后台添加被监控服务器信息即可
安装过程
添加一个zabbix的官方yum源
#rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpmRetrieving http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpmwarning: /var/tmp/rpm-tmp.OyOrcF: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEYPreparing...########################################### [100%]1:zabbix-release ########################################### [100%]
安装依赖组件包
#yum -y install iksemel libssh2 zabbix-server-mysql zabbix-web-mysql mysql-server zabbix-agent install net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils net-snmp Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors * base: centos.ustc.edu.cn * extras: mirrors.pubyun.com * updates: centos.ustc.edu.cn base | 3.7 kB 00:00 extras| 3.4 kB 00:00 extras/primary_db | 31 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db| 3.9 MB 00:02 zabbix| 951 B 00:00 zabbix/primary| 17 kB 00:04 zabbix 113/113 zabbix-non-supported | 951 B 00:00 zabbix-non-supported/primary | 3.8 kB 00:00 zabbix-non-supported 15/15 Setting up Install Process No package install available. Resolving Dependencies Installed: iksemel.x86_64 0:1.4-2.el6libjpeg-turbo.x86_64 0:1.2.1-3.el6_5 mysql-server.x86_64 0:5.1.73-5.el6_6 net-snmp.x86_64 1:5.5-50.el6_6.1 net-snmp-devel.x86_64 1:5.5-50.el6_6.1net-snmp-perl.x86_64 1:5.5-50.el6_6.1 net-snmp-utils.x86_64 1:5.5-50.el6_6.1zabbix-agent.x86_64 0:2.4.5-1.el6 zabbix-server-mysql.x86_64 0:2.4.5-1.el6 zabbix-web-mysql.noarch 0:2.4.5-1.el6 Dependency Installed: OpenIPMI-libs.x86_64 0:2.0.16-14.el6elfutils-devel.x86_64 0:0.158-3.2.el6elfutils-libelf-devel.x86_64 0:0.158-3.2.el6 file-devel.x86_64 0:5.04-21.el6 fping.x86_64 0:2.4b2-16.el6 keyutils-libs-devel.x86_64 0:1.4-5.el6 krb5-devel.x86_64 0:1.10.3-37.el6_6 libcom_err-devel.x86_64 0:1.41.12-21.el6 libselinux-devel.x86_64 0:2.0.94-5.8.el6 libsepol-devel.x86_64 0:2.0.41-4.el6lm_sensors-devel.x86_64 0:3.1.1-17.el6 mysql.x86_64 0:5.1.73-5.el6_6 openssl-devel.x86_64 0:1.0.1e-30.el6.11 perl-DBD-MySQL.x86_64 0:4.013-3.el6 php.x86_64 0:5.3.3-46.el6_6 php-bcmath.x86_64 0:5.3.3-46.el6_6 php-cli.x86_64 0:5.3.3-46.el6_6 php-common.x86_64 0:5.3.3-46.el6_6 php-gd.x86_64 0:5.3.3-46.el6_6 php-mbstring.x86_64 0:5.3.3-46.el6_6 php-mysql.x86_64 0:5.3.3-46.el6_6 php-pdo.x86_64 0:5.3.3-46.el6_6 php-xml.x86_64 0:5.3.3-46.el6_6 popt-devel.x86_64 0:1.13-7.el6 rpm-devel.x86_64 0:4.8.0-38.el6_6 tcp_wrappers-devel.x86_64 0:7.6-57.el6 unixODBC.x86_64 0:2.2.14-14.el6 zabbix.x86_64 0:2.4.5-1.el6 zabbix-server.x86_64 0:2.4.5-1.el6 zabbix-web.noarch 0:2.4.5-1.el6 Updated: libssh2.x86_64 0:1.4.2-2.el6 net-snmp-libs.x86_64 1:5.5-50.el6_6.1 Dependency Updated: e2fsprogs.x86_64 0:1.41.12-21.el6e2fsprogs-libs.x86_64 0:1.41.12-21.el6 elfutils.x86_64 0:0.158-3.2.el6 elfutils-libelf.x86_64 0:0.158-3.2.el6 elfutils-libs.x86_64 0:0.158-3.2.el6file.x86_64 0:5.04-21.el6 file-libs.x86_64 0:5.04-21.el6 keyutils.x86_64 0:1.4-5.el6 keyutils-libs.x86_64 0:1.4-5.el6 krb5-libs.x86_64 0:1.10.3-37.el6_6 krb5-workstation.x86_64 0:1.10.3-37.el6_6 libcom_err.x86_64 0:1.41.12-21.el6 libselinux.x86_64 0:2.0.94-5.8.el6 libselinux-python.x86_64 0:2.0.94-5.8.el6 libselinux-utils.x86_64 0:2.0.94-5.8.el6 libss.x86_64 0:1.41.12-21.el6lm_sensors-libs.x86_64 0:3.1.1-17.el6 mysql-libs.x86_64 0:5.1.73-5.el6_6 openssl.x86_64 0:1.0.1e-30.el6.11rpm.x86_64 0:4.8.0-38.el6_6 rpm-build.x86_64 0:4.8.0-38.el6_6 rpm-libs.x86_64 0:4.8.0-38.el6_6 rpm-python.x86_64 0:4.8.0-38.el6_6 zlib.x86_64 0:1.2.3-29.el6 zlib-devel.x86_64 0:1.2.3-29.el6 Replaced: libjpeg.x86_64 0:6b-46.el6 Complete!
启动Mysql数据库
# service mysqld start
登陆数据库,设置root用户密码
# mysql -u root Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.#设置root密码 mysql>set password for root@localhost=password('zabbixadmin');
创建zabbix外部数据库
数据库:zabbix用户名:zabbixadmin 密码:zabbixadmin创建zabbix的数据库:create databas e zabbix character set utf8 collate utf8_bin;授权zabbix系统访问Mysql数据库的用户和密码:grant all privileges on zabbix.* to zabbixadmin@localhost identified by 'zabbixadmin';
导入zabbix数据库表结构
mysql -uroot -pzabbixadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/schema.sqlmysql -uroot -pzabbixadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/images.sqlmysql -uroot -pzabbixadmin zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/data.sql导入sql文件命令说明:mysql -uroot -pzabbixadmin zabbixmysql 数据库操作主指令-uroot 以root用户登录-pzabbixadmin这里的zabbixadmin为你3-2步骤设置的root密码(这里注意,-p和密码之间不要有空格,直接输入密码就行 否则会报错)zabbix为创建的数据库名称/usr/share/doc/zabbix-server-mysql-2.4.1/create/目录内的三个sql文件为安装zabbix软件时自动创建
编辑zabbix的配置文件
vi /etc/zabbix/zabbix_server.conf 依次找到DBHost DBName DBUser DBPassword 四个关键字, 修改成你自己上面定义的内容: DBHost=localhost 指的是访问本机数据库 DBName=zabbix 创建的zabbix的数据库名字 DBUser=zabbixadmin 授权访问数据库的用户名 DBPassword=zabbixadmin 授权访问数据库的密码
编辑PHP环境配置文件
vi /etc/httpd/conf.d/zabbix.conf 对应修改内容如下 php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value date.timezone Asia/Shanghai 其实zabbix都给你设置好了,只有最后一项需要你改动下,去掉前面的#号 时区设置成Asia/Shanghai
添加固定服务端口,以便于后期监测和防火墙监控端口
编辑/etc/services文件 vi /etc/services 跳到文件末尾(大写G直接跳)追加以下内容: zabbix-agent 10050/tcp # zabbix-agent-tcp zabbix-agent 10050/udp # zabbix-agent-udp zabbix-trapper 10051/tcp # zabbix-trapper-tcp zabbix-trapper 10051/udp # zabbix-trapper-udp echo "zabbix-agent10050/tcp # zabbix-agent-tcp" >> /etc/services echo "zabbix-agent10050/udp # zabbix-agent-udp" >> /etc/services echo "zabbix-trapper 10051/tcp # zabbix-trapper-tcp" >> /etc/services echo "zabbix-trapper 10051/udp # zabbix-trapper-udp" >> /etc/services
开启防火墙端口(tcp80,10050,10051 udp10050,10051)
当然你可以直接关闭防火墙,但是强烈建议生产环境一定不要这么做! iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT service iptables save
关闭selinux
selinux是否关闭。一定要关闭这个,开启selinux会引起一连串问题,甚至zabbix的discovery功能也不能正常使用 关闭SELinux的方法: 修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启。
设置所需服务自动启动
(httpd,mysqld,snmpd,snmptrapd,zabbix-agent,zabbix-server) chkconfig httpd on ; service httpd start chkconfig mysqld on ; service mysqld start chkconfig snmpd on ; service snmpd start chkconfig snmptrapd on ; service snmptrapd start chkconfig zabbix-agent on ; service zabbix-agent start chkconfig zabbix-server on ; service zabbix-server start
修改系统字体(切换成中文后)
cd /usr/share/zabbix/fonts mv graphfont.ttf graphfont.ttf.bak wget -SO graphfont.ttf http://v.dbsa.cn/zabbix/DejaVuSans.ttf #不替换 graphfont.ttf的方法 #下载会字体文件 .ttf #vi /usr/share/zabbix/include/defines.inc.php #('ZBX_GRAPH_FONT_NAME', 'graphfont'); #将graphfont替换为下载的文件名即可 #('ZBX_FONT_NAME', 'graphfont'); #将graphfont替换为下载的文件名即可
部署Zabbix Agent
yum install zabbix-agent zabbix-sender zabbix-get -y # grep -vE '(^$|^#)' /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server=172.16.43.40 #修改为Server的IP,支持多个IP,逗号分隔,使用域名的话,需要支持反向解析 ServerActive=172.16.43.40#修改为Server的IP,不支持写多个IP HostnameItem=system.hostname#默认是用Hostname需要手动指定主机名,改为HostnameItem 使用内部key的自动获取方式 Include=/etc/zabbix/zabbix_agentd.d/ # /etc/init.d/zabbix-agent start # chkconfig zabbix-agent on
##关注日志
#tail -n50 -f /var/log/zabbix/zabbix_agentd.log 1526:20141126:150356.024 Starting Zabbix Agent [localhost.localdomain]. Zabbix 2.4.2 (revision 50419). 1526:20141126:150356.024 using configuration file: /etc/zabbix/zabbix_agentd.conf 1526:20141126:150356.025 agent #0 started [main process] 1530:20141126:150356.026 agent #4 started [listener #3] 1529:20141126:150356.026 agent #3 started [listener #2] 1531:20141126:150356.026 agent #5 started [active checks #1] 1528:20141126:150356.027 agent #2 started [listener #1] 1527:20141126:150356.027 agent #1 started [collector] 1531:20141126:150356.062 no active checks on server [172.16.43.40:10051]: host [localhost.localdomain] not found 同样,'no active checks on server' 也不是一个错误,后续更新的blog会进行描述.
Web安装过程
启动web服务后按照安装指引,配置好数据库,“下一步”即可。