百度网盘获取离线包:提取码:6666 Gitee获取离线包:
yum -y install git
git clone https://gitee.com/haimati/linux_-shell_-zabbix.git zabbix.install
cd zabbix.install/zabbix.install/
bash off_zabbix_install.sh
脚本内容:
#!/bin/bash
clear
. /etc/init.d/functions
## variable
CURRT_PATH=$(pwd)
DBROOT_passwd=NTQ34tg*@19VF
DBUSER_passwd=NTQ34tg*@19VF
zabbix_install(){
echo "离线部署zabbix 请确保在干净的操作系统中执行 进度如下:"
cd ${CURRT_PATH}/zabbix
if (yum localinstall -y * &>/dev/null);then
action "zabbix install"
else
action "zabbix install" false
fi
}
mariadb_install(){
cd ${CURRT_PATH}/mariadb/
if (yum localinstall -y * &>/dev/null);then
action "mariadb install"
else
action "mariadb install" false
fi
if (systemctl enable mariadb.service --now &>/dev/null);then
action "mariadb start"
else
action "mariadb start" false
fi
}
mariadb_config(){
(mysql -e "set password=password('${DBROOT_passwd}');") &>/dev/null
(mysql -uroot -p${DBROOT_passwd} -e \
"create database zabbix character set utf8 collate utf8_bin;") &>/dev/null
(mysql -uroot -p${DBROOT_passwd} -e \
"grant all on zabbix.* to zabbix@'localhost' identified by '${DBUSER_passwd}';") &>/dev/null
(zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | \
mysql -uzabbix -p${DBUSER_passwd} zabbix) &>/dev/null
if [ $? -eq 0 ];then
action "mariadb config"
else
action "mariadb config" false
fi
}
zabbix_config(){
# 配置数据库连接密码
sed -i "s/# DBPassword=/DBPassword=${DBUSER_passwd}/g" \
/etc/zabbix/zabbix_server.conf
if (systemctl enable zabbix-server --now &>/dev/null);then
action "zabbix start"
else
action "zabbix start" false
fi
# 修改http服务时区
(sed -i "/php_value date/ a\php_value date.timezone Asia/Shanghai" \
/etc/httpd/conf.d/zabbix.conf)
if (systemctl enable httpd --now &>/dev/null);then
action "httpd start"
else
action "httpd start" false
fi
# 解决图形乱码
cd ${CURRT_PATH}/luanma
(prm -ivh wqy-microhei-fonts-0.2.0-0.12.beta.el7.noarch.rpm) &>/dev/null
mv /usr/share/zabbix/assets/fonts/graphfont.ttf{,.bak}
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/assets/fonts/graphfont.ttf
}
sys_config(){
IPA=$(ip addr |egrep 'inet'|egrep -v "inet6" | grep "ens[[:digit:]].*$" | awk '{print $2}'| awk -F/ '{print $1}')
(firewall-cmd --add-service=http --permanent) &>/dev/null
(firewall-cmd --add-service=https --permanent) &>/dev/null
(firewall-cmd --add-service=zabbix-server --permanent) &>/dev/null
(firewall-cmd --add-service=zabbix-agent --permanent) &>/dev/null
(firewall-cmd --reload) &>/dev/null
(sed -i 's/^SELINUX=d.*/SELINUX=permissive/g' /etc/selinux/config) &>/dev/null
echo
echo -e "\e[0;32m Visible links:\e[0m"
echo -e "\e[0;32m http://${IPA}/zabbix \e[0m"
echo -e "\e[0;32m http://localhost/zabbix \e[0m"
}
Zabbix(){
zabbix_install
mariadb_install
mariadb_config
zabbix_config
sys_config
}
##########Agent##########
agent(){
cd ${CURRT_PATH}/agent
(rpm -ivh zabbix-agent-4.0.32-1.el7.x86_64.rpm) &>/dev/null
read -p "请输入zabbix Server IP地址:" IPB
sed -i "s/^Server.*/Server=${IPB}/g" /etc/zabbix/zabbix_agentd.conf
if (systemctl enable zabbix-agent.service --now) &>/dev/null;then
action "zabbix-agent"
else
action "zabbix-agent" false
fi
(firewall-cmd --add-service=zabbix-agent --permanent) &>/dev/null
(firewall-cmd --reload) &>/dev/null
}
Zabbix
# agent
- 注意:
1、默认数据库密码为:NTQ34tg*@19VF,可根据脚本中变量自定义
2、安装监控agent端请注释脚本函数 修改如下:
离线部署zabbix演示:
添加agent端演示: