1 #!/bin/bash 2 3 # 4 # 0、配置无人值守的安装,定义安装过程中需要用到的一些信息 5 # 6 mysql_root_pw=root_pw 7 mysql_zabbix_pw=zabbix_pw 8 DBPassword=$mysql_zabbix_pw 9 CacheSize=256M 10 ZBX_SERVER_NAME=My-Zabbix-Server 11 12 # 13 # 1、配置yum源 14 # 15 16 cat /etc/redhat-release |grep -i centos |grep ‘7.[[:digit:]]‘ >/dev/null 17 18 if [[ $? != 0 ]] 19 then 20 echo -e "不支持的操作系统,该脚本只适用于CentOS 7.x x86_64 操作系统" 21 exit 1 22 fi 23 24 rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/ |grep release |awk -F ‘>|<‘ ‘{print $3}‘) &>/dev/null 25 26 sed -i ‘[email protected]@mirrors.aliyun.com/[email protected]‘ /etc/yum.repos.d/zabbix.repo 27 28 # 29 # 2、使用yum安装Zabbix及必备软件 30 # 31 32 yum install -y httpd mariadb-server php gd php-bcmath php-ctype php-xml php-xmlreader php-xmlwriter php-session php-mbstring php-gettext php-ldap OpenIPMI libssh2 fping libcurl libxml2 net-snmp 33 yum install -y gnutls trousers 34 yum install -y zabbix-get zabbix-server-mysql zabbix-web-mysql 35 36 # 37 # 3、配置MySQL 38 # 39 40 sed -i ‘/^symbolic-links=0/a character-set-server=utf8\ninnodb_file_per_table=1‘ /etc/my.cnf 41 systemctl enable mariadb.service 42 systemctl start mariadb.service 43 mysqladmin -uroot password $mysql_root_pw 44 mysql -h localhost -uroot -p$mysql_root_pw -e "create database zabbix character set utf8;" 45 mysql -h localhost -uroot -p$mysql_root_pw -e "grant all privileges on zabbix.* to [email protected] identified by ‘$mysql_zabbix_pw‘;" 46 mysql -h localhost -uroot -p$mysql_root_pw -e "flush privileges;" 47 48 zcat /usr/share/doc/zabbix-server-mysql-3.0.*/create.sql.gz | mysql -uroot -p$mysql_root_pw zabbix 49 50 # 51 # 4、配置Zabbix 52 # 53 54 sed -i "/^# DBPassword=/a DBPassword=$DBPassword" /etc/zabbix/zabbix_server.conf 55 sed -i "/^# CacheSize=8M/a CacheSize=$CacheSize" /etc/zabbix/zabbix_server.conf 56 57 sed -i ‘s/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/‘ /etc/httpd/conf.d/zabbix.conf 58 59 cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php 60 sed -i "10c \$DB[\"PASSWORD\"] = ‘$DBPassword‘;" /etc/zabbix/web/zabbix.conf.php 61 sed -i "16c \$ZBX_SERVER_NAME = ‘$ZBX_SERVER_NAME‘;" /etc/zabbix/web/zabbix.conf.php 62 63 systemctl enable zabbix-server 64 systemctl start zabbix-server 65 systemctl enable httpd 66 systemctl start httpd 67 68 firewall-cmd --permanent --zone=public --add-service=http 69 firewall-cmd --permanent --zone=public --add-port=10050/tcp 70 firewall-cmd --permanent --zone=public --add-port=162/udp 71 firewall-cmd --reload 72 73 setenforce 0 74 sed -i ‘s/SELINUX=enforcing/SELINUX=permissive/‘ /etc/sysconfig/selinux
时间: 2024-10-27 00:31:55