温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-03-06 23:31:08 来源:网络 阅读:227 作者:qq5d47f509174fe 栏目:云计算
#!/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 <<EOF
spawn mysqladmin -u root -p password 123123 
expect {
    "Enter*"
    {send "\r"}
}
expect eof
EOF

}

#检测LAMP架构是否已经安装完毕
service httpd restart &> /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"
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI