Zabbix-server One-click installation script

Source: Internet
Author: User

#!/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 in zabbix.* to [e-mail protected] 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 Services

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"


This article is from the "Gao Chuan" blog, please be sure to keep this source http://luchuangao.blog.51cto.com/11311715/1759970

Zabbix-server One-click installation script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.