標籤:源碼安裝mysql com 啟動 via 資訊 live 添加 自己 uri
剛開說mysql監控的時候 很容易遇到問題 而問題大部分出現在mysql的配置上面,看到我下面做的希望對你們有所協助,哈哈 不聊了 好好學習 現在開始
1.建立mysql使用者
[[email protected] ]# groupadd mysql
[[email protected] ]# mkdir -pv /data/mysql
[[email protected] ]# useradd -r -g mysql -d /data/mysql/ -s /sbin/nologin mysql
2.擷取mysql軟體包
[[email protected] y]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
3.安裝依賴包
[[email protected] ]# yum -y install cmake gcc* ncurses-devel
4.源碼安裝mysql
[[email protected] ]#tar zxvf /data/pkg/mysql-5.6.10.tar.gz
[[email protected] ]# cd mysql-5.5.49
[[email protected] mysql-5.5.49]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mysql-5.5.49]# make -j 4 && make install
[[email protected] mysql-5.5.49]# chown -R mysql.mysql /usr/local/mysql
[[email protected] mysql-5.5.49]# cd /usr/local/mysql/support-files/
5.拷貝mysql設定檔
[[email protected] support-files]# cp my-medium.cnf /data/mysql/my.cnf
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# chmod +x /etc/init.d/mysqld
6.初始化mysql
[[email protected] support-files]# cd /usr/local/mysql/scripts
[[email protected] scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
7.修改mysql的資料目錄
[[email protected] ]# cd / && more /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[[email protected] ]# mkdir -pv /var/lib/mysql/ && ln -s /tmp/mysql.sock /var/lib/mysql/
8.啟動mysql
[[email protected] ]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[[email protected] ]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
[[email protected] ]# service mysqld start
[[email protected] ]# mysqladmin -uroot password "123456"
9.登陸資料庫建立一個zabbix庫
[[email protected] ]# mysql -p123456
mysql> create database zabbix default charset utf8;
mysql> grant all privileges on zabbix.* to [email protected]‘localhost‘ identified by ‘zabbix‘;
mysql> flush privileges;
mysql> show databases;
mysql> quit
編寫一個新的mysql的設定檔因為我們會再mysql的 這個預設的模板中使用 userparameter_mysql.conf
[[email protected] scripts]# more /usr/local/zabbix/etc/.my.cnf
#zabbix_agent
[mysql]
host=localhost
user=zabbix
password=zabbix
socket=/tmp/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=zabbix
socket=/tmp/mysql.sock
[[email protected] scripts]#chmod 655 /usr/local/zabbix/etc/.my.cnf
下面要咋預設範本中配置使用到.my.cnf的設定檔
[[email protected] scripts]# more /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
然後重啟 zabbix_agentd
[[email protected] scripts]# service zabbix_agentd restart
剩下的你要添加模板
zabbix 監控nginx
在zabbix agentd用戶端上,查看nginx是否載入了–with-http_stub_status_module。因為zabbix監控nginx是根據nginx的Stub Status模組,抓取Status模組所提供的資料。假如以前沒開啟,現在想啟用StubStatus 模組,在編譯nginx 的時候要加上參數 –with-http_stub_status_module
檢查with-http_stub_status_module有沒有安裝
[[email protected] scripts]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.15
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
在zabbix.conf配置stub_status_module
啟動nginx
service nginx restart
用curl做測試
[[email protected] zabbix_agentd.conf.d]# curl http://47.93.232.219/nginx-status
Active connections: 2
server accepts handled requests
367 367 8631
Reading: 0 Writing: 1 Waiting: 1
狀態頁面各項資料的意義:
active connections – 當前 Nginx 正處理的活動串連數。
serveraccepts handled requests — 總共處理了 233851 個串連 , 成功建立 233851 次握手 (證明中間沒有失敗的 ), 總共處理了 687942 個請求 ( 平均每次握手處理了 2.94 個資料請求 )。
reading — nginx 讀取到用戶端的 Header 資訊數。
writing — nginx 返回給用戶端的 Header 資訊數。
waiting — 開啟 keep-alive 的情況下,這個值等於 active – (reading + writing), 意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留串連。
zabbix-agent 配置
有3個步驟,首先是編寫擷取Nginx資訊指令碼,接著配置中增加key資訊,然後重啟agent 服務。
①編寫Nginx監控指令碼,記住路徑,後面配置需要用到,注意指令碼許可權問題,agent運行使用者要能執行。
mkidr -p /usr/local/zabbix/scripts/
cd /usr/local/zabbix/scripts
vi nginx-check.sh
#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
# - anything available via nginx stub-status module
#
##################################
# Contact:
# [email protected]
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_URL="http://bbs.jzq.pub/nginx-status" #(這裡寫網站的網域名稱)
WGET_BIN="/usr/bin/wget"
#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
URL="$ZBX_REQ_DATA_URL"
else
URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
fi
#
# Extract data from nginx stats
#
case $ZBX_REQ_DATA in
active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d‘ ‘;;
accepted_connections) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f2 -d‘ ‘;;
handled_connections) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f3 -d‘ ‘;;
handled_requests) echo "$NGINX_STATS" | grep -Ev ‘[a-zA-Z]‘ | cut -f4 -d‘ ‘;;
reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d‘ ‘;;
writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d‘ ‘;;
waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d‘ ‘;;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
chmod o+x /usr/local/zabbix/scripts/nginx-check.sh
agent的設定檔 /etc/zabbix/zabbix_agentd.conf 中定義了其他key的包含目錄 Include=/etc/zabbix/zabbix_agentd.d/, 如果沒有這個配置請自己添加下。接著在 /etc/zabbix/zabbix_agentd.d/ 目錄建立一個檔案 nginx-params.conf, 內容如下
[[email protected] zabbix_agentd.conf.d]# more /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx-params.conf
UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx-check.sh "$1"
/etc/init.d/zabbix-agent restart
下面匯入nginx模板檔案
zabbix監控mysql,nginx