Linux之CentOS 7 安装Zabbix 3

  • A+
所属分类:Linux  自动化运维
摘要

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供柔软的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix 由2部分构成,zabbix server 与可选组件zabbix agent。

zabbix server 可以通过SNMP,zabbix agent ,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台之上。

zabbix agent 需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent 可以运行在Linux ,Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系统之上。

zabbix server 可以单独监视远程服务器的服务状态;同时也可以与zabbix agent 配合,可以轮询zabbix agent 主动接收监视数据(trapping方式),同时还可被动接收zabbix agent 发送的数据(trapping方式)。

另外zabbix server 还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。

zabbix的主要特点:

  1. 安装与配置简单,学习成本低
  2. 支持多语言(包括中文)
  3. 免费开源
  4. 自动发现服务器与网络设备
  5. 分布式监视以及WEB集中管理功能
  6. 可以无agent监视
  7. 用户安全认证和柔软的授权方式
  8. 通过WEB界面设置或查看监视结果
  9. email等通知功能,等等

1、系统配置和安装必要包

[root@DS-VM-Node251 ~]# yum -y install epel-release
[root@DS-VM-Node251 ~]# yum clean all && yum makecache
[root@DS-VM-Node251 ~]# yum groupinstall "Development tools" "Server Platform Development" -y
[root@DS-VM-Node251 ~]# yum install ntpdate -y
[root@DS-VM-Node251 ~]# $(which ntpdate) pool.ntp.org && echo "*/5 * * * * $(which ntpdate) pool.ntp.org >/dev/null 2>&1" >> /var/spool/cron/root

2、编译安装Nginx

[root@DS-VM-Node251 ~]# mkdir /tmp/nginx && cd /tmp/nginx
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# wget -c http://mirrors.dwhd.org/Nginx/nginx-1.9.14.tar.gz
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# tar xf nginx-1.9.14.tar.gz && cd nginx-1.9.14/
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# adduser -r -s /sbin/nologin -c 'Web Server' -M www
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# mkdir -p /data/{wwwlogs/nginx,wwwroot}
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# chown -R www.www /data/{wwwlogs/nginx,wwwroot}
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# yum -y install pcre-devel openssl-devel
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# ./configure --prefix=/usr/local/nginx/ \
--user=www --group=www \
--error-log-path=/tmp/nginx/error.log \
--http-log-path=/tmp/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-pcre \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-client-body-temp-path=/usr/local/nginx/client/ \
--http-proxy-temp-path=/usr/local/nginx/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi
[root@DS-VM-Node251 /tmp/nginx/nginx-1.9.14]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
[root@DS-VM-Node251 /tmp]# echo "export PATH=/usr/local/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
[root@DS-VM-Node251 /tmp]# . /etc/profile.d/nginx.sh
[root@DS-VM-Node251 /tmp]# cat /usr/local/nginx/conf/vhost/zabbix.ds.com.conf
server {
    listen       80;
    server_name zabbix.ds.com;
    access_log  /data/wwwlogs/nginx/zabbix.ds.com_access.log  combined;
 
    index index.html index.php index.html;
    root /data/wwwroot/zabbix.ds.com/;
 
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
 
    location ~ ^(.+.php)(.*)$ {
        fastcgi_split_path_info ^(.+.php)(.*)$;
        include fastcgi.conf;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  PATH_INFO          $fastcgi_path_info;
    }
}
[root@DS-VM-Node251 /tmp]# 

3、编译安装php

