网站建设资讯

NEWS

网站建设资讯

怎么安装配置Zabbix与LNMP

监控端操作

#!/bin/bash
#安装zabbix和LNMP
#
lnmp(){

#关闭防火墙&核心安全功能
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

#创建nginx安装源(centos可以根据不同系统进行替换,后面的版本同样)
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

#启动nginx
systemctl start nginx
systemctl enable nginx

#安装MySQL 5.7并启动
yum install -y mariadb-server mariadb expect
systemctl enable mariadb.service
systemctl start mariadb.service

#设定数据库初始密码
/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配置文件使其能识别php动态文件
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

#重启服务
systemctl start php-fpm
systemctl enable php-fpm
systemctl restart nginx
}

#检测LNMP架构是否已经安装完毕
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以适应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数据库和管理用户
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;"

#解决本地无法登录问题
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

#生成数据库文件
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123123 zabbix

#修改zabbix服务端配置文件
sed -i -e "91s/# //" -e "125cDBPassword=123123" /etc/zabbix/zabbix_server.conf

#工作目录提权
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/

#启动zabbix
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

#所有服务重启
systemctl restart php-fpm nginx mariadb zabbix-server zabbix-agent

#检查服务是否均启动
test=`netstat -atnp | egrep '(nginx|3306|10051|10050)' | grep -v "TIME_WAIT" | wc -l`
if [ $test -ge 5 ];then
    echo "zabbix服务端设置完成"
fi

dizhi=`ifconfig ens33 | awk 'NR==2{print $2}'`
echo "请使用浏览器登陆${dizhi}/zabbix/进行安装
默认登陆用户名为:Admin
默认登陆密码为:zabbix"

登录监控平台

怎么安装配置Zabbix与LNMP
怎么安装配置Zabbix与LNMP

10多年的南谯网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整南谯建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“南谯网站设计”,“南谯网站推广”以来,每个客户项目都认真落实执行。


配置代理端

代理端就是被控服务器,如果服务器也需要被自己监控也需要安装abbix-agent
#关闭防火墙并设定开机自关
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

在WEB平台上做增加被控主机,以便监控端识别

访问http://192.168.142.123/zabbix/配置-主机-创建主机:

  • 配置下的主机选项,点击创建主机
    怎么安装配置Zabbix与LNMP

  • 在主机配置界面填入相应内容,然后点击模板
    怎么安装配置Zabbix与LNMP

  • 在模板中选择HTTP和SSH的模板链接,点击提示器中的添加,然后再点击添加
    怎么安装配置Zabbix与LNMP

  • 新添加的监控项
    怎么安装配置Zabbix与LNMP

谢谢阅读!


网站名称:怎么安装配置Zabbix与LNMP
网站链接:http://cdweb.net/article/jjpohs.html