Zabbix 一键安装脚本(CentOS7)

  • by

系统版本:

[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)

[root@localhost ~]# cat /etc/os-release NAME=”CentOS Linux” VERSION=”7 (Core)” ID=”centos” ID_LIKE=”rhel fedora” VERSION_ID=”7″ PRETTY_NAME=”CentOS Linux 7 (Core)” ANSI_COLOR=”0;31″ CPE_NAME=”cpe:/o:centos:centos:7″ HOME_URL=”https://www.centos.org/” BUG_REPORT_URL=”https://bugs.centos.org/” CENTOS_MANTISBT_PROJECT=”CentOS-7″ CENTOS_MANTISBT_PROJECT_VERSION=”7″ REDHAT_SUPPORT_PRODUCT=”centos” REDHAT_SUPPORT_PRODUCT_VERSION=”7″

以下为脚本内容

#!/bin/bash # #基于CentOS Linux release 7.6.1810 (Core) #安装结束为zabbix 4.2 ifSuccess(){ if [ $? == 0 ];then echo “=======================================================================” echo -e “\033[32m install success \033[0m” echo “=======================================================================” else echo “=======================================================================” echo -e “\033[31m install fail \033[0m” echo “=======================================================================” fi } #关闭selinux setenforce 0 sed -i ‘s/SELINUX=enforcing/SELINUX=disable/’ /etc/sysconfig/selinux #关闭防火墙 systemctl stop firewalld.service systemctl disable firewalld.service #安装基础工具,同步时间 yum install -y wget vim ntp lrzsz ntpdate ntp1.aliyun.com yum -y groupinstall “Development Tools” ifSuccess #设置时区为上海 mv /etc/localtime /etc/localtime.bak ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #下载最新yum源 wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo ifSuccess #yum search mysql | tac #安装mariadb数据库,php、httpd yum -y install mariadb mariadb-server php php-mysql httpd ifSuccess systemctl enable mariadb systemctl start mariadb #mysql_secure_installation #初始化数据库 echo ” y 123456 123456 y y y y ” | mysql_secure_installation –stdin #创建库及zabbix账号 mysql -uroot -p123456 -e “create database zabbix default character set utf8 collate utf8_bin;” mysql -uroot -p123456 -e “grant all on zabbix.*to ‘zabbix’@’%’ identified by ‘zabbix’;” systemctl start httpd #安装zabbix3.0所需要EPEL源和zabbix的yum源,需要重新修改 rpm -ivh http://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm rpm -ivh http://repo.zabbix.com/zabbix/4.1/rhel/7/x86_64/zabbix-release-4.1-1.el7.noarch.rpm #安装zabbix yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get ifSuccess #导入zabbix数据库结构 cd /usr/share/doc/zabbix-server-mysql-4.2.0/ zcat create.sql.gz | mysql -uroot -p123456 zabbix #vim /etc/zabbix/zabbix_server.conf #修改zabbix-server配置文件 sed -i ‘s/# DBPassword=/DBPassword=zabbix/g’ /etc/zabbix/zabbix_server.conf #修改php配置文件 #vim /etc/httpd/conf.d/zabbix.conf sed -i ‘s@# php_value date.timezone Europe/Riga@php_value date.timezone Asia/Shanghai@g’ /etc/httpd/conf.d/zabbix.conf systemctl enable zabbix-server systemctl start zabbix-server systemctl restart httpd #如果fping文件存在则安装,如果不存在则提示用户 if [ -e /root/fping.tar.gz ];then tar xf /root/fping.tar.gz cd /root/fping-2.4b2_to/ ./configure make install sed -i ‘s@# Fping6Location=/usr/sbin/fping6@FpingLocation=/usr/local/sbin/fping@g’ /etc/zabbix/zabbix_server.conf chown root:root /usr/local/sbin/fping chmod u+s /usr/local/sbin/fping systemctl restart zabbix-server else echo -e “\033[32m fping install file not exists \033[0m” echo “=======================================================================” echo -e “\033[32m Zabbix is install success,please access http://11.254.254.250/zabbix/setup.php \033[0m” echo “=======================================================================”

目前在想办法将数据库更换为Mysql,还未完成

标签:

发表评论