Linux配置監控服務器:Zabbix監控(一)
阿新 • • 發佈:2018-04-12
zabbix一、Linux監控平臺介紹
- cacti、nagios、zabbix、smokeping、open-falcon等;
- cacti、smokeping偏向基礎監控,成圖非常漂亮;
- cacti、nagios、zabbix服務端監控中心,需要PHP環境支持,其中zabbix和cacti都需要mysql作為數據存儲,nagios不用存儲歷史數據,註重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而可以成圖;
- open-falcon為小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究;
二、Zabbix監控介紹
- C/S架構,基於C++開發,監控中心支持web界面配置和管理;
- 單server節點可以支持上萬臺客戶端;
- 最新版本3.4 ,官網文檔https://www.zabbix.com/manuals
1、組件
Zabbix整個體系架構中有幾個主要角色:
- zabbix-server:核心,監控中心,接收客戶端上報信息,負責配置、統計、操作數據;
- 數據存儲:存放數據,比如mysql;
- web界面:也叫web UI ,在web界面下操作配置是zabbix簡單易用的主要原因;
- zabbix-proxy:可選組件,它可以代替zabbix-server的功能,減輕server的壓力;
- zabbix-agent:客戶端軟件,負責采集各個監控服務或項目的數據,並上報。
2、架構
三、Zabbix監控安裝與部署
1、用yum安裝Zabbix
[root@zlinux-01 ~]# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm //下載Zabbix的yum擴展源 [root@zlinux-01 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm //安裝擴展源 [root@zlinux-01 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql //安裝相關安裝包 #會連帶安裝httpd和php #如果mysql之前沒有裝的話,需要根據lamp那一章的mysql安裝方法安裝msyql [root@zlinux-01 ~]# ps aux | grep mysql //查看mysql服務是否啟動,沒有就啟動下
2、配置MySQL
[root@zlinux-01 ~]# vim /etc/my.cnf //在[mysqld]下添加以下一行
character_set_server = utf8
[root@zlinux-01 ~]# systemctl restart mysql //重啟mysql
[root@zlinux-01 ~]# mysql -uroot -pzlinux123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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.
mysql> create database zabbix character set utf8; //創建zabbix庫,字符集utf8
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘zlinux123456‘; //創建zabbix用戶,為了zabbix連接數據庫
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
#導入zabbix數據庫
[root@zlinux-01 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@zlinux-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@zlinux-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
[root@zlinux-01 zabbix-server-mysql-3.2.11]# mysql -uroot -pzlinux123456 zabbix < create.sql
#修改zabbix-server配置文件
[root@zlinux-01 ~]# vim /etc/zabbix/zabbix_server.conf //加入以下內容
DBHost=127.0.0.1
DBPassword=zlinux123456
3、啟動相關服務
[root@zlinux-01 ~]# systemctl stop nginx //先停止掉Nginx服務因為占用了80,或者Nginx做下代理配置,可參考前文
[root@zlinux-01 ~]# systemctl start httpd //啟動httpd
[root@zlinux-01 ~]# ps aux | grep httpd
root 3472 0.0 0.8 394324 15480 ? Ss 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3474 0.0 0.4 394460 7680 ? S 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3475 0.0 0.4 394460 7680 ? S 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3476 0.0 0.4 394460 7680 ? S 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3477 0.0 0.4 394460 7680 ? S 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3478 0.0 0.4 394460 7680 ? S 15:20 0:00 /usr/sbin/httpd -DFOREGROUND
[root@zlinux-01 ~]# systemctl start zabbix-server //啟動zabbix服務
[root@zlinux-01 ~]# ps aux | grep zabbix //查看zabbix相關,成功的情況下有很多條服務
[root@zlinux-01 ~]# netstat -lntp //80,3306,11051三個端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:45930 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 995/rpc.mountd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 839/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1703/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 3393/zabbix_server
tcp 0 0 0.0.0.0:42343 0.0.0.0:* LISTEN 824/rpc.statd
tcp6 0 0 :::3306 :::* LISTEN 3330/mysqld
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 3472/httpd
tcp6 0 0 :::38704 :::* LISTEN -
tcp6 0 0 :::20048 :::* LISTEN 995/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 839/sshd
tcp6 0 0 :::40375 :::* LISTEN 824/rpc.statd
tcp6 0 0 ::1:25 :::* LISTEN 1703/master
tcp6 0 0 :::2049 :::* LISTEN -
tcp6 0 0 :::10051 :::* LISTEN 3393/zabbix_server
4、配置web界面
步驟1:
步驟2:
要解決此問題,需要編輯phph.ini或者Zabbix的httpd配置:
[root@zlinux-01 ~]# vim /etc/httpd/conf.d/zabbix.conf //在最後增加下面一行
php_value date.timezone Asia/Shanghai
[root@zlinux-01 ~]# systemctl restart httpd //重啟
步驟3:刷新下瀏覽器,繼續下一步
步驟4:
步驟5:登錄管理後臺首先更改密碼,默認賬戶:admin,密碼:zabbix
5、Zabbix客戶端部署
[root@zlinux-04 ~]# http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
[root@zlinux-04 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
[root@zlinux-04 ~]# yum install -y zabbix-agent
[root@zlinux-04 ~]# vim /etc/zabbix/zabbix_agentd.conf //修改以下內容
Server=192.168.242.128 //定義服務端IP(被動模式)
Server=192.168.242.128 //定義服務點IP(主動模式)
Hostname=zlinux-01 //自定義主機名
[root@zlinux-04 ~]# systemctl start zabbix-agent //啟動
[root@zlinux-04 ~]# netstat -lnp | grep zabbix //zabbix-agent監聽10050端口
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 2436/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 2436/zabbix_agentd
Linux配置監控服務器:Zabbix監控(一)