#!/bin/bash #基於LAMP架構安裝Zabbix # lamp(){
#關閉防火牆&核心安全功能
systemctl stop firewalld.service
systemctl disable firewalld.service &> /dev/null
setenforce 0
sed -i "7cSELINUX=disabled" /etc/sysconfig/selinuxphp
#下載安裝必要組件
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 \
expecthtml
#修改httpd的配置文件
sed -i -e "95aServerName www.kgc.com" -e "/DirectoryIndex/s/index.html/index.html index.php/" /etc/httpd/conf/httpd.confmysql
#修改PHP的時區
sed -i "878cdate.timezone = PRC" /etc/php.inilinux
#數據庫&httpd啓動
systemctl start httpd.service
systemctl enable httpd.service
systemctl start mariadb.service
systemctl enable mariadb.serviceweb
#設定數據庫初始密碼
/usr/bin/expect <<EOF
spawn mysqladmin -u root -p password 123123
expect {
"Enter*"
{send "\r"}
}
expect eof
EOFsql
}數據庫
#檢測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
fivim
#創建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 '123123';"
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 -p123123 zabbix
#修改zabbix服務端配置文件
sed -i "125cDBPassword=123123" /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
#重啓HTTP的服務
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://img-blog.csdnimg.cn/20200205193117319.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Nhb3poZW5ndGFvMTIxMw==,size_16,color_FFFFFF,t_70) ![在這裏插入圖片描述](https://img-blog.csdnimg.cn/20200206200439502.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Nhb3poZW5ndGFvMTIxMw==,size_16,color_FFFFFF,t_70) --- 配置代理端 ---
代理端就是被控服務器,若是服務器也須要被本身監控也須要安裝abbix-agent
```bash #關閉防火牆並設定開機自關 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行,指向監控服務器IP ServerActive=192.168.142.123 #139行,指向監控服務器IP Hostname=czt #150行,可自行定義主機名 #啓動服務 systemctl enable zabbix-agent.service systemctl start zabbix-agent.service #查看服務監聽端口 netstat -anpt | grep zabbix
訪問http://192.168.142.123/zabbix/配置-主機-建立主機:
配置下的主機選項,點擊建立主機
在主機配置界面填入相應內容,而後點擊模板
在模板中選擇HTTP和SSH的模板連接,點擊提示器中的添加,而後再點擊添加