日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

持续集成mysql_持续集成环境搭建(5)zabbix搭建和使用

發(fā)布時(shí)間:2025/3/15 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 持续集成mysql_持续集成环境搭建(5)zabbix搭建和使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

zabbix源碼安裝

安裝mariadb(mysql)

// 執(zhí)行安裝命令

# yum -y install mariadb mariadb-server mariadb-devel

// 啟動(dòng)服務(wù)

# systemctl start mariadb

// 設(shè)置為開機(jī)啟動(dòng)

# systemctl enable mariadb

// 修改root登錄密碼

# mysql_secure_installation

Enter current password for root (enter for none): [回車]

Set root password? [Y/n] y

New password:

Re-enter new password:

Remove anonymous users? [Y/n] y

Disallow root login remotely? [Y/n] n

Remove test database and access to it? [Y/n] y

Reload privilege tables now? [Y/n] y

// 測試登陸

# mysql -uroot -ppassword

// 設(shè)置root訪問權(quán)限

# mysql -uroot -ppassword

MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by 'qwe123' with grant option;

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> exit;

安裝依賴庫

// 以下二選一

// 最小

# yum -y install gcc net-snmp-devel libxml2-devel libcurl-devel libevent libevent-devel

// 完全

# yum -y install gcc net-snmp-devel net-snmp net-snmp-utils libxml2 libxml2-devel libcurl libcurl-devel libevent libevent-devel

# cd /home

# tar -zxf zabbix-3.4.4.tar.gz

# cd zabbix-3.4.4

# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

# make && make install

初始化數(shù)據(jù)

# mysql -uroot -ppassword

MariaDB [none]> create database if not exists zabbix default character set utf8 collate utf8_general_ci;

MariaDB [none]> use zabbix;

MariaDB [zabbix]> source /home/zabbix-3.4.4/database/mysql/schema.sql;

MariaDB [zabbix]> source /home/zabbix-3.4.4/database/mysql/images.sql;

MariaDB [zabbix]> source /home/zabbix-3.4.4/database/mysql/data.sql;

安裝fping

zabbix 3之后把ping更換為fping了,所以需要安裝fping

# wget http://www.fping.org/dist/fping-4.0.tar.gz

# tar -zxvf fping-4.0.tar.gz

# cd fping-4.0

# ./configure --prefix=/usr/local/fping

# make && make install

配置

// server配置

# cd /usr/local/zabbix/

# vi ./etc/zabbix_server.conf

DBHost=localhost

DBName=zabbix

DBUser=root

DBPassword=password

AllowRoot=1

FpingLocation=/usr/local/fping/sbin/fping

// agent配置

# vi ./etc/zabbix_agentd.conf

Server=0.0.0.0/0

Hostname=Zabbix server #注釋掉

AllowRoot=1

啟動(dòng)服務(wù)

# /usr/local/zabbix/sbin/zabbix_server

# /usr/local/zabbix/sbin/zabbix_agent

配置前端環(huán)境

// 安裝apache+php

# yum -y install httpd httpd-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath

// 復(fù)制前端代碼到站點(diǎn)下

# cp -r /home/zabbix-3.4.4/frontends/php /var/www/html/zabbix

// 關(guān)閉防火墻

# systemctl stop firewalld

# setenforce 0

# vi /etc/selinux/config

SELINUX=disabled

// 修改php配置

# vi /etc/php.ini

memory_limit=128M

post_max_size=16M

upload_max_filesize=20M

max_execution_time=300

max_input_time=300

date.timezone=Asia/Shanghai

// 重啟站點(diǎn)

# systemctl restart httpd

zabbix配置Java Gateway

查看是否已經(jīng)安裝了zabbix_java

/usr/local/zabbix/sbin/zabbix_java/start.sh 是否存在

如未安裝,則進(jìn)入zabbix的源碼目錄,進(jìn)行zabbix_java的安裝

# cd /home/zabbix-3.4.4

# ./configure --prefix=/usr/local/zabbix --enable-java

# make && make install

修改zabbix_server的配置文件

# vi /usr/local/zabbix/etc/zabbix_server.conf

JavaGateway=localhost

JavaGatewayPort=10052

StartJavaPollers=5

然后重啟zabbix_server

啟動(dòng)zabbix_java

# /usr/local/zabbix/sbin/zabbix_java/startup.sh

zabbix配置mysql監(jiān)控

編輯腳本文件/usr/local/zabbix/etc/zabbix_agentd.conf.d/chk_mysql.sh

# vi /usr/local/zabbix/etc/zabbix_agentd.conf.d/chk_mysql.sh

