持续集成mysql_持续集成环境搭建(5)zabbix搭建和使用
zabbix源碼安裝
安裝mariadb(mysql)
// 執行安裝命令
# yum -y install mariadb mariadb-server mariadb-devel
// 啟動服務
# systemctl start mariadb
// 設置為開機啟動
# 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
// 設置root訪問權限
# 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
初始化數據
# 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
啟動服務
# /usr/local/zabbix/sbin/zabbix_server
# /usr/local/zabbix/sbin/zabbix_agent
配置前端環境
// 安裝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
// 復制前端代碼到站點下
# cp -r /home/zabbix-3.4.4/frontends/php /var/www/html/zabbix
// 關閉防火墻
# 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
// 重啟站點
# systemctl restart httpd
zabbix配置Java Gateway
查看是否已經安裝了zabbix_java
/usr/local/zabbix/sbin/zabbix_java/start.sh 是否存在
如未安裝,則進入zabbix的源碼目錄,進行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
啟動zabbix_java
# /usr/local/zabbix/sbin/zabbix_java/startup.sh
zabbix配置mysql監控
編輯腳本文件/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'
# 主機地址/IP
MYSQL_HOST='localhost'
# 端口
MYSQL_PORT='3306'
# 數據連接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 參數是否正確
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 獲取數據
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性能指標,這個是上面定義好的腳本
UserParameter=mysql.status[*],/usr/local/zabbix/etc/zabbix_agentd.conf.d/chk_mysql.sh $1
# 獲取mysql運行狀態
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監控
啟用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文件,加入以下代碼
啟動tomcat
確認zabbix_server啟用了Java Gateway,參考上面
在zabbix的控制臺添加主機JMX接口
172.16.1.162:12345
linux snmp配置
確認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
啟動并設置為自啟動
systemctl start snmpd
systemctl enable snmpd
zabbix自動發現各網卡MAC地址
在zabbix控制臺,找到模版Template Module Interfaces SNMPv2
Template Module Interfaces SNMPv2
選擇自動發現規則
自動發現規則
選擇Network Interfaces Discovery
Network Interfaces Discovery
選擇監控項原型
監控項原型
點擊按鈕創建監控項原型
創建監控項原型
按下圖填入相應的內容
MAC監控項原型
zabbix配置ngnix監控
啟用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
編寫服務端獲取nginx信息的腳本文件ngx_status.sh
#!/bin/bash
HOST="192.168.2.207"
PORT="81"
# 檢測nginx進程是否存在
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}'
}
# 執行function
$1
測試使用
zabbix_get -s localhost -k 'nginx.status[ping]'
配置監控項
zabbix_proxy安裝和配置
安裝mariadb(mysql)
// 執行安裝命令
# yum -y install mariadb mariadb-server mariadb-devel
// 啟動服務
# systemctl start mariadb
// 設置為開機啟動
# 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
// 設置root訪問權限
# 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
初始化數據
# 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
關閉防火墻
# systemctl stop firewalld
# setenforce 0
# vi /etc/selinux/config
SELINUX=disabled
啟動服務
# /usr/local/zabbix/sbin/zabbix_proxy
在zabbix控制臺創建agent代理程序
創建agent代理程序
總結
以上是生活随笔為你收集整理的持续集成mysql_持续集成环境搭建(5)zabbix搭建和使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows mysql状态_wind
- 下一篇: mysql relay_技术分享 | M