首页 > 代码库 > Zabbix3.0完整部署

Zabbix3.0完整部署

0. 准备工作

0.1 初始化

#!/bin/shyum clean allsystemctl stop firewalld.servicesystemctl disable firewalld.servicesed -i s/enforcing/disabled/g /etc/selinux/configyum -y install vim openssh* ntp wget screen bash-completionservice ntpd stopntpdate time.nist.govsed -i s/0.centos.pool.ntp.org/time.nist.gov/g /etc/ntp.confchkconfig ntpd onservice ntpd restart

 

0.2 依赖环境

0.2.1 直接使用LAMP环境

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gmp-devel mysql-devel net-snmp-devel perl-DBI libxml libxml-devel gd-devel httpd-manual mod_ssl mod_perl mod_auth_mysql mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel wget fping *ODBC* httpd 

0.2.2 安装数据库

//CentOS 6.x及以下版本

yum -y install mysql mysql-server 


//CentOS 7.x及以上版本

yum install mariadb*

 

0.2.3 安装PHP5.6

CentOS 6.5源

rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 


CentOS 7 源

yum install epel-release rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm 


安装PHP 5.6

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-gd php-mysql php-bcmath php-mbstring php-xml

 

2. 启动LAMP环境

2.1 数据库编码统一

在MariaDB/MySQL关闭的前提下,/etc/my.cnf增加以下内容:

[client] port = 3306 default-character-set = utf8 [mysqld] port = 3306 character-set-server = utf8 character-set-filesystem = utf8

 

2.2 启动服务

service mariadb startservice httpd start

2.2 初始化MySQL密码:

mysqladmin -u root password ning123

2.3 验证数据库编码:

MariaDB [(none)]> show variables like %char%;+--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | utf8                       || character_set_connection | utf8                       || character_set_database   | utf8                       || character_set_filesystem | utf8                       || character_set_results    | utf8                       || character_set_server     | utf8                       || character_set_system     | utf8                       || character_sets_dir       | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.00 sec)
 

3. Zabbix Server安装

3.1 环境下载准备

cd /usr/local/srcwget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gzwget http://www.zabbix.com/downloads/3.0.0/zabbix_agents_3.0.0.linux2_6.amd64.tar.gztar zxvvf zabbix-3.0.4.tar.gz

 

3.2 创建Zabbix用户组

groupadd zabbixuseradd zabbix -g zabbix -s /sbin/nologin

3.3 创建数据库并授权用户

MariaDB [(none)]> create database zabbix character set utf8;MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by zabbix;

3.4 导入Zabbix定义的表结构和数据

cd /usr/local/src/zabbix-3.0.4/database/mysqlmysql -uzabbix -pzabbix zabbix < schema.sqlmysql -uzabbix -pzabbix zabbix < images.sqlmysql -uzabbix -pzabbix zabbix < data.sql

3.5 编译安装Zabbix Server

/usr/local/src/zabbix-3.0.4./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --enable-java --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-ldap --with-unixodbc --with-ssh --with-openipmi --with-jabbermake && make install

配置参数说明:

参数|注释—|—–prefix=/usr/local/zabbix|//服务安装路径–enable-server|//安装Zabbix Server–enable-angent|//安装Zabbix Agent–enable-proxy|//安装Zabbix Proxy–with-mysql|//使用MySQL做数据库服务器–with-net-snmp|//支持SNMP–with-libcurl|//支持curl,用于web监控

 

3.6 服务端口定义

vim /etc/serviceszabbix-agent    10050/tcp               # Zabbix Agentzabbix-agent    10050/udp               # Zabbix Agentzabbix-trapper  10051/tcp               # Zabbix Trapperzabbix-trapper  10051/udp               # Zabbix Trapper

3.7 修改Zabbix Server配置文件

vim /usr/local/zabbix/etc/zabbix_server.conf
参数
注释
LogFile=/tmp/zabbix_server.log//日志位置,根据需求修改
PidFile=/tmp/zabbix_server.pid//PID所在位置
DBHost=localhost//数据库IP,如果不是本机,请修改
DBName=zabbix//数据库名称
DBUser=zabbix//数据库用户名
DBPassword=zabbix//数据库密码

3.8 安装启动脚本,添加可执行权限

cd /usr/local/src/zabbix-3.0.4/misc/init.d/fedora/corecp zabbix_server /etc/init.d/chmod +x /etc/init.d/zabbix_server

3.9 修改启动脚本,启动Zabbix Server

vim /etc/init.d/zabbix_serverBASEDIR=/usr/local/zabbix //修改Zabbix的安装目录CONFILE=$BASEDIR/etc/zabbix_server.conf //添加此行,定义配置文件位置##搜索start,修改启动选项,默认是去/etc下去找配置文件action $"Starting $BINARY_NAME: " $FULLPATH -c $CONFILE

3.10 启动服务

service zabbix_server start

4. 安装Zabbix Web界面

4.1 复制Web代码到httpd配置文件指定目录下

apache默认为:/vat/www/html

cd /usr/local/src/zabbix-3.0.4/frontends/ cp -r php /var/www/html/zabbix

 

4.2 修改date()的错误

vim /etc/php.inidate.timezone = Asia/Shanghai //时区修改为上海

5. Zabbix Agent 安装(在被监控的客户机上安装)

5.1 下载解压编译好的客户端

cd /usr/local/srcwget http://www.zabbix.com/downloads/3.0.0/zabbix_agents_3.0.0.linux2_6.amd64.tar.gzmkdir /usr/local/zabbix_agentstar zxvvf zabbix_agents_3.0.0.linux2_6.amd64.tar.gz -C /usr/local/zabbix_agents/

 

5.2 编辑配置文件

cd /usr/local/zabbix_agents/conf/vim zabbix_agentd.conf
参数
注释
LogFile=/tmp/zabbix_agentd.log//日志路径
Server=192.168.0.22//Zabbix Server IP
ServerActive=192.168.0.22//Zabbix Server IP
Hostname=192.168.0.23//设定本地主机名

5.3 安装修改启动脚本(脚本在服务端的源码包里)

cd /usr/local/src/zabbix-3.0.4/misc/init.d/fedora/corevim zabbix_agentdBASEDIR=/usr/local/zabbix_agents //修改zabbix_agentd安装路径CONFILE=$BASEDIR/conf/zabbix_agentd.conf //添加此行##搜索start,修改启动选项,默认是去/etc下去找配置文件action $"Starting $BINARY_NAME: " $FULLPATH -c $CONFILE

 

5.4 脚本传送到被监控的客户端

cd /usr/local/src/zabbix-2.4.4/misc/init.d/fedora/corescp zabbix_agentd root@192.168.0.23:/etc/init.d/

 

5.5 启动Zabbix Agentd服务

groupadd zabbixuseradd zabbix -g zabbix -s /sbin/nologin/usr/local/zabbix_agents/sbin/zabbix_agentd -c /usr/local/zabbix_agents/conf/zabbix_agentd.conf

 

修改过程

sed -i s/172.16.16.51/10.0.0.29/g /usr/local/zabbix_agents/conf/zabbix_agentd.conf/usr/local/zabbix_agents/sbin/zabbix_agentd -c /usr/local/zabbix_agents/conf/zabbix_agentd.conf

Zabbix3.0完整部署