#!/bin/bash

# 用戶名

MYSQL_USER='root'

# 密碼

MYSQL_PWD='asd123'

# 主機(jī)地址/IP

MYSQL_HOST='localhost'

# 端口

MYSQL_PORT='3306'

# 數(shù)據(jù)連接

MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"

# 參數(shù)是否正確

if [ $# -ne "1" ];then

echo "arg error!"

fi

# 獲取數(shù)據(jù)

case $1 in

Uptime)

result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"`

echo $result

;;

Com_update)

result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3`

echo $result

;;

Slow_queries)

result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"`

echo $result

;;

Com_select)

result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`

echo $result

;;

Com_rollback)

result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`

Questions)

result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"`

echo $result

;;

Com_insert)

result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`

echo $result

;;

Com_delete)

result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3`

echo $result

;;

Com_commit)

result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`

echo $result

;;

Bytes_sent)

result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`

echo $result

;;

Bytes_received)

result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3`

echo $result

;;

Com_begin)

result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`

echo $result

;;

*)

result=`${MYSQL_CONN} extended-status |grep -w "$1" |cut -d"|" -f3`

echo $result

;;

esac

編輯配置文件/usr/local/zabbix/etc/zabbix_agentd.conf.d/zabbix_mysql.conf

# vi /usr/local/zabbix/etc/zabbix_agentd.conf.d/zabbix_mysql.conf

#Mysql版本

UserParameter=mysql.version,mysql -V

# 獲取mysql性能指標(biāo),這個(gè)是上面定義好的腳本

UserParameter=mysql.status[*],/usr/local/zabbix/etc/zabbix_agentd.conf.d/chk_mysql.sh $1

# 獲取mysql運(yùn)行狀態(tài)

UserParameter=mysql.ping,mysqladmin -uroot -pqwe123 -P3306 -hlocalhost ping | grep -c alive

編輯zabbix_agentd的配置文件,加入zabbix_mysql.conf配置

# vi /usr/local/zabbix/etc/zabbix_agentd.conf

// 去掉#

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

重啟zabbix_agent

測試是否成功

# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -I 172.16.1.162 -k mysql.version

附錄: windows下的腳本

mysql_ping.vbs

Set objFS =CreateObject("Scripting.FileSystemObject")

Set objArgs = WScript.Arguments

str1 = getCommandOutput("mysqladmin -uroot -pqwe123 ping")

If Instr(str1,"alive") > 0Then

WScript.Echo 1

Else

WScript.Echo 0

End If

Function getCommandOutput(theCommand)

Dim objShell, objCmdExec

Set objShell =CreateObject("WScript.Shell")

Set objCmdExec = objshell.exec(thecommand)

getCommandOutput =objCmdExec.StdOut.ReadAll

end Function

mysql_status.vbs

Set objFS = CreateObject("Scripting.FileSystemObject")

Set objArgs = WScript.Arguments

str1 = getCommandOutput("mysqladmin -uroot -pqwe123 extended-status")

Arg = objArgs(0)

str2 = Split(str1,"|")

For i = LBound(str2) to UBound(str2)

If Trim(str2(i)) = Arg Then

WScript.Echo TRIM(str2(i+1))

Exit For

End If

next

Function getCommandOutput(theCommand)

Dim objShell, objCmdExec

Set objShell =CreateObject("WScript.Shell")

Set objCmdExec = objshell.exec(thecommand)

getCommandOutput =objCmdExec.StdOut.ReadAll

end Function

zabbix配置tomcat監(jiān)控

啟用tomcat的jmx

windows下,在catalina.bat 頭部增加

set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

linux下,在catalina.sh中,CATALINA_OUT前增加

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.2.207"

下載catalina-jmx-remote.jar到tomcat/lib下

修改tomcat的server.xml文件,加入以下代碼

啟動(dòng)tomcat

確認(rèn)zabbix_server啟用了Java Gateway,參考上面

在zabbix的控制臺(tái)添加主機(jī)JMX接口

172.16.1.162:12345

linux snmp配置

確認(rèn)snmp代理是否已安裝

# rpm -q net-snmp

如果未安裝,安裝snmp

# yum install net-snmp net-snmp-devel net-snmp-utils

修改配置 /etc/snmp/snmpd.conf

com2sec notConfigUser default public

#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

#access notConfigGroup "" any noauth exact systemview none none

access notConfigGroup "" any noauth exact mib2 none none

啟動(dòng)并設(shè)置為自啟動(dòng)

systemctl start snmpd

