一键搭建zabbix脚本
标题搭建zabbix脚本
#!/bin/bash
#1.配置防火墙和selinux
echo"正在配置firewall防火墙……"
systemctl stop firewalld >> /dev/null
systemctl disable firewalld >>/dev/null
if [ $? -eq 0 ];
then
echo"Firewall防火墙初始化完毕!"
fi
echo"正在关闭SELinux……"
setenforce 0 > /dev/null 2>&1
sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config
if [ $? -eq 0 ];
then
echo"SELinux初始化完毕!"
fi#2.安装lamp环境
echo"安装lamp"
yum -y install httpd mariadb mariadb-server php php-mysql php-gd &>/dev/null
if [ $? -eq 0 ];
then
echo "lamp 安装成功"
else
echo "lamp 安装失败"
fi#3.启动数据库
mysql -e "create database zabbix charset utf8;
grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
flush privileges;
"
if [ $? -eq 0 ];
then
echo"数据库初始化完成"
else
echo"数据库初始化失"
fi#4.启动httpd服务并设置为开机自启
systemctlstarthttpd && systemctl enable httpd &>/dev/null
if [ $? -eq 0 ];
then
echo "apache 启动成功"
else
echo "apache 启动失败"
fi#5.安装zabbix服务
rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm &>/dev/null &>/dev/null
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
if [ $? -eq 0 ];
then
echo"zabbix-server安装完成"
else
echo"zabbix-server安装失败"
fi#6.导入数据库
cd /usr/share/doc/zabbix-server-mysql-3.4.15/
zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
if [ $? -eq 0 ];
then
echo"数据导入完成"
else
echo"数据导入失败"
fi#7.配置zabbix配置文件并启动
sed -i '/# DBPassword=/a\DBPassword=zabbix'/etc/zabbix/zabbix_server.conf
if [ $? -eq 0 ];
then
echo"zabbix配置完成"
else
echo"zabbix配置失败"
fisystemctl start zabbix-server && systemctl enable zabbix-server &>/dev/null
if [ $? -eq 0 ];
then
echo"zabbix-server 服务启动成功"
else
echo"zabbix-server 服务启动失败"
fised -i '/^;
date.timezone/a\date.timezone =Asia/Shanghai' /etc/php.ini#8。重启httpd服务
systemctlrestarthttpd && systemctl enable httpd &>/dev/null
if [ $? -eq 0 ];
then
echo "apache 启动成功"
else
echo "apache 启动失败"
fi#9。修改zabbix乱码
sed -i s/graphfont/simkai/g /usr/share/zabbix/include/defines.inc.php
推荐阅读
- 六步搭建ES6语法环境
- (1)redis集群原理及搭建与使用(1)
- 桁架搭建有什么价值()
- VM|VM ware 的 harbor 私有仓库搭建 (Ubuntu16.04)
- PHP开发-Mac搭建ThinkPHP5.0
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- sentry搭建错误监控系统(二)
- 【乐高创意作品】超智能!这款乐高搭建的除草机!
- 8、Flask构建弹幕微电影网站-搭建后台页面-密码修改、主页控制面板
- 适用于小白(VSCode搭建Vue项目,最详细的搭建步骤哦)