#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# 检查是否是root用户
if [ $(id -u) != "0" ]; then
echo "运行此脚本需root权限, 请切换到root用户安装!"
exit 1
fi
echo "========================================================================="
echo "zabbix_agentd 2.26 for CentOS/RadHat Linux Server"
echo "========================================================================="
#开放防火墙端口
cd /etc/sysconfig/
rm -rf iptables
echo '# Firewall configuration written by system-config-securitylevel' >> /etc/sysconfig/iptables
echo '# Manual customization of this file is not recommended.' >> /etc/sysconfig/iptables
echo '*filter' >> /etc/sysconfig/iptables
echo ':INPUT ACCEPT [0:0]' >> /etc/sysconfig/iptables
echo ':FORWARD ACCEPT [0:0]' >> /etc/sysconfig/iptables
echo ':OUTPUT ACCEPT [0:0]' >> /etc/sysconfig/iptables
echo ':RH-Firewall-1-INPUT - [0:0]' >> /etc/sysconfig/iptables
echo '-A INPUT -j RH-Firewall-1-INPUT' >> /etc/sysconfig/iptables
echo '-A FORWARD -j RH-Firewall-1-INPUT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -i lo -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p 50 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p 51 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 7071 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 177 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 161 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited' >> /etc/sysconfig/iptables
echo 'COMMIT' >> /etc/sysconfig/iptables
service iptables restart
#设置SELINUX
sed -i 's/SELINUXTYPE=targeted/#SELINUXTYPE=targeted/g' /etc/selinux/config
setenforce 0
#yum安装源码包
yum install apr* autoconf automake bison cloog-ppl compat* cpp fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers
keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng* libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* libX* make mpfr ncurses* ntp openssl
openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* nasm nasm* wget zlib-devel
#添加用户组和用户
groupadd zabbix
useradd -g zabbix zabbix
#创建zabbix_agentd安装目录并授权
mkdir /usr/local/zabbix
chown -R zabbix.zabbix /usr/local/zabbix
#开始安装
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
/sbin/ldconfig
cd /usr/src
tar zxvf zabbix-2.2.6.tar.gz
cd zabbix-2.2.6
echo "========================================================================="
echo "zabbix_agentd 2开始安装"
echo "========================================================================="
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
#添加软链接
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/
#添加zabbix服务对应的端口
echo 'zabbix-agent 10050/tcp #Zabbix Agent' >> /etc/services
echo 'zabbix-agent 10050/udp #Zabbix Agent' >> /etc/services
echo 'zabbix-trapper 10051/tcp #Zabbix trapper' >> /etc/services
echo 'zabbix-trapper 10051/udp #Zabbix trapper' >> /etc/services
#修改zabbix_agentd配置文件
read -p "请输入服务器IP地址:" IPAddr
sed -i "s/Server=127.0.0.1/Server=$IPAddr/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/# Include=\/usr\/local\/etc\/zabbix_agentd.conf.d\//Include=\/usr\/local\/zabbix\/etc\/zabbix_agentd.conf.d\//g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' /usr/local/zabbix/etc/zabbix_agentd.conf
echo "========================================================================="
echo "修改zabbix_agentd配置文件完成"
echo "========================================================================="
#添加开机启动脚本
cp /usr/src/zabbix-2.2.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix\//g' /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_agentd
echo "========================================================================="
echo "zabbix_agentd加入开机自启动"
echo "========================================================================="
chkconfig zabbix_agentd on
#检查Zabbix客户端是否正常运行
echo "========================================================================="
echo "zabbix_agentd 监控端启动"
echo "========================================================================="
service zabbix_agentd start
echo "========================================================================="
echo "zabbix_agentd 进程查看"
echo "========================================================================="
ps ax|grep zabbix_agentd
netstat -utlnp | grep zabbix
阅读(1423) | 评论(0) | 转发(0) |