[root@DS-VM-Node251 /tmp]# mkdir /tmp/php && cd /tmp/php
[root@DS-VM-Node251 /tmp/php]# yum -y install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
[root@DS-VM-Node251 /tmp/php]# wget -c http://cn2.php.net/get/php-5.6.20.tar.xz/from/this/mirror -O php-5.6.20.tar.xz
[root@DS-VM-Node251 /tmp/php]# tar xf php-5.6.20.tar.xz
[root@DS-VM-Node251 /tmp/php]# cd php-5.6.20/
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# ./configure  --prefix=/usr/local/php/ \
--with-config-file-path=/usr/local/php/etc \
--with-bz2 --with-curl --enable-ftp \
--enable-dom --enable-xml --enable-fpm \
--enable-ipv6 --enable-bcmath --enable-sockets \
--enable-mbstring --enable-calendar \
--enable-gd-native-ttf --with-gd --with-zlib \
--with-gettext --with-libdir=lib64 \
--with-mysql=mysqlnd --with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd --with-png-dir=/usr/local \
--with-jpeg-dir=/usr/local --with-iconv-dir=/usr/local \
--with-libxml-dir=/usr/local --with-freetype-dir=/usr/local
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# cp php.ini-production /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/^(max_execution_time = ).*/\1300/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/^(memory_limit = ).*/\1128M/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/^(post_max_size = ).*/\116M/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/^(upload_max_filesize = ).*/\12M/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/^(max_input_time = ).*/\1300/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri '/date.timezone =/a date.timezone = PRC' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# sed -ri 's/.*(always_populate_raw_post_data .*)/\1/' /usr/local/php/etc/php.ini
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# chmod +x /etc/init.d/php-fpm
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# chkconfig php-fpm on
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# service php-fpm start
Starting php-fpm  done
[root@DS-VM-Node251 /tmp/php/php-5.6.20]# ss -tnl | grep ':9000'
LISTEN     0      128    127.0.0.1:9000  
[root@DS-VM-Node251 /tmp/php/php-5.6.20]#  cd ../..
[root@DS-VM-Node251 /tmp]# echo "export PATH=/usr/local/php/bin:\$PATH" > /etc/profile.d/php.sh
[root@DS-VM-Node251 /tmp]# . /etc/profile.d/php.sh
[root@DS-VM-Node251 /tmp]# php -v
PHP 5.6.20 (cli) (built: Apr  8 2016 20:05:52) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@DS-VM-Node251 /tmp]#

4、安装MariaDB

[root@DS-VM-Node251 /tmp]# mkdir /tmp/mariadb && cd /tmp/mariadb
[root@DS-VM-Node251 /tmp/mariadb]# adduser -r -m -d /data/mariadb -k no -s /sbin/nologin -c 'Mariadb Database' mysql
[root@DS-VM-Node251 /tmp/mariadb]# chown -R mysql.mysql /data/mariadb
[root@DS-VM-Node251 /tmp/mariadb]# wget http://mirrors.dwhd.org/SQL/MariaDB/mariadb-10.0.23/source/mariadb-10.0.23.tar.gz
[root@DS-VM-Node251 /tmp/mariadb]# tar xf mariadb-10.1.13.tar.gz 
[root@DS-VM-Node251 /tmp/mariadb]# cd mariadb-10.1.13/
[root@DS-VM-Node251 /tmp/mariadb/mariadb-10.0.23]# yum -y install cmake ncurses-devel
[root@DS-VM-Node251 /tmp/mariadb/mariadb-10.0.23]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/data/mariadb \
-DWITH_SSL=system -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 -DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 -DWITH_READLINE=1 -DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8
[root@DS-VM-Node251 /tmp/mariadb/mariadb-10.0.23]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
[root@DS-VM-Node251 /tmp]# cd /usr/local/mariadb
[root@DS-VM-Node251 /usr/local/mariadb]# wget http://www.dwhd.org/script/mysql_my.cnf -cO- >/etc/my.cnf
[root@DS-VM-Node251 /usr/local/mariadb]# /usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
[root@DS-VM-Node251 /usr/local/mariadb]# service mysqld start
Starting mysqld (via systemctl):                           [  确定  ]
[root@DS-VM-Node251 /usr/local/mariadb]# curl -s http://www.dwhd.org/script/mysql_zabbix_init.sql >/tmp/mysql_zabbix_init.sql
[root@DS-VM-Node251 /usr/local/mariadb]# mysql -uroot -e "source /tmp/mysql_zabbix_init.sql;"
+--------+-------------------------------------------+---------------------------+
| USER   | PASSWORD                                  | HOST                      |
+--------+-------------------------------------------+---------------------------+
| root   | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | localhost                 |
| root   | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ds-vm-node251.cluster.com |
| root   | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 127.0.0.1                 |
| root   | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ::1                       |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | localhost                 |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 127.0.0.1                 |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | ::1                       |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 192.168.%.%               |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 172.16.%.%                |
| zabbix | *153CCFAEAA83407D8DBDBFAA3D17B1A95553E60C | 10.%.%.%                  |
+--------+-------------------------------------------+---------------------------+
[root@DS-VM-Node251 /usr/local/mariadb]# cd ~ 

5、安装JDK

[root@DS-VM-Node251 ~]# yum install http://mirrors.ds.com/tar_source/JDK/jdk-8u77-linux-x64.rpm -y
[root@DS-VM-Node251 ~]# cat > /etc/profile.d/java.sh << EOF
JAVA_HOME=/usr/java/latest
PATH=\$JAVA_HOME/bin:\$PATH
export JAVA_HOME PATH
EOF
[root@DS-VM-Node251 ~]# . /etc/profile.d/java.sh
[root@DS-VM-Node251 ~]# java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
[root@DS-VM-Node251 ~]# 

