#!/bin/bash
#安裝zabbix和LNMP
#
lnmp(){
#關(guān)閉防火墻&核心安全功能
systemctl stop firewalld.service
systemctl disable firewalld.service &> /dev/null
setenforce 0
sed -i "7cSELINUX=disabled" /etc/sysconfig/selinux
#yum安裝nginx
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
#創(chuàng)建nginx安裝源(centos可以根據(jù)不同系統(tǒng)進(jìn)行替換,后面的版本同樣)
echo "[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/\$basearch/
gpgcheck=0
enabled=1" > /etc/yum.repos.d/nginx.repo
yum install nginx -y
#啟動(dòng)nginx
systemctl start nginx
systemctl enable nginx
#安裝MySQL 5.7并啟動(dòng)
yum install -y mariadb-server mariadb expect
systemctl enable mariadb.service
systemctl start mariadb.service
#設(shè)定數(shù)據(jù)庫初始密碼
/usr/bin/expect <0;i++));do
rpm -q php72w-cli &> /dev/null
if [ $? -ne 0 ];then
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
else
break
fi
done
#修改fpm模塊使其支持nginx
sed -i -e "8cuser = nginx" -e "10cgroup = nginx" /etc/php-fpm.d/www.conf
#更改nginx配置文件使其能識(shí)別php動(dòng)態(tài)文件
sed -i "10s/index.html/index.html index.php/" /etc/nginx/conf.d/default.conf
sed -i -e "30,36s/#//" -e "31s/html/\/usr\/share\/nginx\/html/" -e "34s/\/scripts/\$document_root/" /etc/nginx/conf.d/default.conf
#配置PHP
sed -i -e "359s/On/Off/" -e "202s/Off/On/" /etc/php.ini
#重啟服務(wù)
systemctl start php-fpm
systemctl enable php-fpm
systemctl restart nginx
}
#檢測LNMP架構(gòu)是否已經(jīng)安裝完畢
systemctl restart nginx &> /dev/null
service mysqld restart &> /dev/null
systemctl restart mariadb &> /dev/null
netstat -atnp | egrep '(nginx|3306)' &> /dev/null
if [ $? -ne 0 ];then
lnmp
fi
#配置PHP以適應(yīng)zabbix
sed -i -e "368s/30/300/" -e "378s/60/300/" -e "656s/8/16/" -e "799aalways_populate_raw_post_data = -1" -e "877cdate.timezone = Asia/Shanghai" /etc/php.ini
systemctl restart php-fpm
#建立zabbix數(shù)據(jù)庫和管理用戶
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 '123123';"
mysql -uroot -p123123 -e "flush privileges;"
#解決本地?zé)o法登錄問題
mysql -uroot -p123123 -e "drop user ''@localhost;"
mysql -uroot -p123123 -e "drop user ''@localhost.localdomain;"
mysql -uroot -p123123 -e "flush privileges"
#安裝zabbix
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
for ((k=1;k>0;k++));do
rpm -q zabbix-agent &> /dev/null
if [ $? -ne 0 ];then
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
else
break
fi
done
#生成數(shù)據(jù)庫文件
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123123 zabbix
#修改zabbix服務(wù)端配置文件
sed -i -e "91s/# //" -e "125cDBPassword=123123" /etc/zabbix/zabbix_server.conf
#工作目錄提權(quán)
cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
#啟動(dòng)zabbix
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
#所有服務(wù)重啟
systemctl restart php-fpm nginx mariadb zabbix-server zabbix-agent
#檢查服務(wù)是否均啟動(dòng)
test=`netstat -atnp | egrep '(nginx|3306|10051|10050)' | grep -v "TIME_WAIT" | wc -l`
if [ $test -ge 5 ];then
echo "zabbix服務(wù)端設(shè)置完成"
fi
dizhi=`ifconfig ens33 | awk 'NR==2{print $2}'`
echo "請(qǐng)使用瀏覽器登陸${dizhi}/zabbix/進(jìn)行安裝
默認(rèn)登陸用戶名為:Admin
默認(rèn)登陸密碼為:zabbix"
10多年的南譙網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整南譙建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“南譙網(wǎng)站設(shè)計(jì)”,“南譙網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
代理端就是被控服務(wù)器,如果服務(wù)器也需要被自己監(jiān)控也需要安裝abbix-agent
#關(guān)閉防火墻并設(shè)定開機(jī)自關(guān)
systemctl stop firewalld.service
systemctl disable firewalld.service
#安裝yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
#安裝zabbix-agent
yum install -y zabbix-agent
#修改配置文件
grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
98:Server=127.0.0.1
139:ServerActive=127.0.0.1
150:Hostname=Zabbix server
268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.142.123
#98行,指向監(jiān)控服務(wù)器IP
ServerActive=192.168.142.123
#139行,指向監(jiān)控服務(wù)器IP
Hostname=czt
#150行,可自行定義主機(jī)名
#啟動(dòng)服務(wù)
systemctl enable zabbix-agent.service
systemctl start zabbix-agent.service
#查看服務(wù)監(jiān)聽端口
netstat -anpt | grep zabbix
訪問http://192.168.142.123/zabbix/配置-主機(jī)-創(chuàng)建主機(jī):
配置下的主機(jī)選項(xiàng),點(diǎn)擊創(chuàng)建主機(jī)
在主機(jī)配置界面填入相應(yīng)內(nèi)容,然后點(diǎn)擊模板
在模板中選擇HTTP和SSH的模板鏈接,點(diǎn)擊提示器中的添加,然后再點(diǎn)擊添加