用zabbix监控服务器2年多了,早就写好了服务器端的安装部署脚本,现在拿出来和大家分享一下。zabbix1.8和2.0版本通用的安装脚本,默认的为1.8.9的版本,大家要是想安装2.0以上的版本,只用替换zabbix的安装包即可,其他的不变。安装所用到的软件包在:http://down.51cto.com/data/556418这个位置,大家可以下载,也可以根据脚本中用到的软件自行去下载。安装之后打开浏览器:http://192.168.8.11/zabbix进行zabbix的初始化,基本就是检测运行环境之类的,点击下一步即可完成,如果有错误的话他会提示,按照提示修改配置即可。脚本如下:
- #/bin/sh
- mkdir -p /home/soft
- unzip zabbix.zip -d /home/soft/
- cd /home/soft/
- tar -zxf libpng-1.2.16.tar.gz
- cd libpng-1.2.16/
- ./configure --prefix=/usr/local --enable-shared
- make && make install
- cd /home/soft/
- tar -zxf libiconv-1.11.tar.gz
- cd libiconv-1.11/
- ./configure --prefix=/usr/local --enable-shared --enable-static
- make && make install
- cd /home/soft/
- tar -zxf jpegsrc.v6b.tar.gz
- cd jpeg-6b/
- ./configure --enable-static --enable-shared --prefix=/usr/local
- make && make install
- cd /home/soft/
- tar -zxf freetype-2.3.1.tar.gz
- cd freetype-2.3.1/
- ./configure --prefix=/usr/local --enable-shared
- make && make install
- cd /home/soft/
- tar -zxf curl-7.17.1.tar.gz
- cd curl-7.17.1/
- ./configure --prefix=/usr/local --enable-shared
- make && make install
- cd /home/soft/
- tar -zxf gd-2.0.34.tar.gz
- cd gd-2.0.34/
- ./configure --prefix=/usr/local --enable-shared --with-png=/usr/local --with-freetype=/usr/local --with-libiconv-prefix=/usr/local --with-jpeg=/usr/local
- make && make install
- cd /home/soft/
- tar -zxf httpd-2.2.21.tar.gz
- cd httpd-2.2.21/
- ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-deflate --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-ssl --with-ssl=/usr/include/openssl --enable-mods-shared=all
- make && make install
- groupadd apache
- useradd -g apache apache
- cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
- chmod 755 /etc/rc.d/init.d/httpd
- echo '# chkconfig: 2345 85 15' >> /etc/rc.d/init.d/httpd
- mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
- cp /home/soft/httpd.conf /usr/local/apache/conf/httpd.conf
- echo '# description: httpd is a World Wide Web Server' >> /etc/rc.d/init.d/httpd
- chkconfig --add httpd
- chkconfig httpd on
- echo "127.0.0.1 `hostname`">>/etc/hosts
- service httpd restart
- cd /home/soft/
- groupadd mysql
- useradd -g mysql mysql
- mv /home/mysql /data1/
- ln -s /data1/mysql /home/mysql
- tar -zxf mysql-5.1.59-linux-i686-glibc23.tar.gz -C /usr/local/
- mv /usr/local/mysql-5.1.59-linux-i686-glibc23/ /usr/local/mysql/
- mkdir -p /usr/local/mysql/etc/
- chown -R mysql.mysql /usr/local/mysql
- cd /usr/local/mysql/
- ./scripts/mysql_install_db --no-defaults
- cd /home/soft/
- cp -rp /usr/local/mysql/data/mysql /data1/mysql/data/
- chown -R mysql.mysql /data1/mysql
- mkdir -p /usr/lib/mysql/
- ln -s /usr/local/mysql/lib/* /usr/lib/mysql/
- ln -s /usr/local/mysql/bin/* /usr/bin/
- echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
- ldconfig
- cp /home/soft/mysqld /etc/init.d/
- chmod +x /etc/init.d/mysqld
- chkconfig --add mysqld
- chkconfig --level 345 mysqld on
- service mysqld start
- mysqladmin -uroot password zabbix
- mysql -pzabbix -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'zabbix';update mysql.user set password=password('zabbix') where user='root';flush privileges;"
- #mysql -pzabbix -e "UPDATE zabbix.items SET history=7;"
- #这条语句在安装结束后导入监控模板后手动执行,用于修改监控数据保存天数的修改。
- #如果需要用snmp来监控的话,需要加上snmp软件,自己指定yum源进行安装
- #echo "baseurl=ftp://10.14.23.235/snmp">> /etc/yum.repos.d/as.repo
- #yum install net-snmp-devel -y
- cd /home/soft/
- tar -zxf php-5.2.17.tar.gz
- ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
- ln -s /usr/local/lib/libcurl.so.4 /usr/lib/libcurl.so.4
- cd /home/soft/php-5.2.17/;
- ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-ttf --with-freetype-dir=/usr/local --with-iconv-dir=/usr/local --with-curl=/usr/local --with-zlib --with-gettext --with-libxml-dir=/usr/local --with-gd=/usr/local --with-png-dir --enable-mbstring --enable-exif --enable-force-cgi-redirect --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-calendar --enable-gd-native-ttf --enable-gd-jis-conv --disable-debug --disable-path-info-check --enable-soap --silent --enable-sockets --with-openssl --enable-bcmath --with-gettext --with-jpeg-dir=/usr/local
- #用到snmp的话加上 --with-snmp
- #--enable-bcmath --with-gettext还有GD的 注意这几个参数一定要加上,特别是zabbix2.0以上版本需要
- make && make install
- mkdir -p /usr/local/php/etc
- cp /home/soft/php.ini /usr/local/php/etc/
- cd /home/soft/
- tar -zxf zabbix-1.8.9.tar.gz
- cd zabbix-1.8.9
- ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-libcurl && make && make install
- #用到snmp的话加上--with-net-snmp 用到代理的话加上 --enable-proxy
- mkdir -p /etc/zabbix
- cp /home/soft/zabbix_* /etc/zabbix/
- #110行和111行在2.0以上的版本中不需要,因为zabbix默认安装的配置文件在/usr/local/zabbix/etc/下面,只需修改相关数据库连接信息即可
- cd /home/soft/
- groupadd zabbix
- useradd zabbix -g zabbix
- mysql -uroot -pzabbix -e "create database zabbix character set utf8;"
- cd /home/soft/zabbix-1.8.9/
- mysql -uroot -pzabbix zabbix < create/schema/mysql.sql
- mysql -uroot -pzabbix zabbix < create/data/data.sql
- mysql -uroot -pzabbix zabbix < create/data/images_mysql.sql
- #zabbix2.0以上版本导入数据库时有先后顺序,并且数据库文件的名字也有变化,请按照一下顺序来导入
- #mysql -uroot -pzabbix zabbix < create/schema/schema.sql
- #mysql -uroot -pzabbix zabbix < create/data/images.sql
- #mysql -uroot -pzabbix zabbix < create/data/data.sql
- cp -r /home/soft/zabbix-1.8.9/frontends/php /usr/local/apache/htdocs/zabbix
- cp /home/soft/zabbix-server /etc/init.d/zabbix-server
- cp /home/soft/zabbix-agentd /etc/init.d/zabbix-agentd
- chmod +x /etc/init.d/zabbix*
- chkconfig --add zabbix-agentd
- chkconfig --add zabbix-server
- chkconfig --level 345 zabbix-server on
- chkconfig --level 345 zabbix-agentd on
- cp /home/soft/simhei.ttf /usr/local/apache/htdocs/zabbix/fonts/
- sed -i 's/DejaVuSans/simhei/g' /usr/local/apache/htdocs/zabbix/include/defines.inc.php
- #在页面选择中文时用这个字体替换掉之前的字体,这样可以汉化图标中的中文。
- 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
zabbix客户端的安装比较简单:
1:linux系统
下载zabbix软件包,解压zabbix软件包:
cd /home/soft/zabbix-1.8.11/ ./configure --prefix=/usr/local/zabbix --enable-agent && make && make install
在http://down.51cto.com/data/556418这个位置有他的配置文件和服务文件的模板,是我修改过的,可以直接使用。
/usr/sbin/groupadd zabbix
/usr/sbin/useradd zabbix -g zabbix
/sbin/chkconfig --add zabbix-agentd
/sbin/chkconfig --level 345 zabbix-agentd on
echo "zabbix-agent 10050/tcp #Zabbix Agent">>/etc/services
echo "zabbix-agent 10050/udp #Zabbix Agent">>/etc/services
/etc/init.d/zabbix-agentd restart
2:windows端的安装:
下载zabbix的windows软件包,解压zabbix软件包,windows端的配置文件和linux一样,执行下面的安装zabbix为服务:
C:\zabbix\zabbix_agentd.exe -c C:\zabbix\zabbix_agentd.conf -i
net start "Zabbix Agent"
@pause
本文转自 lover00751CTO博客,原文链接:http://blog.51cto.com/wangwei007/1033847,如需转载请自行联系原作者