当前位置:网站首页>Prometheus + grafana + MySQL master-slave replication + host monitoring
Prometheus + grafana + MySQL master-slave replication + host monitoring
2022-06-28 07:59:00 【m0_ fifty-nine million four hundred and thirty thousand one hun】
List of articles
One 、 Host allocation
| Host name | ip Address | Deploy |
|---|---|---|
| prometheus + grafana | 192.168.8.18 | prometheus-2.27.1.linux-amd64.tar.gz/grafana-7.3.6-1.x86_64.rpm |
| master | 192.168.8.19 | node_exporter mysqld_exporter |
| slave | 192.168.8.20 | node_exporter mysqld_exporter |
Two 、 Master slave replication deployment
master:192.168.8.19
slave:192.168.8.20
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
1. Master slave time synchronization
#master
yum install -y ntp
vim /etc/ntp.conf # At the end of the line, add the following
server 127.127.8.0 # Set local clock source , Pay attention to modifying your own network segment
fudge 127.127.8.0 stratum 8 # Set the time level to 8( Restriction on 15 Inside )
systemctl start ntpd
------------------------------------------------------------------------------------------------
#slave
yum install -y ntp ntpdate
systemctl start ntpd
/usr/sbin/ntpdate 192.168.8.19 # Time synchronization
crontab -e # Set up scheduled tasks
*/30 * * * * /usr/sbin/ntpdate 192.168.8.19
2. Of the main server mysql To configure
vim /etc/my.cnf
# Add the following configuration
server-id = 1 # Definition server-id, Each host cannot be the same
log-bin=master-bin # The primary server turns on the binary log
binlog_format = MIXED # This use MIXED Pattern
log-slave-updates=true # Allows binary logs to be updated from the server
# Be careful :default-character-set=utf8 You need to comment this out , Otherwise, it will report a mistake
systemctl restart mysqld.service # Restart the service
# Set the slave server account and authorize
mysql -uroot -p123456
# Authorize the slave server
mysql> GRANT REPLICATION SLAVE ON *.* TO 'myslave'@'192.168.8.%' IDENTIFIED BY '123456';
mysql> flush privileges;
mysql> use mysql;
mysql> select user,host,authentication_string from user;
+-----------+-------------+-------------------------------------------+
| user | host | authentication_string |
+-----------+-------------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| myslave | 192.168.8.% | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 | 602 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
#File The column displays the log name ,Position Column shows the offset
3. From the server mysql To configure
vim /etc/my.cnf
server-id = 2 # Be careful id It cannot be the same as other hosts
relay-log=relay-log-bin # Turn on relay log , Synchronize log records from the primary server to the local
relay-log-index=slave-relay-bin.index # Define the location and name of the relay log file
relay_log_recovery = 1 # Optional items
# When slave After downtime from the library , If relay-log Damaged , Some relay logs are not processed , Then all the unimplemented relay-log,
And again from master Get log on , That's the guarantee relay-log The integrity of .
This feature is off by default , take relay_log_recovery Is set to 1 when , Can be found in slave Open this function from the library , Recommended Opening .
systemctl restart mysqld
mysql -uroot -p123456
# Configuration synchronization , Be careful master_log_file and master_log_pos The value of should be the same as Master Consistency of query
mysql> CHANGE master to master_host='192.168.8.19',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=602;
mysql> start slave; # Start the synchronization , If an error is reported, execute reset slave;
mysql> show slave status\G; # see Slave state , Make sure IO and SQL Threads are Yes, It means that the synchronization is normal

