#!/bin/bash
#
#########################环境准备阶段###################
#1、关闭防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
service iptables stop
chkconfig iptables off
#2、部署LAMP环境(这个脚本可以参照:测试环境LAMP用YUM快速部署这篇文章)
./yum_lamp_install.sh
#################安装Zabbix Server管理端###################
#1、安装依赖包
yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI
#2、创建zabbix组,并创建zabbix用户加入zabbix组
groupadd zabbix
useradd zabbix -g zabbix
#3、获取zabbix-2.2.0.tar.gz包,并解压
mkdir -p /data/source
cd /data/source
tar zxvf zabbix-2.2.0.tar.gz
#4、创建zabbix数据库,并授权
mysql -uroot -pkundylee -e"create database zabbix character set utf8;"
mysql -uroot -pkundylee -e"grant all privileges on zabbix.* TO zabbix@'localhost' identified by 'zabbix';"
mysql -uroot -pkundylee -e"flush privileges;"
#5、导入数据库sql
cd zabbix-2.2.0/database/mysql/
mysql -uroot -pkundylee zabbix mysql -uroot -pkundylee zabbix mysql -uroot -pkundylee zabbix #6、编译安装zabbix_server和zabbix_angetd cd ../.. ./configure --prefix=/data/soft/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy make && make install #7、修改zabbix_server.conf配置参数 cd /data/soft/zabbix/etc/ vim zabbix_server.conf DBName=zabbix DBUser=zabbix DBPassword=zabbix #8、创建自启动脚本 /data/source/zabbix-2.2.0 cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/ cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/ sed -i 's@ZABBIX_BIN="/usr/local/sbin/zabbix_server"@ZABBIX_BIN="/data/soft/zabbix/sbin/zabbix_server"@' /etc/init.d/zabbix_server sed -i 's@ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"@ZABBIX_BIN="/data/soft/zabbix/sbin/zabbix_agentd"@' /etc/init.d/zabbix_agentd chmod 755 /etc/init.d/zabbix_* chown zabbix:zabbix /etc/init.d/zabbix_server chown zabbix:zabbix /etc/init.d/zabbix_agentd #9、启动服务并设置开机启动 /etc/init.d/zabbix_server start /etc/init.d/zabbix_agentd start chkconfig zabbix_server on chkconfig zabbix_agentd on #10、修改php相关参数 vi /etc/php.ini date.timezone = Asia/Shanghai max_execution_time = 300 max_input_time = 300 memory_limit = 128M post_max_size = 32M mbstring.func_overload = 2 #11、重启httpd /etc/init.d/httpd restart #12、配置php文件 cd zabbix-2.0.6/frontends/ cp -rf php /var/www/html/ cd /var/www/html mv php zabbix chown -R zabbix:zabbix zabbix #13、开始部署zabbix # http://IP/zabbix #14、修改conf目录的zabbix.conf.php配置文件的密码为zabbix cd /var/www/html/zabbix/conf/ mv zabbix.conf.php.example zabbix.conf.php vim zabbix.conf.php $DB["TYPE"] = 'MYSQL'; $DB["SERVER"] = 'localhost'; $DB["PORT"] = '0'; $DB["DATABASE"] = 'zabbix'; $DB["USER"] = 'zabbix'; $DB["PASSWORD"] = 'zabbix'; #15、输入管理用户名:admin 默认口令 zabbix 登陆 #16、Zabbix 中文汉化及出现乱码解决办法 cd /data/source/ wget http://down1.chinaunix.net/distfiles/ttf-arphic-uming_0.0.20050501-1.tar.gz tar zxvf ttf-arphic-uming_0.0.20050501-1.tar.gz cd ttf-arphic-uming-0.0.20050501/ mv /var/www/html/zabbix/fonts/DejaVusans.ttf /var/www/html/zabbix/fonts/DejaVusans.ttf.bak cp uming.ttf /var/www/html/zabbix/fonts/ #17、修改zabbix页面管理的中文字体设置,刷新页面 vim /var/www/html/zabbix/include/defines.inc.php define('ZBX_FONT_NAME', 'uming'); define('ZBX_GRAPH_FONT_NAME', 'uming'); #################安装zabbix agentd客户端################### #1、安装依赖包 yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI #2、创建zabbix组,并创建zabbix用户加入zabbix组 groupadd zabbix useradd zabbix -g zabbix #3、获取zabbix-2.2.0.tar.gz包,并解压 cd /data/source tar zxvf zabbix-2.2.0.tar.gz #4、编译安装zabbix_angetd cd zabbix-2.2.0 ./configure --prefix=/data/soft/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-agent --enable-proxy make && make install #5、修改zabbix_agentd.conf配置参数(IP地址根据实际环境自行修改为管理端ip) cd /data/soft/zabbix/etc/ vim zabbix_agentd.conf Server=192.168.10.151 ServerActive=192.168.10.151 Hostname=192.168.10.152 #6、创建自启动脚本 /data/source/zabbix-2.2.0 cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/ sed -i 's@ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"@ZABBIX_BIN="/data/soft/zabbix/sbin/zabbix_agentd"@' /etc/init.d/zabbix_agentd chmod 755 /etc/init.d/zabbix_* chown zabbix:zabbix /etc/init.d/zabbix_agentd #7、启动服务并设置开机启动 /etc/init.d/zabbix_agentd start chkconfig zabbix_agentd on ##########在管理端测试客户端是否正常通信,有数据显示说明通信正常######### /data/soft/zabbix/bin/zabbix_get -s 192.168.10.152 -p 10050 -k"system.uptime"