#!/bin/bash
#基于LAMP架構(gòu)安裝Zabbix
#
lamp(){
#關(guān)閉防火墻&核心安全功能
systemctl stop firewalld.service
systemctl disable firewalld.service &> /dev/null
setenforce 0
sed -i "7cSELINUX=disabled" /etc/sysconfig/selinux
豐南ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
#下載安裝必要組件
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的時區(qū)
sed -i "878cdate.timezone = PRC" /etc/php.ini
#數(shù)據(jù)庫&httpd啟動
systemctl start httpd.service
systemctl enable httpd.service
systemctl start mariadb.service
systemctl enable mariadb.service
#設(shè)定數(shù)據(jù)庫初始密碼
/usr/bin/expect <
expect {
"Enter*"
{send "\r"}
}
expect eof
EOF
}
#檢測LAMP架構(gòu)是否已經(jīng)安裝完畢
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數(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;"
echo "開始準(zhǔn)備安裝zabbix"
sleep 3
#安裝PHP對應(yīng)工具
yum install php-bcmath php-mbstring -y
#生成zabbix對應(yīng)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
#解決本地?zé)o法登錄問題
mysql -uroot -p123123 -e "drop user ''@localhost;"
mysql -uroot -p123123 -e "drop user ''@localhost.localdomain;"
mysql -uroot -p123123 -e "flush privileges"
#生成數(shù)據(jù)庫文件
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p123123 zabbix
#修改zabbix服務(wù)端配置文件
sed -i "125cDBPassword=123123" /etc/zabbix/zabbix_server.conf
#修改時區(qū)
sed -i "20cphp_value date.timezone Asia/Shanghai" /etc/httpd/conf.d/zabbix.conf
#設(shè)定開機(jī)自啟
systemctl enable zabbix-server
#啟動服務(wù)
systemctl start zabbix-server
#重啟HTTP的服務(wù)
service httpd restart
#查看服務(wù)狀態(tài)
netstat -anpt | grep zabbix &> /dev/null
if [ $? -eq 0 ];then
echo "zabbix服務(wù)端設(shè)置完成"
fi
dizhi=ifconfig ens33 | awk 'NR==2{print $2}'
echo "請使用瀏覽器登陸${dizhi}/zabbix/進(jìn)行安裝
默認(rèn)登陸用戶名為:Admin
默認(rèn)登陸密碼為:zabbix"
- 登錄監(jiān)控平臺
![在這里插入圖片描述](/upload/otherpic67/20200205193117319.png)
![在這里插入圖片描述](/upload/otherpic67/20200206200439502.png)
---
配置代理端
---
代理端就是被控服務(wù)器,如果服務(wù)器也需要被自己監(jiān)控也需要安裝abbix-agent
```bash
#關(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
#修改如下內(nèi)容
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ī)名
#啟動服務(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)擊添加