zabbix監控搭建腳本
#!/bin/bash www.2cto.com
#1.0 安裝zabbix依懶包
yum install -y httpd php mysql mysql-server gcc* php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel > /dev/null
#1.1 加載php
cat << ok >> /etc/httpd/conf/httpd.conf
DirectoryIndex index.php
ok
#1.2 開機啟動web服務和數據庫服務
/etc/init.d/httpd restart
chkconfig httpd on
/etc/init.d/mysqld restart
chkconfig mysqld on
#1.3 給數據庫設置密碼
mysqladmin -uroot -password'anfenghu'
#1.4 測試php,apache,mysql連接情況
cat << ceshi >> /var/www/html/index.php
it works!
<?php
$link=mysql_connect('localhost','root','redhat');
if($link)
echo "success";
else
echo "fail";
?>
測試成功
ceshi
#2.0 開始安裝zabbix
#2.1 首先建立zabbix用戶與組
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
tar -zxvf /root/zabbix-2.0.3.tar.gz -C /usr/src
cd /usr/src/zabbix-2.0.3
#2.2 為zabbix創建數據庫並添加用戶
/etc/init.d/mysqld restart
mysql -uroot -p'anfenghu'
create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by 'redhat';
flush privileges;
exit
#2.3 將zabbix源碼包中的數據導入到新建的zabbix數據庫
mysql -uzabbix -p'anfenghu' zabbix < /usr/src/zabbix-2.0.3/database/mysql/schema.sql
mysql -uzabbix -p'anfenghu' zabbix < /usr/src/zabbix-2.0.3/database/mysql/images.sql
mysql -uzabbix -p'anfenghu' zabbix < /usr/src/zabbix-2.0.3/database/mysql/data.sql
#創建zabbix的安裝目錄並初始化zabbix
mkdir /usr/local/zabbix
/usr/src/zabbix-2.0.3/configure --prefix=/usr/local/zabix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl
make > /dev/null
make install > /dev/null
ln -s /usr/local/zabbix/etc /etc/zabbix
#2.4 更改配置文件中數據庫相關的用戶名密碼
sed -i 's/DBName=/DBName=zabbix/g'/etc/zabbix/zabbix_server.conf
sed -i 's/DBUser=/DBUser=zabbix/g'/etc/zabbix/zabbix_server.conf
sed -i 's/#DBPassword=/DBPassword=anfenghu/g'/etc/zabbix/zabbix_server.conf
zjm=hostname
sed -i 's/Hostname=/Hostname=$zjm/g' /etc/zabbix/zabbix_agentd.conf
ip=ifconfig | head -2 | awk -F":" '{print $2}'| awk -F" " '{print $1}'| tail -1
sed -i 's/ServerActive=/ServerActive=$ip/' /etc/zabbix/zabbix_agentd.conf
#2.5 給zabbix服務端程序做軟鏈接
for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done
#2.6 添加數據庫Lib文件位置到/etc/ld.so.conf中,並使其生效
echo "/usr/local/mysql-5.1.48/lib/mysql/" >> /etc/ld.so.conf
ldconfig
#2.7 拷貝相應的web程序到相關WEB服務目錄下
cp -r /usr/src/zabbix-2.0.3/frontends/php/ /var/www/html/zabbix/
chown -R zabbix.zabbix /var/www/html/zabbix
#2.8 拷貝zabbix的啟動腳步到/etc/init.d/
cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_server /etc/init.d
cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d
#2.9 修改啟動腳本
sed -i 's/ZABBIX_BIN="/usr/local/sbin/zabbix_server"/ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"/g' /etc/init.d/zabbix_server
/etc/init.d/zabbix_server restart
sed -i 's/ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"/ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"/g' /etc/init.d/zabbix_agentd
/etc/init.d/zabbix_agentd restart
chkconfig zabbix_server on
chkconfig zabbix_agentd on
sed -i 's/date.timezone =/date.timezone =Asia/Shanghai/' /etc/php.ini
sed -i 's/post_max_size =/post_max_size =32M/' /etc/php.ini
sed -i 's/max_execution_time =/max_execution_time =300/' /etc/php.ini
sed -i 's/max_input_time =/max_input_time =300/' /etc/php.ini
sed -i 's/memory_limit =/memory_limit =128M/' /etc/php.ini
sed -i 's/mbstring.func_overload =/mbstring.func_overload =2/' /etc/php.ini
/etc/init.d/httpd restart
chkconfig httpd on