Docker 에서 node exporter 를 실행하는 것은 권장하지 않는다는 글을 본 적이 있다.
Docker의 경우, 머신의 내부동작과 컨테이너를 격리시키려고 하기 때문에 노드 익스포터에서 내부 동작 결과가 작동하지 않을 수 있다는 이유 였다.
그래서 직접 node exporter 와 mysqld exporter 를 설치하는 과정을 Shell script로 작성해보았다.
[ 사전 준비 ]
- mysql 설치
node exporter
#!/bin/bash
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar -xvf node_exporter-0.18.1.linux-amd64.tar.gz
sudo mv node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
sudo cat > node_exporter.service <<-EOF
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=$User
Group=$User
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
sudo cp node_exporter.service /etc/systemd/system/node_exporter.service
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl status node_exporter
sudo systemctl enable node_exporter
sudo rm -f node_exporter-0.18.1.linux-amd64.tar.gz
mysqld exporter
#!/bin/bash
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
tar -xvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
sudo mv mysqld_exporter-0.13.0.linux-amd64/mysqld_exporter /usr/local/bin/
sudo chmod +x /usr/local/bin/mysqld_exporter
mysqld_exporter --version
# mysqld_exporter 명령어가 실행되는 지 확인해야함 ( echo $PATH 에 /usr/local/bin 디렉토리 경로 있는 지 확인)
password='Password'
echo -e "CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'Password' WITH MAX_USER_CONNECTIONS 2;\nGRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';\nFLUSH PRIVILEGES;\nexit\n" | mysql -u root -p'Password'
sudo cat > .mysqld_exporter.cnf <<-EOF
[client]
user=exporter
password='Password'
EOF
sudo cp .mysqld_exporter.cnf /etc/.mysqld_exporter.cnf
sudo rm -f .mysqld_exporter.cnf
sudo chown root:prometheus /etc/.mysqld_exporter.cnf
sudo cat > mysqld_exporter.service <<-EOF
[Unit]
Description=Prometheus MySQL Exporter
After=network.target
[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
EOF
sudo cp mysqld_exporter.service /etc/systemd/system/mysqld_exporter.service
sudo systemctl daemon-reload
sudo systemctl start mysqld_exporter
sudo systemctl enable mysqld_exporter
sudo systemctl status mysqld_exporter
sudo rm -f mysqld_exporter-0.13.0.linux-amd64.tar.gz
'AWS(Amazon Web Service) > Prom+Grafana+cAdvisor' 카테고리의 다른 글
Prometheus Architecture (0) | 2022.10.30 |
---|---|
[AWS] Prometheus+Grafana+cAdvisor 설치 (0) | 2021.11.19 |
[AWS] Prometheus+Grafana 설치 (2) (0) | 2021.11.17 |
[AWS] Prometheus+Grafana 설치 (1) (0) | 2021.11.16 |