4. Master slave replication node authorization exporter
#master The node database is authorized to execute
create user 'exporter'@'%' identified by '123456';
create user 'exporter'@'127.0.0.1' identified by '123456';
create user 'exporter'@'localhost' identified by '123456';
grant process,replication client,select on *.* to 'exporter'@'%' identified by 'admin123';
grant process,replication client,select on *.* to 'exporter'@'127.0.0.1' identified by 'admin123';
grant process,replication client,select on *.* to 'exporter'@'localhost' identified by 'admin123';
flush privileges;
5. To configure mysql Indicator exposure of master-slave replication
Upload mysqld_exporter, To configure mysqld Indicator exposure of master-slave replication
master:192.168.8.19
slave:192.168.8.20
# Upload installation package mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local
cd /usr/local/mysqld_exporter-0.12.1.linux-amd64/ # Entry directory , create profile
cat > /usr/local/mysqld_exporter-0.12.1.linux-amd64/my.cnf << EOF [client] user=exporter password=admin123 EOF
cat > /usr/lib/systemd/system/mysqld_exporter.service << EOF [Unit] Description=mysqld_exporter After=network.target [Service] User=root Type=simple ExecStart=/usr/local/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter \ --config.my-cnf /usr/local/mysqld_exporter-0.12.1.linux-amd64/my.cnf \ --collect.info_schema.processlist Restart=on-failure [Install] WantedBy=multi-user.target EOF
systemctl daemon-reload
systemctl start mysqld_exporter.service
netstat -natp | grep 9104
6. To configure mysql Server indicator expose
master:192.168.8.19
slave:192.168.8.20
# Upload installation package node_exporter-1.1.2.linux-amd64.tar.gz
tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /opt
cd /opt
mv node_exporter-1.1.2.linux-amd64 node_exporter
cat > /usr/lib/systemd/system/node_exporter.service << EOF [Unit] Description=node_exporter Documentation=https://prometheus.io/ After=network.target [Service] Type=simple User=root ExecStart=/opt/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target EOF
systemctl daemon-reload
systemctl start node_exporter && systemctl enable node_exporter
netstat -antp | grep 9100
3、 ... and 、 Deploy prometheus
# Upload and unzip prometheus-2.27.1.linux-amd64.tar.gz
tar zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local
1. Modify the configuration file
cd /usr/local/prometheus-2.27.1.linux-amd64
vim prometheus.yml
# Finally insert :
- job_name: 'mysql-master-slave' # Define master-slave replication job
scrape_interval: 5s # Index data collection cycle
static_configs: # Static acquisition mode
- targets: ['192.168.8.19:9104','192.168.8.20:9104'] # Definition targets
- job_name: 'nodes' # Definition nodes Host information job
scrape_interval: 5s
static_configs:
- targets: ['192.168.8.19:9100','192.168.8.20:9100']
2. start-up prometheus
./prometheus
netstat -antp | grep prometheus
tcp 0 0 192.168.8.18:33584 192.168.8.19:9104 ESTABLISHED 45282/./prometheus
tcp 0 0 192.168.8.18:50022 192.168.8.20:9100 ESTABLISHED 45282/./prometheus
tcp 0 0 192.168.8.18:54936 192.168.8.19:9100 ESTABLISHED 45282/./prometheus
tcp 0 0 192.168.8.18:53908 192.168.8.20:9104 ESTABLISHED 45282/./prometheus
tcp6 0 0 :::9090 :::* LISTEN 45282/./prometheus
tcp6 0 0 ::1:9090 ::1:52512 ESTABLISHED 45282/./prometheus
tcp6 0 0 ::1:52512 ::1:9090 ESTABLISHED 45282/./prometheus
3. Log in to the browser to view

4. Deploy grafana-server
The account password defaults to admin,admin grafana
Default profile directory /etc/grafana/grafana.ini Direct access to
ip:3000 Get into grafana Console
# Upload installation package grafana-7.3.6-1.x86_64.rpm
yum -y install grafana-7.3.6-1.x86_64.rpm
systemctl start grafana-server
establish data sources choice prometheus
Definition prometheus node http://192.168.8.18:9090
Click on save & text
Click on "+" Input import , Select template 7371, choice prometheus data source -> save preservation mysqld-master-slave monitor
Click on "+" Input import , Select template 8919, choice prometheus data source -> save preservation mysqld nodes monitor
Click on dashboard Select the above two templates







边栏推荐
- Is it reliable to register and open an account for stock speculation? Is it safe?
- At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
- Recommended system series (Lecture 5): Optimization Practice of sorting model
- sql主從複制搭建
- Is it reliable to open a new bond registration account? Is it safe?
- 异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
- 推荐系统系列精讲(第五讲): 排序模型的调优实践
- SQL Master slave Replication Build
- sql分析(查询截取分析做sql优化)
- Resizing node of rediscluster cluster cluster mode
猜你喜欢
随机推荐
Design of DSP image data stream
Unity UI shadow component
你了解TCP协议吗(一)?
Implementation of commit message standardized control in large projects
HJ character count
Llvm and clang
How to configure DDR3 of dm8148
Helloword routine for ROS
Online WPS tool
协程、asyncio、异步编程
Redis master-slave structure and application scenarios
MySQL installation and environment variable configuration
Ambari (VII) --- ambari integrated hue4.2 document (valid for personal test)
你了解TCP协议吗(二)?
HJ delete the character with the least number of occurrences in the string
asp. Net to search products and realize paging function
Airflow2.1.1 ultra detailed installation document
HJ21 简单密码
Flex layout
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)









