yum -y remove php php-bcmath php-cli php-common php-devel php-fpm php-gd php-imap php-ldap php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-pear php-pecl-igbinary php-xml php-xmlrpc
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

yum -y install php55w php55w-bcmath php55w-cli php55w-common php55w-devel php55w-fpm php55w-gd php55w-imap php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql php55w-odbc php55w-pdo php55w-pear php55w-pecl-igbinary php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache

yum -y install net-snmp-devel OpenIPMI-devel

groupadd zabbix
useradd zabbix -g zabbix -s /sbin/nologin

wget -c http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.3/zabbix-3.4.3.tar.gz
tar zxf zabbix-3.4.3.tar.gz
cd zabbix-3.4.3
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc

make install

service mysqld start;
mysql -e "create database zabbix character set utf8;"
mysql -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';flush privileges;"

mysql -uroot zabbix < database/mysql/schema.sql
mysql -uroot zabbix < database/mysql/images.sql
mysql -uroot zabbix < database/mysql/data.sql

sed -i 's/^DBUser=.$/DBUser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/^.
DBPassword=.$/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbixserver.conf
cp -r frontends/php /var/www/html/zabbix
cp misc/init.d/fedora/core/zabbix
/etc/init.d/
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_server
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd

cat >>/etc/services <zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper
EOF

sed -i 's/^register_globals = Off$/register_globals = On/g' /etc/services

cat >>/etc/php.ini <date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
EOF

cat >>/etc/httpd/conf/httpd.conf <ServerName 127.0.0.1

DocumentRoot "/var/www/html"
ServerName zabbix_server

EOF

cat >/var/www/html/zabbix/conf/zabbix.conf.php <// Zabbix GUI configuration file
global \$DB;

\$DB['TYPE'] = 'MYSQL';
\$DB['SERVER'] = 'localhost';
\$DB['PORT'] = '0';
\$DB['DATABASE'] = 'zabbix';
\$DB['USER'] = 'zabbix';
\$DB['PASSWORD'] = 'zabbix';

// SCHEMA is relevant only for IBM_DB2 database
\$DB['SCHEMA'] = '';

\$ZBX_SERVER = 'localhost';
\$ZBX_SERVER_PORT = '10051';
\$ZBX_SERVER_NAME = '';

\$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
EOF

service iptables stop
chkconfig --level 345 iptables off
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
echo "/etc/init.d/zabbix_server start" >> /etc/rc.local
echo "/etc/init.d/zabbix_agentd start" >> /etc/rc.local
chkconfig --level 345 mysqld on
chkconfig --level 345 httpd on

/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
/etc/init.d/httpd start