赞
踩
mkdir /opt/mysqld_exporter/
cd /opt/mysqld_exporter/
# 修改为自己的软件下载地址
wget http://soft.download/soft/linux/prometheus/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.14.0.linux-amd64.tar.gz
[root@shuan-node0132 mysqld_exporter-0.14.0.linux-amd64]# cat .my.cnf
[client]
host = localhost
user = reporter #mysql账号
password = 123456yuyuyut #mysql密码
port = 3308 #mysql端口
CREATE USER 'reporter'@'localhost' IDENTIFIED BY '123456yuyuyut' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'reporter'@'localhost';
vim /etc/systemd/system/mysqld_exporter.service
[Service]
ExecStart=/opt/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64/mysqld_exporter --config.my-cnf /opt/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64/.my.cnf
[Install]
WantedBy=multi-user.target
[Unit]
Description=mysqld_exporter
After=network.target
systemctl start mysqld_exporter
systemctl enable mysqld_exporter
firewall-cmd --permanent --add-port=9104/tcp --zone=public&&firewall-cmd --reload
cat install_mysqld_exporter.sh
#!/bin/bash InstallDir='/opt/mysqld_exporter/' FileName='mysqld_exporter-0.14.0.linux-amd64.tar.gz' function RedFont(){ echo -e "\033[31mError: $1 \033[0m" } function GreenFont(){ echo -e "\033[32mSuccess: $1 \033[0m" } function YellowFont(){ echo -e "\033[33mWarning: $1 \033[0m" } if [ ! -d "$InstallDir" ];then mkdir $InstallDir else YellowFont "${InstallDir}文件夹已经存在,请删除后重新执行" exit fi #进入安装目录 cd $InstallDir #下载安装包 wget http://soft.download/soft/linux/prometheus/mysqld_exporter/$FileName > /dev/null 2>&1 if [ $? -eq 0 ];then GreenFont "$FileName download success" else RedFont "$FileName download faild" exit fi #解压安装包到指定目录,解压不包含压缩一级目录 tar -zxf $FileName --strip-components 1 -C $InstallDir > /dev/null 2>&1 if [ $? -eq 0 ];then GreenFont "$FileName decompress success" else RedFont "$FileName decompress faild" exit fi #创建配置文件 cat > ${InstallDir}.my.cnf << EOF [client] host = localhost user = reporter #mysql账号 password = 123456yuyuyut #mysql密码 port = 3308 #mysql端口 EOF #设置开机自启 cat > /etc/systemd/system/mysqld_exporter.service << EOF [Service] ExecStart=${InstallDir}mysqld_exporter --config.my-cnf ${InstallDir}.my.cnf [Install] WantedBy=multi-user.target [Unit] Description=mysqld_exporter After=network.target EOF #防火墙放行端口 firewall-cmd --permanent --add-port=9104/tcp --zone=public&&firewall-cmd --reload #启动服务 systemctl daemon-reload systemctl enable mysqld_exporter systemctl start mysqld_exporter && GreenFont "started mysqld_exporter" || RedFont "start mysqld_exporter faild"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。