lamp+zabbix

!/bin/bash
Auto zabbix
By author pingbao zhou
date: 2019/08/01
Version: 1.1.0
关闭防火墙 &setenforce
setenforce 0
systemctl stop firewalld

安装 httpd
function httpd_install(){
if “$1” -eq “1” ; then
yum install httpd -y
if [$? -eq 0]; then
echo -e “ Install Successs “
else
echo -e “Installation failed!”
fi
fi
sed -i ‘s/DirectoryIndex index.html index.php /#DirectoryIndex index.html/g’ /etc/httpd/conf/httpd.conf
systemctl start httpd
systemctl enable httpd
rpm -qa | grep httpd
ps -ef | grep httpd

}

安装 mysql
function mysql_install(){
if “$1” -eq “2” ; then
yum install wget -y
sudo yum install -y https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
yum -y install yum-utils
sudo yum-config-manager —disable mysql80-community #禁用
sudo yum-config-manager —disable mysql80-community-source
sudo yum-config-manager —enable mysql57-community #启用
sudo yum-config-manager —disable mysql57-community-source
sudo yum install mysql-community-server -y
if [$? -eq 0]; then
echo -e “Install Successs !”
echo -e ‘skip-grant-tables’ >> /etc/my.cnf

else
    echo -e  "Installation failed!"
fi

fi
if [ -z systemctl restart mysqld ];then
#数据库初始化账户:root 密码:123456 修改密码规则
mysql -e “flush privileges;alter user ‘root’@‘localhost’ identified by ‘123456’;”
sed -i ‘s/skip.*//’ /etc/my.cnf
systemctl restart mysqld
#创建 zabbix& 设定密码和规则
mysql -uroot -p123456 -e “CREATE DATABASE zabbix character set utf8 collate utf8_bin;”
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to ‘zabbix’@‘localhost’ identified by ‘THISpasswd123?’;"
mysql -uroot -p123456 -e “mysqlcmd” “flush privileges;”
sudo systemctl restart mysqld.service
sudo systemctl status mysqld.service
sudo systemctl enable mysqld.service
else
echo -e ‘mysqlservices start failed!’
fi
}

安装 PHP 及其拓展
function php_install(){
if “$1” -eq “3” ; then
yum -y remove php*
cd /etc/yum.repos.d
sudo mv CentOS-Base.repo CentOS-Base.repo.bak
sudo wget -c http://mirrors.aliyun.com/repo/
sudo wget -c http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

if [ $? -eq 0 ]; then
     echo -e "Successful implementation !"
else
     yum clean all&&yum makecache
     yum search php
fi
if [ $? -eq 0 ]; then
    echo -e "Install Successs !!"
else
    echo -e  "Installation failed!"
fi

fi
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
systemctl enable php-fpm.service
systemctl restart php-fpm.service
yum install -y php72w-pecl-redis.x86_64
php -m
yum -y install php71w-xxx #安装其他需要的拓展模块
}

systemctl stop firewalld.service
setenforce 0
systemctl start httpd.service
systemctl start mysql.service

安装 zabbix 及其拓展
function zabbix_install(){
if “$1” -eq “4” ; then
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum clean all
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
fi
if [$? -eq 0]; then
echo -e “Install Successs !!”
else
echo -e “”Installation failed!””
yum clean all
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

sed -i ‘s/date.timezone = PRC/;date.timezone = /g’ /etc/php.ini
sed -i ‘s/expose_php = Off/expose_php = On/g’ /etc/php.ini
sed -i ‘s/short_open_tag=On/;short_open_tag/g’ /etc/php.ini
sed -i ‘s/cgi.fix_pathinfo=1/;cgi.fix_pathinfo=1/g’ /etc/php.ini
sed -i ‘s/max_execution_time=0/max_execution_time=30/g’ /etc/php.ini
sed -i ‘s/max_input_time =300/max_input_time =60/g’ /etc/php.ini
sed -i ‘s/max_input_time =256/memory_limit = 128/g’ /etc/php.ini
sed -i ‘s/post_max_size = 100M/post_max_size = 8M/g’ /etc/php.ini
导入数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

配置 zabbixserver 连接 mysql
sed -i.ori ‘115a DBPassword=THISpasswd123?’ /etc/zabbix/zabbix_server.conf

添加时区
sed -i.ori ‘18a php_value date.timezone Asia/Shanghai’ /etc/httpd/conf.d/zabbix.conf

解决中文乱码
yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

为 Zabbix 前端配置 PHP
sed -i ‘s/php_value date.timezone Europe/Riga/#php_value date.timezone Europe/Riga/g’ /etc/httpd/conf.d/zabbix.conf
systemctl restart zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd

写入开机自启动
chmod +x /etc/rc.d/rc.local
cat >>/etc/rc.d/rc.local<<EOF
systemctl start mysql
systemctl start httpd
systemctl start zabbix-server
EOF

输出信息
echo “浏览器访问 http://hostname -I|awk ‘{print $1}’/zabbix”
fi
echo -e “expose_php = Off” >> /etc/php.ini
echo -e “date.timezone =PRC” >> /etc/php.ini
echo -e “short_open_tag = On “ >> /etc/php.ini
echo -e “cgi.fix_pathinfo=1 “ >> /etc/php.ini
echo -e “max_execution_time = 0 “ >> /etc/php.ini
echo -e “max_input_time = 300 “ >> /etc/php.ini
echo -e “memory_limit = 256M “ >> /etc/php.ini
echo -e “post_max_size = 100M “ >> /etc/php.ini
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
echo -e “DBPassword=THISpasswd123? “ >> /etc/zabbix/zabbix_server.conf
echo -e “php_value date.timezone Europe/Riga” >> /etc/httpd/conf.d/zabbix.conf
}

PS3=”Please enter you select install menu:”
select i in http mysql php zabbix quit
do
case $i in
http)
httpd_install 1
;;
mysql)
mysql_install 2
;;
php)
php_install 3
;;
zabbix)
zabbix_install 4
;;
quit)
exit
esac
done