#!/bin/bash

#

 

#配置yum

d1=/etc/yum.repos.d/rhel.repo

rm -rf /etc/yum.repos.d/*

touch /etc/yum.repos.d/rhel.repo

mount /dev/sr0 /mnt

echo "[localyumserver]" > /etc/yum.repos.d/rhel.repo

sed -i '$a\name=abc' $d1

sed -i '$a\baseurl=file:///mnt' $d1

sed -i '$a\enabled=1' $d1

sed -i '$a\gpgcheck=0' $d1

yum clean all

yum makecache

 

#安装必须的软件并且注意所有软件需要放至/root下面

 

d=/root/zabbix-2.4.4

cd

tar xvf zabbix-2.4.4.tar.gz

rpm -ivh php-bcmath-5.3.3-22.el6.x86_64.rpm

rpm -ivh php-mbstring-5.3.3-22.el6.x86_64.rpm

yum -y install gcc gcc-c++ autoconf httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-ldap php-pear php-xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp net-snmp-devel curl-devel

 

service httpd start

service mysqld start

chkconfig httpd on

chkconfig mysqld on

 

iptables -I INPUT -p tcp -m multiport --destination-port 80,10050:10051 -j ACCEPT

service iptables save

 

hip=`ifconfig eth0 | grep "inet addr:" | cut -d : -f2 | cut -d " " -f1`

sed -i "s@max_execution_time = 30@max_execution_time = 300@g" /etc/php.ini

sed -i "s@post_max_size = 8M@post_max_size = 32M@g" /etc/php.ini

sed -i "s@max_input_time = 60@max_input_time = 300@g" /etc/php.ini

sed -i "s@;mbstring.func_overload = 0@mbstring.func_overload = 0@g" /etc/php.ini

echo "ServerName $hip:80" >> /etc/httpd/conf/httpd.conf

/etc/init.d/httpd restart

 

groupadd zabbix -g 201

useradd -g zabbix -u 201 -m zabbix

tar xvf zabbix-2.4.4.tar.gz

cd $d

./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl

make

make install

mysql -e "create database zabbix default charset utf8;"

mysql -e "grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';"

mysql -e "grant all on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix';"

mysql -e "grant all on zabbix.* to zabbix@'%' identified by 'zabbix';"

mysql -uzabbix -pzabbix zabbix < /root/zabbix-2.4.4/database/mysql/schema.sql

mysql -uzabbix -pzabbix zabbix < /root/zabbix-2.4.4/database/mysql/images.sql

mysql -uzabbix -pzabbix zabbix < /root/zabbix-2.4.4/database/mysql/data.sql

 

#配置软链接和启动文件信息

mkdir /var/log/zabbix

chown zabbix.zabbix /var/log/zabbix

ln -s /usr/local/zabbix/etc/ /etc/zabbix

ln -s /usr/local/zabbix/bin/* /usr/bin/

ln -s /usr/local/zabbix/sbin/* /usr/sbin/

 

cp /root/zabbix-2.4.4/misc/init.d/fedora/core/zabbix_* /etc/init.d

chmod 755 /etc/init.d/zabbix_*

 

#修改/etc/init.d目录下的zabbix_serverzabbix_agentd 启动文件

sed -i 's@BASEDIR=/usr/local@BASEDIR=/usr/local/zabbix@g' /etc/init.d/zabbix_*

 

# 修改zabbix——server.conf

sed -i 's@LogFile=/tmp/zabbix_server.log@LogFile=/var/log/zabbix/zabbix_server.log@g' /etc/zabbix/zabbix_server.conf

sed -i 's@DBUser=root@DBUser=zabbix@g' /etc/zabbix/zabbix_server.conf

sed -i 's@# DBPassword=@DBPassword=zabbix@g' /etc/zabbix/zabbix_server.conf

 

# 修改/etc/zabbix/zabbix_agentd.conf,这里的ip地址写的是zabbix_serverip

sed -i "s@Server=127.0.0.1@Server=127.0.0.1,$hip@g" /etc/zabbix/zabbix_agentd.conf

sed -i "s@ServerActive=127.0.0.1@ServerActive=$hip:10051@g" /etc/zabbix/zabbix_agentd.conf

sed -i "s@/tmp/zabbix_agentd.log@/var/log/zabbix/zabbix_agentd.log@g" /etc/zabbix/zabbix_agentd.conf

sed -i "s@# UnsafeUserParameters=0@UnsafeUserParameters=0@g" /etc/zabbix/zabbix_agentd.conf

 

mkdir /var/www/html/zabbix/

cp -r $d/frontends/php/* /var/www/html/zabbix/

chown -R apache.apache /var/www/html/zabbix/

 

chkconfig zabbix_server on

chkconfig zabbix_agentd on

service zabbix_server start

service zabbix_agentd start