一、ZABBIX准备环境
1.安装ngnixmkdir /usr/local/nginx
tar xzvf nginx-1.7.9.tar.gz
./configure --prefix=/usr/local/nginx
make
make install
遇到问题yum -y install openssl openssl-devel
yum -y install pcre-devel
判断Nginx配置是否正确命令如下:nginx -t -c /usr/local/nginx/conf/nginx.conf
启动/usr/local/nginx/sbin/nginx
平滑重启/usr/local/nginx/sbin/nginx -s reload
停止操作
步骤1:查询nginx主进程号ps -ef | grep nginx
在进程列表里 面找master进程,它的编号就是主进程号了。
验证安装是否成功
输入安装地址查看
2.安装php环境
安装tar xzvf php-5.6.4.tar.gz
cd php-5.6.4
./configure --enable-fpm
make&&make install
验证PHP是否安装成功php -v
显示版本就是安装成功了
创建php.ini文件cp php.ini-production /usr/local/lib/php.ini
echo ‘extension=mbstring.so' >>/usr/local/lib/php.ini
添加nginx支持phplocation ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
修改后平滑重启nginx/usr/local/nginx/sbin/nginx -s reload
创建配置文件cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
修改配置文件;pid = run/php-fpm.pid
启动和停止 php-fpm
# 启动/usr/local/sbin/php-fpm
# 停止kill `cat /usr/local/var/run/php-fpm.pid`
3.安装mysql
卸载本机自带的版本rpm -qa | grep mysql
显示如下:mysql-5.0.77-3.el5
php-mysql-5.1.6-23.2.el5_3
mysql-devel-5.0.77-3.el5
libdbi-dbd-mysql-0.8.1a-1.2.2
mysql-5.0.77-3.el5
mysql-devel-5.0.77-3.el5
mysql-bench-5.0.77-3.el5
mod_auth_mysql-3.0.0-3.2.el5_3
mysql-server-5.0.77-3.el5
mysql-connector-odbc-3.51.26r1127-1.el5
删除相关文件rm -f /etc/my.cnf
rm -rf /var/lib/mysql
安装新版MySQL
服务端rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm
安装成功后有提示随机密码A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'.
客户端rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
启动mysql服务cd /etc/rc.d/init.d
service mysql start
显示:Starting MySQL. [确定]
查看或编辑vi /root/.mysql_secret
获取随机密码IL8Woo26zIaRKWGt
第一次随机密码登陆后必须修改root密码SET PASSWORD = PASSWORD('123456');
创建zabbix所需数据库
(1)创建数据库create database zabbix character set utf8;
(2)创建用户CREATE USER 'zabbix'@'localhost' IDENTIFIED BY "liuyu33@6a+";
(3)授权grant all on zabbix.* to 'zabbix'@'localhost' identified by 'liuyu33@6a+' with grant option;
(4)刷新系统授权flush privileges;
导入数据表use zabbix;
source /usr/src/zabbix-2.2.6/database/mysql/schema.sql
source /usr/src/zabbix-2.2.6/database/mysql/images.sql
source /usr/src/zabbix-2.2.6/database/mysql/data.sql
二、服务端安装ZABIXX
创建用户和用户组groupadd zabbix
useradd -g zabbix zabbix
安装依赖包yum install net-snmp-devel curl curl-devel mysql-devel
创建安装目标目录/usr/local/zabbixmkdir /usr/local/zabbix
授权目录chown -R zabbix.zabbix /usr/local/zabbix
进入解压目录,安装如下:./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql
=/usr/local/mysql/bin/mysql_config
遇到的问题
安装过程中可能会出现Not found mysqlclient library
解决办法:cp /usr/local/mysql/lib/mysql/libmysqlclient.so.16.0.0 /usr/lib64/libmysqlclient.so.16
cp /usr/local/mysql/lib/mysql/libmysqlclient_r.so.16.0.0 /usr/lib64/libmysqlclient_r.so.16
ln -s /usr/lib64/libmysqlclient.so.16 /usr/lib64/mysql/libmysqlclient.so
ln -s /usr/lib64/libmysqlclient.so.16 /usr/lib64/mysql/libmysqlclient.so
snmp报错Invalid Net-SNMP directory - unable to find net-snmp-config
解决办法:yum -y install net-snmp-devel
编译后出现***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <
http://www.zabbix.com
> *
***********************************************************
说明编译成功了make insatll
添加zabbix服务对应的端口,编辑vi /etc/services
在最后添加以下代码# Zabbix
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
修改zabbix配置文件cd /usr/local/zabbix/etc
vi zabbix_server.conf
具体参数如下:DBName=zabbix #数据库名称
DBUser=zabbix #数据库用户名
DBPassword=123456 #数据库密码
DBSocket=/temp/mysql.sock
DBPort=3306 #数据库端口
ListenIP=127.0.0.1 #数据库ip地址
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录
添加开机自启动脚本
服务端cp /usr/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
客户端cp /usr/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_server #添加脚本执行权限
chmod +x /etc/rc.d/init.d/zabbix_agentd #添加脚本执行权限
chkconfig zabbix_server on #添加开机启动
chkconfig zabbix_agentd on #添加开机启动
修改zabbix开机启动脚本中的zabbix安装目录vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件
添加一行:BASEDIR=/usr/local/zabbix/ #zabbix安装目录
编辑客户端配置文件vi /etc/rc.d/init.d/zabbix_agentd
添加一行:BASEDIR=/usr/local/zabbix/
配置web站点cd /usr/src/zabbix-2.2.6
cp -r /usr/src/zabbix-2.2.6/frontends/php /usr/local/nginx/html/zabbix /home/wwwroot/default
chown nobody.nobody -R /usr/local/nginx/html/zabbix
service zabbix_server start
service zabbix_agentd start
修改php配置文件参数,编辑vi /etc/php.ini
添加以下行:post_max_size =16M
max_execution_time =300
max_input_time =300
编辑php-fpm.confvi /usr/local/php/etc/php-fpm.conf
添加一行:request_terminate_timeout = 300
修改配置以中文支持vi /usr/local/nginx/html/zabbix/include/locales.inc.php
如下所示:'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => true),
改变字体
替换监控图像上系统默认的字体 #默认字体不支持中文,如果不替换,图像上会显示乱码
在Windows系统中的C:/Windows/Fonts目录中复制出一个中文字体文件,例如 简体.ttf
把字体文件 简体.ttf上传到zabbix站点根目录下fonts文件夹中
备份默认的字体文件:DejaVusSans.ttf-bak
修改简体.ttf名称为DejaVusSans.ttf
登陆后选择Profile中的chinese保存。
三、监控端安装
开放防火墙端口vi /etc/sysconfig/iptables
添加以下几行:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT
重启服务service iptables restart
设置SELINUXvi /etc/selinux/config
禁用selinux,将SELINUX=disabled,或临时执行
setenforce 0
上传软件包/usr/src
添加用户组和用户groupadd zabbix
useradd -g zabbix zabbix
创建安装目录并授权mkdir /usr/local/zabbix
授权目录chown -R zabbix.zabbix /usr/local/zabbix
安装Zabbixln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
使配置立即生效/sbin/ldconfig
编译安装cd /usr/src
tar zxvf zabbix-2.2.6.tar.gz
cd zabbix-2.2.6
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/
yum install apr* autoconf automake bison cloog-ppl compat* cpp fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng* libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* libX* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* nasm nasm* wget zlib-devel
添加zabbix服务对应的端口echo 'zabbix-agent 10050/tcp #Zabbix Agent' >> /etc/services
echo 'zabbix-agent 10050/udp #Zabbix Agent' >> /etc/services
echo 'zabbix-trapper 10051/tcp #Zabbix trapper' >> /etc/services
echo 'zabbix-trapper 10051/udp #Zabbix trapper' >> /etc/services
或者vi /etc/services
# Zabbixzabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
修改zabbix_agentd配置文件vi /usr/local/zabbix/etc/zabbix_agentd.conf
修改为:Server=10.5.61.159
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1 #启用自定义key
添加开机启动脚本cp /usr/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
vi /etc/rc.d/init.d/zabbix_agentd #编辑
修改为:BASEDIR=/usr/local/zabbix/ #Zabbix安装目录
执行以下命令,检查Zabbix客户端是否正常运行:chmod +x /etc/rc.d/init.d/zabbix_agentd
chkconfig zabbix_agentd on
service zabbix_agentd start
ps ax|grep zabbix_agentd
netstat -utlnp | grep zabbix #
测试客户端与服务端通信/usr/local/zabbix/bin/zabbix_get -s10.5.61.163 -p10050 -k"system.uptime"