在 CentOS6 上安装 Zabbix2.4 Server

 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 '6.[[:digit:]]' &>/dev/null
17 
18 if [[ $? != 0 ]] 
19 then
20     echo -e "不支持的操作系统,该脚本只适用于CentOS 6.x 操作系统"
21     exit 1
22 fi
23 
24 os_m=$(uname -m)
25 za_rpm=$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/2.4/rhel/6/$os_m/ |grep release  |awk -F '>|<' '{print $3}')
26 rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/2.4/rhel/6/$os_m/$za_rpm
27 
28 if [[ $? != 0 ]] 
29 then
30     echo -e "yum源配置失败,请检查网络或者其他原因"
31     exit 1
32 fi
33 
34 sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@' /etc/yum.repos.d/zabbix.repo
35 
36 #
37 #    2、使用yum安装Zabbix及必备软件
38 #
39 
40 yum install -y httpd mysql-server php 
41 yum install -y zabbix 
42 yum install -y zabbix-agent zabbix-sender
43 yum install -y zabbix-server zabbix-get
44 yum install -y zabbix-web zabbix-web-mysql
45 
46 #
47 #    3、配置MySQL
48 #
49 
50 sed -i '/^symbolic-links=0/a character-set-server=utf8\ninnodb_file_per_table=1' /etc/my.cnf
51 chkconfig mysqld on
52 /etc/init.d/mysqld start
53 mysqladmin -uroot password $mysql_root_pw
54 mysql -h localhost -uroot -p$mysql_root_pw -e "create database zabbix character set utf8;"
55 mysql -h localhost -uroot -p$mysql_root_pw -e "grant all privileges on zabbix.* to zabbix@localhost identified by '$mysql_zabbix_pw';"
56 mysql -h localhost -uroot -p$mysql_root_pw -e "flush privileges;"
57 
58 mysql -h localhost -uzabbix -p$mysql_zabbix_pw -Dzabbix < /usr/share/doc/$(rpm -q zabbix-server-mysql |awk -F '-' '{print $1"-"$2"-"$3"-"$4}')/create/schema.sql
59 mysql -h localhost -uzabbix -p$mysql_zabbix_pw -Dzabbix < /usr/share/doc/$(rpm -q zabbix-server-mysql |awk -F '-' '{print $1"-"$2"-"$3"-"$4}')/create/images.sql
60 mysql -h localhost -uzabbix -p$mysql_zabbix_pw -Dzabbix < /usr/share/doc/$(rpm -q zabbix-server-mysql |awk -F '-' '{print $1"-"$2"-"$3"-"$4}')/create/data.sql
61 
62 #
63 #    4、配置Zabbix
64 #
65 
66 sed -i "/^# DBPassword=/a DBPassword=$DBPassword" /etc/zabbix/zabbix_server.conf
67 sed -i "/^# CacheSize=8M/a CacheSize=$CacheSize" /etc/zabbix/zabbix_server.conf
68 sed -i 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/' /etc/httpd/conf.d/zabbix.conf
69 cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php
70 sed -i "10c \$DB[\"PASSWORD\"]    = '$DBPassword';" /etc/zabbix/web/zabbix.conf.php
71 sed -i "16c \$ZBX_SERVER_NAME   = '$ZBX_SERVER_NAME';" /etc/zabbix/web/zabbix.conf.php
72 chkconfig zabbix-server on
73 chkconfig zabbix-agent on
74 chkconfig httpd on
75 /etc/init.d/zabbix-server start
76 /etc/init.d/zabbix-agent start
77 /etc/init.d/httpd start
78 iptables -I  INPUT -m state --state NEW -p tcp  --dport 10051 -j ACCEPT 
79 iptables -I  INPUT -m state --state NEW -p tcp  --dport 80 -j ACCEPT  
80 /etc/init.d/iptables save
81 setenforce 0
82 sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux

 

posted @ 2016-04-28 02:31  三角形  阅读(327)  评论(0编辑  收藏  举报