zabbix-server一键安装脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix-server一键安装脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash


#created : 2015-03-22

#version : 1.0.0

#author : Jason


install_tools()

{

echo -e "\e[1;32mBegin install tools......\e[0m"

echo 


yum install -y wget lrzsz > /dev/null


if [ $? -eq 0 ];then

echo -e "\e[1;32mThe tools installation is complete.\e[0m"

echo 

else

echo -e "\e[30;41m The tools installation is failure. \e[0m"

echo 

exit 0

fi

}


#安装下载源

install_repo()

{

echo -e "\e[1;32mBegin install repo......\e[0m"

echo 

wget http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm 

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 

rpm -ivh zabbix-release-2.4-1.el6.noarch.rpm > /dev/null

rpm -ivh epel-release-6-8.noarch.rpm > /dev/null


if [ $? -eq 0 ]; then

echo -e "\e[1;32mThe REPO installation is complete.\e[0m"

echo

else

echo -e "\e[30;41m The REPO installation is failure. \e[0m"

echo 

exit 0

fi

}


install_zabbix()

{

echo -e "\e[1;32mBegin install zabbix......\e[0m"

echo 


yum install -y zabbix zabbix-get zabbix-server zabbix-web-mysql zabbix-web zabbix-agent  > /dev/null


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe Zabbix installation is complete.\e[0m"

echo

else

echo -e "\e[30;41m The Zabbix installation is failure.\e[0m"

echo

exit 0

fi

}


install_mysql()

{

echo -e "\e[1;32mBegin install mysql......\e[0m"

echo


yum install -y mysql-server > /dev/null


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe mysql installation is complete.\e[0m"

echo

else

echo -e "\e[30;41m The mysql installation is failure.\e[0m"

echo

exit 0

fi

}


#修改Mysql配置文件

mysql_config()

{

echo -e "\e[1;32mBegin to configure the mysql service......\e[0m"

echo

sed -i ‘7 s/^/character-set-server=utf8\n/‘ /etc/my.cnf

sed -i ‘8 s/^/innodb_file_per_table=1\n/‘ /etc/my.cnf


if [ $? -eq 0 ];then

echo -e "\e[1;32mThe Mysql configuration is complete. \e[0m"

echo

else

echo -e "\e[30;41m The Mysql configuration is failure. \e[0m"

echo

exit 0

fi

}


#启动mysqld服务

mysqld_on()

{

echo -e "\e[1;32mTo start the Mysql service......\e[0m"

echo

chkconfig mysqld on

service mysqld start


if [ $? -eq 0 ];then

echo -e "\e[1;32mThe Mysql service start successfully. \e[0m"

echo

else

echo -e "\e[30;41m The Mysql service start failure. \e[0m"

echo

exit 0

fi

}


#创建Zabbix的数据库

zabbix_created()

{

echo -e "\e[1;32mBegin creating the Zabbix database......\e[0m"

echo

mysqladmin -uroot password admin

mysql -uroot -padmin -e "create database zabbix character set utf8;"

mysql -uroot -padmin -e "grant all privileges on zabbix.* to [email protected]host identified by ‘zabbix‘;flush privileges;"

mysql -uzabbix -pzabbix zabbix < /usr/share/doc/zabbix-server-mysql-*/create/schema.sql

mysql -uzabbix -pzabbix zabbix < /usr/share/doc/zabbix-server-mysql-*/create/images.sql

mysql -uzabbix -pzabbix zabbix < /usr/share/doc/zabbix-server-mysql-*/create/data.sql


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe Zabbix database to create success. \e[0m"

echo

else

echo -e "\e[30;41m The Zabbix database to create failed. \e[0m"

echo

exit 0

fi

}


#修改zabbix_server配置文件

zabbix_server_config()

{

echo -e "\e[1;32mBegin to configure the Zabbix-server service......\e[0m"

echo


mkdir /etc/zabbix/alertscripts

mkdir /etc/zabbix/externalscripts

cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak

cat > /etc/zabbix/zabbix_server.conf <<EOF

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock

DBPort=3306

StartPollers=5

StartIPMIPollers=10

StartPollersUnreachable=10

StartTrappers=10

StartPingers=10

StartDiscoverers=10

VMwareFrequency=60

VMwareCacheSize=8M

SNMPTrapperFile=/var/log/snmptt/snmptt.log

ListenIP=127.0.0.1

MaxHousekeeperDelete=500

CacheSize=256M

StartDBSyncers=40

HistoryCacheSize=128M

TrendCacheSize=128M

HistoryTextCacheSize=128M

ValueCacheSize=128M

Timeout=30

TrapperTimeout=300

UnreachablePeriod=45

UnavailableDelay=60

UnreachableDelay=15

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts

FpingLocation=/usr/sbin/fping

LogSlowQueries=10000

StartProxyPollers=50

ProxyConfigFrequency=3600

EOF


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe Zabbix-server configuration is complete. \e[0m"

echo

else

        echo -e "\e[30;41m The Zabbix-server configuration is failure. \e[0m"

echo

exit 0

fi

}


#php配置文件的设置

php_config()

{

echo -e "\e[1;32mBegin to configure the PHP service......\e[0m"

echo


cp /etc/php.ini /etc/php.ini.bak

cat >>/etc/php.ini <<EOF

date.timezone = Asia/Shanghai

max_execution_time = 300

post_max_size = 16M

max_input_time = 300

memory_limit = 128M

mbstring.func_overload = 1

EOF


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe PHP configuration is complete. \e[0m"

echo

else

        echo -e "\e[30;41m The PHP configuration is failure. \e[0m"

echo

exit 0

fi

}


#启动Zabbix-Server服务

zabbix_server_on()

{

echo -e "\e[1;32mTo start the Zabbix-server service......\e[0m"

echo

/etc/init.d/zabbix-server start

/etc/init.d/zabbix-agent start

/etc/init.d/httpd start

chkconfig zabbix-server on

chkconfig zabbix-agent on

chkconfig httpd on


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe Zabbix-server service start successfully. \e[0m"

echo

else

        echo -e "\e[30;41m The Zabbix-server service start failure. \e[0m"

echo

exit 0

fi

}


#关闭Selinux服务

selinux_stop()

{

echo -e "\e[1;32mClose the SELINUX service......\e[0m"

echo


setenforce 0

sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/sysconfig/selinux 


if [ $? -eq 0 ];then

        echo -e "\e[1;32mThe SELINUX service closed successfully. \e[0m"

echo

else

        echo -e "\e[30;41m The SELINUX service closed  failure. \e[0m"

echo

exit 0

fi

}


#开启iptables端口

iptables_on()

{

echo -e "\e[1;32mOpen the iptables port......\e[0m"

echo

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT

iptables -I OUTPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT

iptables-save > /etc/sysconfig/iptables


if [ $? -eq 0 ];then

        echo -e "\e[1;32mOpen the iptables port successfully. \e[0m"

echo

else

        echo -e "\e[30;41m Open the iptables port failure. \e[0m"

echo

exit 0

fi

}



echo -e "\e[30;42m +===============A key installation Zabbix services===============+ \e[0m"

echo

install_tools

sleep 3

install_repo

sleep 3

install_zabbix

sleep 3

install_mysql

sleep 3

mysql_config

sleep 3

mysqld_on

sleep 3

zabbix_created

sleep 3

zabbix_server_config

sleep 3

php_config

sleep 3

zabbix_server_on

sleep 3

selinux_stop

sleep 3

iptables_on

sleep 3

echo

echo -e "\e[30;42m +==============Zabbix service installation is complete=============+ \e[0m"


本文出自 “高路川” 博客,请务必保留此出处http://luchuangao.blog.51cto.com/11311715/1759970

以上是关于zabbix-server一键安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

一键安装脚本JDKmysqlredis

shell脚本一键部署——tomcat安装部署

shell脚本一键部署——tomcat安装部署

centos怎么样编写一键安装脚本

centos一键换内核安装锐速脚本

vsftpd一键安装脚本