一键实现基于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 <<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"

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/183561.html

(0)
上一篇 2021年11月2日
下一篇 2021年11月2日

相关推荐

发表回复

登录后才能评论