脚本说明:
1、基于cent7.5最小化安装 2、修改php配置文件,以符合zabbix配置要求 3、zabbix网页文件目录配置为apache默认目录
#!/bin/bash
#====================================================
# Author: Mr.Song
# Create Date: 2018-12-18
# Description:auto install zabbix 4.0.2
# OS :Cent 7.5
#====================================================
ZABBIX_SOFT="zabbix-4.0.2.tar.gz"
ZABBIX_SERVER="192.168.10.11"
INSTALL_DIR="/usr/local/zabbix"
ZABBIX_WEB_DIR="/var/www/html/zabbix/"
function SERVER_INSTALL()
{
yum install -y gcc wget curl curl-devel net-snmp net-snmp-devel perl-DBI libevent-devel php php-cli php-common php-gd php-ldap php-mbstring php-mcrypt php-mysql php-bcmath php-pdo php-xml mariadb mariadb-server mariadb-devel httpd httpd-devel httpd-tools
groupadd zabbix ;useradd -g zabbix zabbix -s /sbin/nologin
sed -i '/post_max_size/s/8/16/;/max_execution_time/s/30/300/;/max_input_time/s/60/300/;/;date.timezone/s#;date.timezone =#date.timezone = PRC#' /etc/php.ini
wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz/download -O $ZABBIX_SOFT
tar zxf $ZABBIX_SOFT
cd `echo $ZABBIX_SOFT |sed 's/.tar.*//g'`
./configure --prefix=$INSTALL_DIR --enable-server --enable-agent --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl && make install
if [ $? -eq 0 ];then
ln -s $INSTALL_DIR/sbin/zabbix_* /usr/local/sbin/
else
echo "Compile error,please check .exiting now..."
exit 1
fi
cp misc/init.d/tru64/zabbix_* /etc/init.d/
chmod o+x /etc/init.d/zabbix_*
sed -i 's#DAEMON=/usr/local/sbin/zabbix_server#DAEMON=/usr/local/zabbix/sbin/zabbix_server#' /etc/init.d/zabbix_server
sed -i 's#DAEMON=/usr/local/sbin/zabbix_agentd#DAEMON=/usr/local/zabbix//sbin/zabbix_agentd#' /etc/init.d/zabbix_agentd
systemctl start mariadb
mysql -e "create database zabbix charset=utf8;"
mysql -e "grant all on zabbix.* to zabbix@localhost identified by '111111';"
mysql -e "flush privileges;"
mysql -uzabbix -p111111 zabbix < database/mysql/schema.sql
mysql -uzabbix -p111111 zabbix < database/mysql/images.sql
mysql -uzabbix -p111111 zabbix < database/mysql/data.sql
mkdir $ZABBIX_WEB_DIR
cp -r frontends/php/* $ZABBIX_WEB_DIR
systemctl start httpd
cp $INSTALL_DIR/etc/zabbix_agentd.conf $INSTALL_DIR/etc/zabbix_agentd.conf.bak
cp $INSTALL_DIR/etc/zabbix_server.conf $INSTALL_DIR/etc/zabbix_server.conf.bak
cat > $INSTALL_DIR/etc/zabbix_server.conf<<-EOF
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=111111
EOF
for i in `hostname -i`
do
echo $i |egrep '[a-z]|192.168.122' 2>&1 >/dev/null
if [ $? -eq 1 ];then
IP=${i}
fi
done
cat > $INSTALL_DIR/etc/zabbix_agentd.conf<<-EOF
LogFile=/tmp/zabbix_agentd.log
Server=$ZABBIX_SERVER
ServerActive=$ZABBIX_SERVER
Hostname=$IP
EOF
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
setenforce 0
}
function AGENT_INSTALL()
{
yum install -y gcc wget pcre-devel
groupadd zabbix ;useradd -g zabbix zabbix -s /sbin/nologin
wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz/download -O $ZABBIX_SOFT
tar zxf $ZABBIX_SOFT
cd `echo $ZABBIX_SOFT |sed 's/.tar.*//g'`
./configure --prefix=$INSTALL_DIR --enable-agent &&make install
if [ $? -eq 0 ];then
ln -s $INSTALL_DIR/sbin/zabbix_* /usr/local/sbin/
else
echo "Compile error,please check .exiting now..."
exit 1
fi
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_*
cp $INSTALL_DIR/etc/zabbix_agentd.conf $INSTALL_DIR/etc/zabbix_agentd.conf.bak
for i in `hostname -i`
do
echo $i |egrep '[a-z]|192.168.122' 2>&1 >/dev/null
if [ $? -eq 1 ];then
IP=${i}
fi
done
cat > $INSTALL_DIR/etc/zabbix_agentd.conf<<-EOF
LogFile=/tmp/zabbix_agentd.log
Server=$ZABBIX_SERVER
ServerActive=$ZABBIX_SERVER
Hostname=$IP
EOF
/etc/init.d/zabbix_agentd start
setenforce 0
}
read -p "Plesse confirm whether to install Zabbix Server,yes or no?" CHOICE
if [ $CHOICE == "yes" -o $CHOICE == "y" ];then
SERVER_INSTALL
else
AGENT_INSTALL
fi