资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

一键实现基于LAMP架构的zabbix基本安装

#!/bin/bash
#简易安装zabbix+LAMP
#
lamp(){

#关闭防火墙&核心安全功能
systemctl stop firewalld.service
systemctl disable firewalld.service &> /dev/null
setenforce 0
sed -i "7cSELINUX=disabled" /etc/sysconfig/selinux

yum install -y \
httpd \
mariadb-server mariadb \
php \
php-MySQL \
php-gd \
libjpeg* \
php-ldap \
php-odbc \
php-pear \
php-xml \
php-xmlrpc \
php-mhash \
expect

#修改httpd的配置文件
sed -i -e "95aServerName www.kgc.com" -e "/DirectoryIndex/s/index.html/index.html index.php/" /etc/httpd/conf/httpd.conf

#修改PHP的时区
sed -i "878cdate.timezone = PRC" /etc/php.ini

#数据库&httpd启动
systemctl start httpd.service
systemctl enable httpd.service
systemctl start mariadb.service
systemctl enable mariadb.service

#设定数据库初始密码
/usr/bin/expect < /dev/null
service mysqld restart &> /dev/null
systemctl restart mariadb &> /dev/null
netstat -atnp | egrep '(httpd|3306)' &> /dev/null
if [ $? -ne 0 ];then
    lamp
fi

#建立zabbix数据库和管理用户
mysql  -uroot -p123123 -e "CREATE DATABASE zabbix character set utf8 collate utf8_bin;"
mysql  -uroot -p123123 -e "GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'zhy94666';"
mysql  -uroot -p123123 -e "flush privileges;"

echo "开始准备安装zabbix"
sleep 3
#安装PHP对应工具
yum install php-bcmath php-mbstring -y

#生成zabbix对应yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm

#安装zabbix(网络不好,比较难下)
for ((i=1;i>0;i++));do
rpm -q zabbix-web-mysql &> /dev/null
if [ $? -ne 0 ];then
        yum install zabbix-server-mysql zabbix-web-mysql -y
else
        break
fi
done

#解决本地无法登录问题
mysql -uroot -p123123 -e "drop user ''@localhost;"
mysql -uroot -p123123 -e "drop user ''@localhost.localdomain;"
mysql -uroot -p123123 -e "flush privileges"   

#生成数据库文件
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -pzhy94666 zabbix

#修改zabbix服务端配置文件
sed -i "125cDBPassword=zhy94666" /etc/zabbix/zabbix_server.conf

#修改时区
sed -i "20cphp_value date.timezone Asia/Shanghai" /etc/httpd/conf.d/zabbix.conf

systemctl enable zabbix-server
systemctl start zabbix-server
service httpd restart
netstat -anpt | grep zabbix &> /dev/null
if [ $? -eq 0 ];then
    echo "zabbix服务端设置完成"
fi
dizhi=`ifconfig ens33 | awk 'NR==2{print $2}'`
echo "请使用浏览器登陆${dizhi}/zabbix/进行安装
默认登陆用户名为:Admin
默认登陆密码为:zabbix"

分享题目:一键实现基于LAMP架构的zabbix基本安装
本文路径:http://www.cdkjz.cn/article/psgdph.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220