Mysql

為什麼 /etc/munin/plugin-conf.d/ 中的配置文件被忽略?

  • October 17, 2019

我有一個 Munin 腳本/etc/munin/plugins/mysql_replag,它查詢 MySQL 伺服器以檢查主從複製的狀態:

#!/bin/sh
# Plugin to monitor the Seconds_Behind_Master of replication on a MySQL slave

MYSQLOPTS="$mysqlopts"
MYSQL=${mysql:-mysql}
if [ "$1" = "autoconf" ]; then
       $MYSQL --version 2>/dev/null >/dev/null
       if [ $? -eq 0 ]
       then
               $MYSQL $MYSQLOPTS -e '' 2>/dev/null >/dev/null
               if [ $? -eq 0 ]
               then
                       echo yes
                       exit 0
               else
                       echo "no (could not connect to mysql)"
               fi
       else
               echo "no (mysql not found)"
       fi
       exit 1
fi

if [ "$1" = "config" ]; then
       echo 'graph_title Replication lag'
       echo 'graph_args --base 1000 -l 0'
       echo 'graph_vlabel lag in secs'
       echo 'graph_category mysql'
       echo 'lag.label lag'
       exit 0
fi

/usr/bin/printf "lag.value "
mysql $MYSQLOPTS -e 'show slave status\G' | grep Seconds_Behind_Master | awk '{print $2}'

外掛配置文件是/etc/munin/plugin-conf.d/mysql_replag:(注意:已編輯)

[mysql_replag]
user root
env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13

但是,在執行外掛時顯然會忽略外掛配置文件:

# munin-run mysql_replag 
lag.value ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

當我從配置文件中刪除 MySQL 選項並直接通過$MYSQLOPTS變數在外掛中指定它們時,該外掛起作用。為什麼忽略配置文件?

munin 中的變數是使用 env.myvariable 聲明的,而不是 env.var myvariable;試試這個:

env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13

我試圖mysql_queries使用這種格式配置外掛,因為這是我在下面找到的/usr/share/munin/plugins/mysql_

[mysql*]

env.mysqluser MyUser
env.mysqlpassword MyPassword

感謝 Patrice Levesque 的回复,我意識到一些 Mysql munin 外掛(例如mysql_queries)使用這種格式:

[mysql_queries]
env.mysqlopts -uMyUser -pMyPassword

引用自:https://unix.stackexchange.com/questions/225360