6、安装Zabbix3.0

[root@DS-VM-Node251 ~]# useradd -r -s /sbin/nologin -M -d /data/wwwroor/zabbix.ds.com -c 'Zabbix Server' zabbix
[root@DS-VM-Node251 ~]# mkdir -p /tmp/zabbix && cd /tmp/zabbix
[root@DS-VM-Node251 /tmp/zabbix]# wget -c http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.1/zabbix-3.0.1.tar.gz
[root@DS-VM-Node251 /tmp/zabbix]# tar xf zabbix-3.0.1.tar.gz 
[root@DS-VM-Node251 /tmp/zabbix]# cd zabbix-3.0.1/
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# yum install -y net-snmp-devel OpenIPMI OpenIPMI-devel perl-ZMQ-LibZMQ3 curl-devel libxml2-devel
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# ./configure --prefix=/usr/local/zabbix/ \
--sysconfdir=/etc/zabbix \
--enable-server \
--enable-proxy \
--enable-agent \
--enable-ipv6 \
--enable-java \
--with-mysql=/usr/local/mariadb/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-openipmi \
--with-libxml2
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# echo "export PATH=/usr/local/zabbix/sbin:\$PATH" > /etc/profile.d/zabbix.sh
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# . /etc/profile.d/zabbix.sh
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# for i in schema.sql images.sql data.sql; do mysql -uroot -plookback zabbix < ./database/mysql/$i;done 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri '/^DBName=/d' /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri '/^DBUser=/d' /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri '/^DBPassword=/d' /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri "s/(DBName=)/&\n\1zabbix/" /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri "s/(DBUser=)/&\n\1zabbix/" /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -ri "s/.*(DBPassword=).{0,}/&\n\1lookback/" /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i '/JavaGateway=/a JavaGateway=127.0.0.1\nJavaGatewayPort=10052\nStartJavaPollers=5' /etc/zabbix/zabbix_server.conf 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i '/LISTEN_IP="0.0.0.0"/a LISTEN_IP="0.0.0.0"' /usr/local/zabbix/sbin/zabbix_java/settings.sh 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i '/LISTEN_PORT=10052/a LISTEN_PORT=10052' /usr/local/zabbix/sbin/zabbix_java/settings.sh 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i '/START_POLLERS=5/a START_POLLERS=5' /usr/local/zabbix/sbin/zabbix_java/settings.sh 
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# ln -sv /usr/local/mariadb/lib/libmysqlclient.so.18 /usr/lib/ "/usr/lib/libmysqlclient.so.18" -> "/usr/local/mariadb/lib/libmysqlclient.so.18"
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# ln -sv /usr/local/mariadb/lib/libmysqlclient.so.18 /usr/lib64/
"/usr/lib64/libmysqlclient.so.18" -> "/usr/local/mariadb/lib/libmysqlclient.so.18"
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# ldconfig
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# cat >> /etc/services << EOF
zabbix-agent    10050/tcp        #ZabbixAgent
zabbix-agent    10050/udp        #Zabbix Agent
zabbix-trapper  10051/tcp        #ZabbixTrapper
zabbix-trapper  10051/udp        #Zabbix Trapper
EOF
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# mkdir -p /data/wwwroot/zabbix.ds.com
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i '/zh_CN/{s/false/true/}' ./frontends/php/include/locales.inc.php
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i 's/DejaVuSans/simkai/g' ./frontends/php/include/defines.inc.php
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# cp -rp ./frontends/php/* /data/wwwroot/zabbix.ds.com/
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# wget http://www.dwhd.org/wp-content/uploads/2015/05/simkai.ttf -O /data/wwwroot/zabbix.ds.com/fonts/simkai.ttf
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# chown -R www.www /data/wwwroot/zabbix.ds.com
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# cp -a ./misc/init.d/fedora/core/zabbix_server /etc/init.d/
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# cp -a ./misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_server
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_agentd
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# chkconfig zabbix_server on
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# chkconfig zabbix_agentd on
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# service zabbix_server start
Starting zabbix_server (via systemctl):                    [  确定  ]
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# service zabbix_agentd start
Starting zabbix_agentd (via systemctl):                    [  确定  ]
[root@DS-VM-Node251 /tmp/zabbix/zabbix-3.0.1]# iptables -A -p tcp -m tcp --dport 80 -j ACCEPT

Linux之CentOS 7 安装Zabbix 3

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: