项目: Zabbix监控搭建部署
环境:zabbix-server :192.168.200.130
zabbix-被 监 控:192.168.200.128
一 ZabbixServer的安装:
1.1 搭建自定义yum仓库并安装支持包:
fontconfig-2.8.0-5.el6.x86_64.rpm libX11-common-1.6.4-3.el6.noarch.rpm fontconfig-devel-2.8.0-5.el6.x86_64.rpm libX11-devel-1.6.4-3.el6.x86_64.rpm freetype-2.3.11-17.el6.x86_64.rpm libXau-devel-1.0.6-4.el6.x86_64.rpm freetype-devel-2.3.11-17.el6.x86_64.rpm libxcb-1.12-4.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm libxcb-devel-1.12-4.el6.x86_64.rpm libICE-1.0.6-1.el6.x86_64.rpm libXext-1.3.3-1.el6.x86_64.rpm libSM-1.2.1-2.el6.x86_64.rpm libXpm-devel-3.5.10-2.el6.x86_64.rpm libvpx-1.3.0-5.el6_5.x86_64.rpm libXt-1.1.4-6.1.el6.x86_64.rpm libvpx-devel-1.3.0-5.el6_5.x86_64.rpm repodata libX11-1.6.4-3.el6.x86_64.rpm xorg-x11-proto-devel-7.7-14.el6.noarch.rpm
支持包下载路径:待写-------
1.2 自定义yum仓库并安装支持包:
[root@zabbix-server ~]# mkdir rpm
[root@zabbix-server ~]# cd rpm
[root@zabbix-server rpm]# createrepo -v .
1.3 自定义yum仓库,配置文件修改:
[root@zabbix-server rpm]#vim /etc/yum.repos.d/CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[rpm]
name=rpm #随便设置
baseurl=file:///root/rpm/ #依赖包安装的路径
gpgcheck=0 #开机不检查
enabled=1
~
1.4 安装支持包:
yum -y install pcre pcre-devel zlib-devel libaio libaio-devel libxml2 libxml2-devel bzip2-devel openssl openssl-devel net-snmp-devel net-snmp curl-devel gd gcc gcc-c++ make libjpeg-devel libpng-devel libcurl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker mysql-devel net-snmp-utils
#如果下一步出现问题,请注释掉yum配置文件里的本地光盘源
yum -y install libvpx-devel gd-devel
具体操作不一样方法:6.5虚拟机:
yum配置文件中,原yum配置文件删除,或移动别处,创建自定义yum源,例如rpm.repo
[root@zabbix-server ~]# cd /etc/yum.repos.d/
[root@zabbix-server yum.repos.d]# ls
bak CentOS-Media.repo
[rootzabbix-server yum.repos.d]# vim rpm.repo #创建自定义yum
[rpm]
name=rpm
baseurl=file:///root/rpm/ #rpm包所在的路径
gpgcheck=0
enabled=1
[root@zabbix-server yum.repos.d]# mv CentOS-Media.repo bak/
#把本地yum源注释,或者移动到别处。
[root@zabbix-server yum.repos.d]# yum -y install libvpx-devel gd-devel
成功如下:------------
具体操作方法:7.5虚拟机:
[root@zabbix-server ~]# cd /etc/yum.repos.d
[root@zabbix-server yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/CentOS-Media.repo
[root@@zabbix-server yum.repos.d]# yum -y install libvpx-devel gd-devel
二 编译安装LNMP环境
2.1 安装nginx
[root@@zabbix-server ~]# useradd -s /sbin/nologin -M www
[root@@zabbix-server ~]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@@zabbix-server ~]# cd /usr/src/nginx-1.10.2/
[root@@zabbix-server nginx-1.10.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module && make && make install
[root@@zabbix-server nginx-1.10.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
#创建nginx配置文件模版
[root@@zabbix-server nginx-1.10.2]# cd /usr/local/nginx/conf/
egrep -v "^$|#" nginx.conf.default > nginx.conf
#将nginx配置文件改成如下内容
[root@@zabbix-server conf]# vim nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
location = /nginx-status {
stub_status on;
access_log off;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@@zabbix-server conf]# nginx -t
# /usr/local/nginx/sbin/nginx启动
#补充:/usr/local/nginx/sbin/nginx -s stop 停止
/usr/local/nginx/sbin/nginx -s reload 平滑重启
[root@@zabbix-server conf]# /usr/local/nginx/sbin/nginx
[root@@zabbix-server conf]#ss -antup | grep 80 #查看是否启动
yum -y install pcre-devel openssl-devel
[root@@zabbix-server conf]# scp nginx.conf 192.168.200.128://usr/local/nginx/conf/
#管理机ngxin.conf 复制到 192.168.200.128://usr/local/nginx/conf/ 被管理机下:
2.2 安装mysql
[root@@zabbix-server ~]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/
[root@@zabbix-server~]# cd /usr/local/
[root@@zabbix-server local]# mv mysql-5.5.32-linux2.6-x86_64 mysql
[root@@zabbix-server local]# cd mysql
[root@@zabbix-server mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
[root@@zabbix-server mysql]# useradd -s /sbin/nologin -M mysql
[root@@zabbix-server mysql]# chown -R mysql.mysql data
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql #初始化数据库
[root@zabbix-server mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@zabbix-server mysql]# chmod +x /etc/init.d/mysqld
[root@zabbix-server mysql]# /etc/init.d/mysqld start #启动mysql
[root@zabbix-server mysql]# ss -antup | grep 3306 #查看mysql启动情况
[root@zabbix-server mysql]# chkconfig --add mysqld 设置MySQL开机自启动
[root@zabbix-server mysql]# chkconfig mysqld on
[root@zabbix-server mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
提示:也可以将启动命令/etc/init.d/mysqld start 放到/etc/rc.local里面
[root@zabbix-server mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/ 创建mysql命令
[root@zabbix-server mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
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.
mysql> Ctrl-C -- exit!
Server version: 5.5.32 MySQL Community Server (GPL)
[root@zabbix-server mysql]# mysqladmin -u root password '123123' #给mysql设密码
3 安装libmcrypt:
[root@zabbix-server ~]# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/
[root@zabbix-server ~]# cd /usr/src/libmcrypt-2.5.8/
[root@zabbix-serverlibmcrypt-2.5.8]# ./configure && make && make install
4 安装GD:
[root@zabbix-server ~]# tar xf GD-2.18.tar.gz -C /usr/src/
[root@zabbix-server ~]# cd /usr/src/GD-2.18/
[root@zabbix-server GD-2.18]# perl Makefile.PL
[root@zabbix-servert GD-2.18]# make && make install
5 安装PHP
[root@zabbix-server ~]# tar xf php-5.6.30.tar.gz -C /usr/src/
[root@zabbix-server ~]# cd /usr/src/php-5.6.30/
[root@zabbix-server php-5.6.30]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
[root@zabbix-server php-5.6.30]# make && make install
[root@zabbix-server php-5.6.30]# cp php.ini-development /usr/local/php/etc/php.ini
#创建php配置文件
[root@zabbix-server php-5.6.30]# vim /usr/local/php/etc/php.ini
[root@zabbix-server php-5.6.30]# cat -n /usr/local/php/etc/php.ini | sed -n '372p;382p;393p;660p;702p;820p;936p'
372 max_execution_time = 300
382 max_input_time = 60
393 memory_limit = 128M
660 post_max_size = 8M
702 always_populate_raw_post_data = -1
820 upload_max_filesize = 2M
936 date.timezone =Asia/Shanghai
cat -n /usr/local/php/etc/php.ini | sed -n '372p;382p;393p;660p;702p;820p;936p'
[root@zabbix-server php-5.6.30]# cd /usr/local/php/etc/ #创建php-fpm配置文件
[root@zabbix-server etc]# cp php-fpm.conf.default php-fpm.conf
修改php-fpm.conf配置文件:如下--
[root@zabbix-server etc]# vim php-fpm.conf +149
[root@zabbix-server etc]# cat -n php-fpm.conf | sed -n '149,150p'
149user = www
150group = www
2.3 安装zabbix server端
2.3.1 编译安装zabbix server
[root@zabbix-server etc]#useradd zabbix -s /sbin/nologin -M
[root@zabbix-server etc]# cd ~
[root@zabbix-server ~]# tar xf zabbix-3.2.4.tar.gz -C /usr/src/
[root@zabbix-server ~]# cd /usr/src/zabbix-3.2.4/
[root@zabbix-server zabbix-3.2.4]# ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --with-libxml2
[root@zabbix-server zabbix-3.2.4]# make && make install
#由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前简历软连接:
[root@zabbix-server zabbix-3.2.4]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@zabbix-server zabbix-3.2.4]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
2.3.2 配置zabbix的mysql环境
[root@zabbix-server zabbix-3.2.4]# mysqladmin -uroot password '123123'
[root@zabbix-server zabbix-3.2.4]# mysql -uroot -p123123 -e 'create database zabbix character set utf8;'
[root@zabbix-server zabbix-3.2.4]# mysql -uroot -p123123 -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by '123123';"
[root@zabbix-server zabbix-3.2.4]# mysql -uroot -p123123 -e 'flush privileges;'
#如下数据的导入顺序不可以错:
[root@6 zabbix-3.2.4]# mysql -uzabbix -p123123 zabbix < /usr/src/zabbix-3.2.4/database/mysql/schema.sql
[root@zabbix-server zabbix-3.2.4]# mysql -uzabbix -p123123 zabbix < /usr/src/zabbix-3.2.4/database/mysql/images.sql
[root@zabbix-server zabbix-3.2.4]# mysql -uzabbix -p123123 zabbix < /usr/src/zabbix-3.2.4/database/mysql/data.sql
2.4 安装Zabbix web GUI
[root@6 zabbix-3.2.4]# cd ~
[root@6 ~]# cp -rp /usr/src/zabbix-3.2.4/frontends/php /usr/local/nginx/html/zabbix
[root@zabbix-server~]# cd /usr/local/nginx/html/
[root@zabbix-server html]# chown -R www.www zabbix
2.4.2 启动nginx服务及php-fpm
[root@zabbix-server html]# /usr/local/nginx/sbin/nginx
[root@zabbix-server html]# /usr/local/php/sbin/php-fpm
[root@zabbix-server html]# netstat -antup | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 32657/php-fpm: mast
2.4.3 登录web根据提示生成zabbix.conf.php配置文件
[roo@zabbix-server ~]# cd /usr/local/nginx/html/zabbix/conf
[root@zabbix-server conf]# ls
maintenance.inc.php zabbix.conf.php.example #登录目录锁有的东西
在浏览器里输入http://IP/zabbix,配置zabbix数据库环境,如下图所示
调中文模式:
执行如上图所示的步骤生成zabbix.conf.php配置文件
[root@6 conf]# ls
maintenance.inc.php zabbix.conf.php zabbix.conf.php.example
修改zabbix密码:
三,zabbix server的配置
3.1 zabbix_server.conf配置
通过源码安装方式将zabbix安装到/usr/local/zabbix下面,zabbix server的
配置文件为/usr/local/zabbix/etc/zabbix_server.conf,需要修改的内容为如下:
[root@6 conf]# cd /usr/local/zabbix/etc/
grep -Ev '^#|^$' zabbix_server.conf
[root@6 etc]# vim zabbix_server.conf +12 #打开12行
12 ListenPort=10051 #zabbix server监听端口
38 LogFile=/tmp/zabbix_server.log #zabbix server日志路径
87 DBName=zabbix #zabbix server连接MySQL数据库的数据库名
103 DBUser=zabbix #zabbix server连接MySQL数据库的用户名
111 DBPassword=123123 #zabbix server连接MySQL数据库的密码
118 DBSocket=/tmp/mysql.sock #MySQL的实例文件位置
136 StartPollers=5 #用于设置zabbix server服务启动时启动Pollers(主动收集数据进程)的数量,数量越多,则服务端吞吐能力越强,同时对系统资源消耗越大
165 StartTrappers=10 #用于设置zabbix server服务启动时启动Trappers(负责处 理Agentd推送过来的数据的进程)的数量。Agentd为主动模式时,zabbix server需要设置这个值大一些。
181 StartDiscoverers=10 #用于设置zabbix server服务启动时启动Discoverers进程.数量,如果zabbix监控报Discoverers进程忙时,需要提高该值。
297 ListenIP=0.0.0.0 #zabbix server启动的监听端口对哪些ip开放,Agentd为主 动模式时,这个值建议设置为0.0.0.0
447 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix sever运行脚本存放目录,一些供zabbix server使用的脚本,都可以放在这里。0
[root@6 etc]# vim /etc/services #最后添加以下内容:
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
(vim 中 :$跳转最后 :1 跳转第一行)
3.3 添加管理维护脚本
[root@6 etc]# cp /usr/src/zabbix-3.2.4/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
[root@zabbix-server etc]# cd /etc/init.d/
[root@zabbix-server init.d]# chmod +x /etc/init.d/zabbix_server
[root@zabbix-server init.d]# chkconfig zabbix_server on
3.4 启动zabbix_server端进程
[root@zabbix-server init.d]# /etc/init.d/zabbix_server start
[root@zabbix-server init.d]# ss -antup | grep 1005 #查看1005端口启动情况
四,zabbix_agent(还在本机安装agent端)的安装与配置
zabbix agent端的安装建议采用rpm包方式安装 zabbix-
agent-3.2.4-1.el6.x86_64.rpm(和servic端一样的RPM文件)
[root@zabbix-server ~]# cd ~
[root@zabbix-server ~]# rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm
(注意:另一台zabbix-被监控 也需要安装,才可被监控 )
[root@zabbix-被监控 ~]# rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm
然后回到:zabbix-server监控主机:
修改zabbix配置文件:------------------------------------------------
[root@zabbix-server ~]# cd /etc/zabbix/
[root@zabbix-server zabbix]# ls
zabbix_agentd.conf zabbix_agentd.d
[root@zabbix-server zabbix]# vim zabbix_agentd.conf
(注意:vim中 数字+gg 跳转到那一行)
- 13 PidFile=/var/run/zabbix/zabbix_agentd.pid #进程pid存放路径
- 32 LogFile=/var/log/zabbix/zabbix_agentd.log #zabbix agent日志存放路径
- 95 Server=127.0.0.1,192.168.0.220 #指定zabbix server端IP地址
- 103 ListenPort=10050 #指定agentd的监听端口
- 120 StartAgents=3 #指定启动agentd进程数量。设置0表示关闭
- 136 ServerActive=192.168.0.220:10051 #启用agnetd主动模式,启动主动模式后,agentd将主动将收集到的数据发送到zabbix server端,Server Active后面指定的IP就是zabbix server端IP
- 147 Hostname=192.168.0.220 #需要监控服务器的主机名或者IP地址,此选项的设置一定要和zabbix web端主机配置中对应的主机名一致。
- 265 Include=/etc/zabbix/zabbix_agentd.d/ #相关配置都可以放到此目录下,自动生效
- 284 UnsafeUserParameters=1 #启用agent端自定义item功能,设置此参数为1后,就可以使用UserParameter指令了。UserParameter用于自定义item
[root@zabbix-server zabbix]# /etc/init.d/zabbix-agent start
#zabbix-server启动zabbix_agent端进程
[root@zabbix-server zabbix]# netstat -antup | grep 10050
[root@zabbix-server zabbix]# chkconfig zabbix-agent on
五,被监控端进行操作:
[root@zabbix-被监控 ~]#
[root@zabbix-server zabbix]# scp zabbix_agentd.conf root@192.168.200.129:/etc/zabbix/
#zabbix-server端,先把其zabbix_agentd.conf远程复制到,被监控端,
[root@zabbix-被监控 ~]# cd /etc/zabbix/
[root@zabbix-被监控 zabbix]# vim zabbix_agentd.conf
95 Server=192.168.200.129 #127.0.0.1本地的被监控端要关闭,此时
被监控端。即本机的ip
147 Hostname=192.168.200.135 #改成自己,被监控主机的ip
[root@zabbix-被监控 zabbix]# /etc/init.d/zabbix-agent start
[root@zabbix-被监控 zabbix]# netstat -antup | grep 10050
如何测试一下,zabbix-server端成功监测beikongzhi端:
在zabbix-server端操作如下:
zabbix_get -s 192.168.200.134 -p 10050 -k "system.uptime"
打开浏览器中:zabbix界面:
六,Zabbix的web操作入门
6.1.3 追加常用的监控图形
报警模式设置:
Zabbix共享模板下载:
自定义被监控的服务器:
自定义一个主机
注意:
cd /etc/zabbix/
说明:我的zabbix主机就是本机,用本机来检测本机内的agentd端:其agentd配置文件如下:
Zabbix主机agentd配置:cd /usr/local/zabbix/etc
第二台被监控主机【配置】