systemctl enable snmpd

zabbix自動(dòng)發(fā)現(xiàn)各網(wǎng)卡MAC地址

在zabbix控制臺(tái),找到模版Template Module Interfaces SNMPv2

Template Module Interfaces SNMPv2

選擇自動(dòng)發(fā)現(xiàn)規(guī)則

自動(dòng)發(fā)現(xiàn)規(guī)則

選擇Network Interfaces Discovery

Network Interfaces Discovery

選擇監(jiān)控項(xiàng)原型

監(jiān)控項(xiàng)原型

點(diǎn)擊按鈕創(chuàng)建監(jiān)控項(xiàng)原型

創(chuàng)建監(jiān)控項(xiàng)原型

按下圖填入相應(yīng)的內(nèi)容

MAC監(jiān)控項(xiàng)原型

zabbix配置ngnix監(jiān)控

啟用nginx status

// 下載nginx源碼,再用以下命令編譯安裝

# ./configure --with-http_stub_status_module

# make && make install

// 修改/usr/local/nginx/conf/nginx.conf,增加以下location

location /ngx_status {

stub_status on;

access_log off;

}

Active connections: 3

server accepts handled requests

3 3 1

Reading: 0 Writing: 1 Waiting: 2

編寫服務(wù)端獲取nginx信息的腳本文件ngx_status.sh

#!/bin/bash

HOST="192.168.2.207"

PORT="81"

# 檢測nginx進(jìn)程是否存在

function ping {

/sbin/pidof nginx | wc -l

}

# 檢測nginx性能

function active {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'

}

function reading {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'

}

function writing {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'

}

function waiting {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'

}

function accepts {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'

}

function handled {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'

}

function requests {

/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'

}

# 執(zhí)行function

$1

測試使用

zabbix_get -s localhost -k 'nginx.status[ping]'

配置監(jiān)控項(xiàng)

zabbix_proxy安裝和配置

安裝mariadb(mysql)

// 執(zhí)行安裝命令

# yum -y install mariadb mariadb-server mariadb-devel

// 啟動(dòng)服務(wù)

# systemctl start mariadb

// 設(shè)置為開機(jī)啟動(dòng)

# systemctl enable mariadb

// 修改root登錄密碼

# mysql_secure_installation

Enter current password for root (enter for none): [回車]

Set root password? [Y/n] y

New password:

Re-enter new password:

Remove anonymous users? [Y/n] y

Disallow root login remotely? [Y/n] n

Remove test database and access to it? [Y/n] y

Reload privilege tables now? [Y/n] y

// 測試登陸

# mysql -uroot -ppassword

// 設(shè)置root訪問權(quán)限

# mysql -uroot -ppassword

MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by 'qwe123' with grant option;

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> exit;

安裝依賴庫

# yum -y install gcc net-snmp-devel libssh2-devel

# cd /home

# tar -zxf zabbix-3.4.4.tar.gz

# cd zabbix-3.4.4

# ./configure --prefix=/usr/local/zabbix --enable-proxy --with-net-snmp --with-mysql --with-ssh2

# make && make install

初始化數(shù)據(jù)

# mysql -uroot -ppassword

MariaDB [none]> create database if not exists zabbix_proxy default character set utf8 collate utf8_general_ci;

MariaDB [none]> use zabbix_proxy;

MariaDB [zabbix]> source /home/zabbix-3.4.4/database/mysql/schema.sql;

安裝fping

zabbix 3之后把ping更換為fping了,所以需要安裝fping

# wget http://www.fping.org/dist/fping-4.0.tar.gz

# tar -zxvf fping-4.0.tar.gz

# cd fping-4.0

# ./configure --prefix=/usr/local/fping

# make && make install

配置

// server配置

# cd /usr/local/zabbix/

# vi ./etc/zabbix_proxy.conf

ProxyMode=0

Server=192.168.31.199(zabbix server)

Hostname=proxy01

DBHost=localhost

DBName=zabbix_proxy

DBUser=root

DBPassword=password

AllowRoot=1

FpingLocation=/usr/local/fping/sbin/fping

關(guān)閉防火墻

# systemctl stop firewalld

# setenforce 0

# vi /etc/selinux/config

SELINUX=disabled

啟動(dòng)服務(wù)

# /usr/local/zabbix/sbin/zabbix_proxy

在zabbix控制臺(tái)創(chuàng)建agent代理程序

創(chuàng)建agent代理程序

總結(jié)

以上是生活随笔為你收集整理的持续集成mysql_持续集成环境搭建(5)zabbix搭建和使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。