页面“Mysql 基础 Mysql study之常用操作”与“Monitoring with prometheus”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
 
第1行: 第1行:
==mysql study之常用操作==
+
==
  
=== 关闭 启动===
 
<pre>
 
本质关闭和启动的最直接就是他们了,启动脚本也是启用他们的
 
 
 
关闭mysql 数据库
 
mysqladmin --defaults-file=/etc/my.cnf -uroot -p'xx'  shutdown  2>&1
 
killall -15 mysqld
 
 
 
启动
 
mysqld_safe my.cnf
 
</pre>
 
 
=== 日常基本操作===
 
[[Sql 基础]]
 
 
CREATE DATABASE youdbname CHARACTER SET utf8mb4  COLLATE utf8mb4_general_ci; #创建库
 
#create database dbname default charset=utf8;
 
 
====SQL  select  DELETE  etc 语句====
 
 
DELETE FROM 表名称 WHERE 列名称 = 值
 
注意  del是不对的 例如
 
  
del hello_wallet.t_wallet_biz_transfer_apply where id = '1356131535272050002' ;
+
=book=
  
参考
+
[https://www.bookstack.cn/read/prometheus-book/README.md  Prometheus操作指南]
http://www.w3school.com.cn/sql/sql_delete.asp
+
=进阶=
 +
以后全改成自己 docker-compose build
  
 +
[https://blog.51cto.com/wzlinux/2487300 prometheus 监控概述(一)有常用监控警告]
  
 +
[https://blog.51cto.com/wzlinux/2490670 PromQL 内置函数(三)]
  
<pre>首次记录时间:2016年8月14日
 
有个哥说介绍一些mysql常用操作,于是有了此文
 
  
补充
 
RDBS, Relation data base system(关系型数据库系统),数据以二维表形式存储,每行(row)代表同一行数据,为记录
 
每列表示记录中的某个属性,为字段也
 
  
不能用 kill -9 因为会 自动重启 mysql service
+
[https://www.jb51.net/article/189679.htm  prometheus python 库编写自定义指标的方法(完整代码)]
root@debian:/# mysqladmin -pevan shutdown
 
root@debian:/h# ps -ef | grep mysqld
 
root 9950 5490 0 19:11 pts/0 00:00:00 grep mysqld
 
  
root@debian:# mysqladmin -pevan status
 
mysqladmin: connect to server at ‘localhost’ failed
 
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
 
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
 
  
rm -f /var/run/mysqld/mysqld.sock
+
[https://www.jianshu.com/p/19442595e886 promethues + python + flask监控后端服务状态]
  
root@debian:# mysqladmin -pevan status
+
[https://blog.csdn.net/weixin_33754913/article/details/91803530  prometheus python client]
Uptime: 19 Threads: 1 Questions: 2 Slow
 
  
p628 /etc/init.d/mysqld
+
[https://blog.csdn.net/JackLiu16/article/details/80381201?utm_medium=distribute.pc_relevant.none-task-blog-title-7&spm=1001.2101.3001.4242  使用Python和Flask编写Prometheus监控]
  
mysql> show variables like ‘%buffer%’;
+
[https://blog.csdn.net/specter11235/article/details/87927202 python开发prometheus exporter]
+——————————+———–+
 
| Variable_name | Value |
 
+——————————+———–+
 
| bulk_insert_buffer_size | 8388608 |
 
| innodb_buffer_pool_instances | 1 |
 
| innodb_buffer_pool_size | 134217728 |
 
| innodb_change_buffering | all |
 
| innodb_log_buffer_size | 8388608 |
 
| join_buffer_size | 131072 |
 
| key_buffer_size | 16777216 |
 
| myisam_sort_buffer_size | 8388608 |
 
| net_buffer_length | 16384 |
 
| preload_buffer_size | 32768 |
 
| read_buffer_size | 131072 |
 
| read_rnd_buffer_size | 262144 |
 
| sort_buffer_size | 2097152 |
 
| sql_buffer_result | OFF |
 
+——————————+———–+
 
  
mysqladmin
+
=ins on docker-composer=
 +
git clone https://github.com/evan886/docker-compose-monitor.git
  
#change the root password is 123456
 
mysqladmin -uroot -p password 123456
 
  
evan@debian:~/bakkali/software$ mysqladmin -uroot -p processlist
+
https://gitee.com/atompi/PrometheusStackDockerCompose
Enter password:
 
+—-+——+———–+—-+———+——+——-+——————+
 
| Id | User | Host | db | Command | Time | State | Info |
 
+—-+——+———–+—-+———+——+——-+——————+
 
| 53 | root | localhost | | Sleep | 118 | | |
 
| 54 | root | localhost | | Query | 1 | | show processlist |
 
+—-+——+———–+—-+———+——+——-+——————+
 
  
26.5 p639
+
=安全=
mysql> show tables;
 
+—————————+
 
| Tables_in_mysql |
 
+—————————+
 
| columns_priv |
 
| db |
 
| event |
 
| func |
 
| general_log |
 
| help_category |
 
| help_keyword |
 
 
 
mysql> describe user;
 
+————————+———————————–+——+—–+———+——-+
 
| Field | Type | Null | Key | Default | Extra |
 
+————————+———————————–+——+—–+———+——-+
 
| Host | char(60) | NO | PRI | | |
 
| User | char(16) | NO | PRI | | |
 
| Password | char(41) | NO | | | |
 
| Select_priv | enum(‘N’,’Y’) | NO | | N | |
 
| Insert_priv | enum(‘N’,’Y’) | NO | | N | |
 
| Update_priv | enum(‘N’,’Y’) | NO | | N | | </pre>
 
 
 
=====#创建表=====
 
 
<pre>
 
<pre>
CREATE TABLE IF NOT EXISTS employees ( #
+
node exporter 添加防火墙
  
EMPLOYEE_ID varchar(10) not null, #// EMPLOYEE_ID 字段的类型为varchar(10),字段值不允许为空
+
curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo
 +
# yum install node_exporter
 +
</pre>
  
FIRST_NAME varchar(10) not null,
+
=prometheus=
 +
[[Nginx用户密码认证配置 Basic HTTP authentication]]
  
LAST_NAME varchar(10) not null,
+
不错的书
 +
https://yunlzheng.gitbook.io/prometheus-book/
  
EMALL varchar(50) not null,
 
  
HIRE_DATE date, #date 类型
 
  
JOB_ID int not null,
 
  
SALARY int default 0, #//SALARY 字段默认值为0
+
[https://blog.csdn.net/lijiaocn/article/details/81865120 新型监控告警工具prometheus(普罗米修斯)的入门使用(附视频讲解)]
  
MANAGER_ID int ,
+
[https://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/08/03/prometheus-usage.html#prometheus%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6 【视频】新型监控告警工具prometheus(普罗米修斯)入门使用(附视频讲解)]
  
DEPARTMENT_ID int not null,
+
[https://zhuanlan.zhihu.com/p/91215371 为什么说 Prometheus 是足以取代 Zabbix 的监控神器?]
  
primary key (EMPLOYEE_ID) ) #// 主键为EMPLOYEE_ID
+
[https://zhuanlan.zhihu.com/p/24811652 基于Prometheus的分布式在线服务监控实践]
  
#// 使用数据库引擎为MyISAM
+
==usage==
 +
[https://www.jianshu.com/p/03cf0fc9c746 Grafana单图表告警邮件&面板图(Dashboard)日报邮件]
  
ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
[https://prometheus.io/docs/practices/rules/ Recording rules ]
 
 
CREATE TABLE `wallet`.`t_wallet_biz_benefit_mining_order`  (
 
  `id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主键',
 
  `order_no` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '订单编号',
 
  `user_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户ID',
 
  `activity_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '活动ID',
 
  `user_coin_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户钱包主键ID',
 
  `deposit_amount` decimal(28, 8) NULL DEFAULT NULL COMMENT '存入金额',
 
  `deposit_coin_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '存入币种ID',
 
  `cumulative_income` decimal(28, 8) NULL DEFAULT NULL COMMENT '累计收益',
 
  `income_coin_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '累计收益币种ID',
 
  `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态【1:计息中 2:已转出】',
 
  `current_weights` int(11) NULL DEFAULT NULL COMMENT '订单当前权重',
 
  `weight_update_time` datetime(0) NULL DEFAULT NULL COMMENT '权重更新时间',
 
  `weights_reset_time` datetime(0) NULL DEFAULT NULL COMMENT '权重重置时间',
 
  `expiration` datetime(0) NULL DEFAULT NULL COMMENT '订单过期时间',
 
  `mining_date` int(5) NULL DEFAULT NULL COMMENT '挖矿时长',
 
  `settlement_time` datetime(0) NULL DEFAULT NULL COMMENT '结算时间',
 
  `next_settlement_time` datetime(0) NULL DEFAULT NULL COMMENT '下次结算时间',
 
  `fund_apply_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '资金申请id',
 
  `remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
 
  `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
 
  `create_by` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
 
  `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
 
  `update_by` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人',
 
  `del_flag` tinyint(1) NULL DEFAULT NULL COMMENT '删除标记【 0:未删除,1:已删除】',
 
  PRIMARY KEY (`id`) USING BTREE
 
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '做市挖矿订单表' ROW_FORMAT = Dynamic;
 
</pre>
 
  
 +
https://github.com/prometheus/blackbox_exporter/blob/master/blackbox.yml
  
===== other =====
+
=grafana=
 
<pre>
 
<pre>
mysql> desc employees;
+
#防火墙  grafana ng 在 10.3.10.10
mysql> describe employees;
+
firewall-cmd  --permanent --add-rich-rule="rule family="ipv4" source address="10.3.10.10" port protocol="tcp" port="3000" accept "
+—————+————-+——+—–+———+——-+
+
firewall-cmd --reload
| Field | Type | Null | Key | Default | Extra |
 
+—————+————-+——+—–+———+——-+
 
| EMPLOYEE_ID | varchar(10) | NO | PRI | NULL | |
 
| FIRST_NAME | varchar(10) | NO | | NULL | |
 
| LAST_NAME | varchar(10) | NO | | NULL | |
 
| EMALL | varchar(50) | NO | | NULL | |
 
| HIRE_DATE | date | YES | | NULL | |
 
| JOB_ID | int(11) | NO | | NULL | |
 
| SALARY | int(11) | YES | | 0 | |
 
| MANAGER_ID | int(11) | YES | | NULL | |
 
| DEPARTMENT_ID | int(11) | NO | | NULL | |
 
+—————+————-+——+—–+———+——-+
 
9 rows in set (0.00 sec)
 
  
#######################
+
</pre>
修改新密码
 
  
set password for root@localhost = password('');
 
  
 +
[https://grafana.com/docs/grafana/latest/installation/docker/ grafana.com Run Grafana Docker image]
  
use mysql;
+
[https://grafana.com/grafana/dashboards/8919 中文 Node Exporte for Prometheus Dashboard]
update user set password=PASSWORD('evan') where user='root'; # on mysql 5.7
 
  
##最好要加这一行
+
usage  creat-->import --> id  8919
  
flush privileges;
+
Container
  
shell>mysqladmin -uroot -p password  新密码
 
#然后在提示符后输入老密码
 
  
增加新用户
 
  
格式:grant select on 数据库.* to 用户名@登录主机 identified by ‘密码’
+
https://grafana.com/grafana/dashboards/11174
举例:
 
例 1:增加一个用户 test1 密码为 abc,让他可以在任何主机上登录,并对所有数据库有
 
查询、插入、修改、删除的权限。首先用以 root 用户连入 MySQL,然后键入以下命令:
 
mysql>
 
grant select,insert,update,delete on *.* to test1@localhost identified by 'abc';
 
  
Query OK, 0 rows affected
+
#或者
+
docker-grafana/config.env  https://github.com/stefanwalther/docker-grafana/blob/master/config.env 
mysql>
 
grant all privileges on *.* to test1@localhost identified by 'abc';
 
  
flush privileges;
+
==grafana 添加源和数据 ==
  
删除用户
+
[https://www.bookstack.cn/read/prometheus-book/quickstart-use-grafana-create-dashboard.md 使用Grafana创建可视化Dashboard]
delete from user where user=’用户名’ and host=’localhost’;
 
delete from user where user='test2' and host='localhost';
 
  
flush privileges;
+
===Panel plugin not found: grafana-piechart-panel===
 +
<pre>
  
查看当前使用的数据库
+
升级为7.0.0就好了 不过要看其它模板还能用么
select database();
 
  
表操作
+
#这个放弃了 是在 6.x系列的  还不好用
 +
grafana-cli plugins install grafana-piechart-panel
  
备注:操作之前使用“use <数据库名>”应连接某个数据库。
+
docker-compose  restart  grafana
建表
 
命令:create table <表名> (<字段名 1> <类型 1> [,..<字段名 n> <类型 n>]);
 
  
create table mm(
 
  
id int(4) not null primary key auto_increment,
+
执行过程
 +
grafana-cli plugins install grafana-piechart-panel
 +
installing grafana-piechart-panel @ 1.6.1
 +
from: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.6.1/download
 +
into: /var/lib/grafana/plugins
  
name char(20) not null,
+
✔ Installed grafana-piechart-panel successfully
  
sex int(4) not null default '0',
+
Restart grafana after installing plugins . <service grafana-server restart>
  
degree double(16,2))
+
[https://github.com/unifi-poller/unifi-poller/issues/248 RESOLVED: Panel plugin not found: table-old ]
  
#ENGINE=InnoDB;
 
  
ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
</pre>
 +
[https://www.jianshu.com/p/153d944ab836 Panel plugin not found: grafana-piechart-panel]
  
查看表结构
+
==grafana 添加用户 ==
命令: desc 表名,  show create table 表名; 或者show columns from 表名
+
<pre>
mysql> describe my;
+
1.Users-->  2.Invite -->  
  
mysql> desc my;
+
3.进行邀请
 +
Email or Username:输入用户邮箱,建议先跟用户名保持相同,然后在后面在写邮箱,后面会说到,这样不会报错
 +
Name:输入用户名
 +
Role:配置用户权限(只读Viewer 编辑Editor 管理员Admin)
 +
Send invite email:勾选时,会将新用户的设置密码的链接发到邮箱
  
show columns from my;
+
点击创建之后回调到新用户设置密码
  
删除表
+
-->
drop table
 
  
插入数据
+
4.创建好之后,点击Pending Invites
命令:insert into <表名> [( <字段名 1>[,..<字段名 n > ])] values ( 值 1 )[, ( 值 n )]
+
复制链接到浏览器的地址栏中访问(也可从邮件中收到链接)
mysql> insert into my values(1,'tom',0,96);
+
进去之后是下面的界面,这里有个坑,复制的IP地址是localhost,我们这里改为自己搭建的IP地址,然后在Email填写邮箱地址,设置新用户的密码
 +
设置完成后,会直接以新用户身份登陆
  
mysql> insert into my(name,sex,degree) values('evan',1,90);
 
  
查询表中的数据
+
http://localhost:3000/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa
mysql> select * from my;
 
+—-+——+—–+——–+
 
| id | name | sex | degree |
 
+—-+——+—–+——–+
 
| 1 | tom | 0 | 96.00 |
 
| 2 | evan | 1 | 90.00 |
 
+—-+——+—–+——–+
 
  
#select 2020
+
http://a.linuxsa.org/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa
#前 2 行数据
 
select * from my limit 0,2;
 
  
select * from my order by id limit 0,2;
+
  -->
  
UPDATE hello_wallet.t_wallet_user SET trade_lock_status = 0 WHERE telephone = '185206773';
+
</pre>
select  *  from  hello_wallet.t_wallet_user  where  telephone = '185206773'\G
 
  
删除表中数据
+
[https://blog.csdn.net/liuxiangyang_/article/details/86737103  grafana的用户及权限的配置]
命令:delete from 表名 where 表达式
 
delete from my where id=2;
 
  
修改表中数据
+
[https://blog.csdn.net/GX_1_11_real/article/details/85119451  grafana的用户及权限的配置]
命令:update 表名 set 字段=新值,… where 条件
 
update my set name=’eva’ where id=1;
 
mysql> select * from my order by id limit 0,2;
 
+—-+——+—–+——–+
 
| id | name | sex | degree |
 
+—-+——+—–+——–+
 
| 1 | eva | 0 | 96.00 |
 
+—-+——+—–+——–+
 
  
在表中增加字段
+
[https://blog.csdn.net/kozazyh/article/details/93759717?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase  grafana-利用Google OAuth2 身份验证]
命令:alter table 表名 add 字段 类型 其他;
 
例如:在表 MyClass 中添加了一个字段 pass,类型为 int(4),默认值为 0
 
mysql> alter table my add pass int(4) default '0';
 
  
更改表名
+
== ng config==
命令:rename table 原表名 to 新表名;
+
<pre>
rename table my to mm;
+
cat gf.conf
 +
server
 +
{
 +
    listen 80;
 +
    server_name gf.linuxsa.org;
 +
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 +
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
  
更新字段内容
 
命令:update 表名 set 字段名 = 新内容
 
update 表名 set 字段名 = replace(字段名, ‘旧内容’, ‘新内容’);
 
update my set name='nick' where name='eva';
 
  
update my set name=replace(name,'jkjk','evan');
+
    client_max_body_size 10m;
 +
 
 +
    location / {
 +
      proxy_pass http://10.3.10.124:3000;
 +
      proxy_http_version 1.1;
  
数据库导入导出
+
#set_real_ip_from 10.0.0.0/8;
 +
#set_real_ip_from 172.16.0.0/12;
 +
#set_real_ip_from 192.168.0.0/16;
 +
#real_ip_header X-Forwarded-For;
  
将数据库 com 中的 my 导出到 文件中
+
        proxy_set_header        Host                $host;
mysqldump -uroot -pevan com my > my.sql
+
        proxy_set_header        X-Real-IP            $remote_addr;
 +
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 +
        proxy_set_header        X-Remote-Port        $remote_port;
 +
        proxy_set_header        X-Forwarded-Proto    $scheme;
 +
        proxy_redirect          off;
  
数据库 mydb 的结构导出到 e:\MySQL\mydb_stru.sql 文件中
+
          proxy_connect_timeout 1800s;
mysqldump -uroot -pevan com --add-drop-table >com.stru.sql
+
          proxy_send_timeout 1800s;
 +
          proxy_read_timeout 1800s;
  
导出结构不导出数据 Fri Aug 21 10:48:02 CST 2020
 
mysqldump --opt -d 数据库名 -u root -p > xxx.sql
 
  
只导出数据不导出数据结构
 
mysqldump -u [数据库用户名] -p -t [要备份的数据库名称]>[备份文件的保存路径]
 
mysqldump -uroot -pevan -t com >com0.sql
 
  
#here
+
      real_ip_recursive on;
导出数据库中的Events
+
#      real_ip_header X-Forwarded-For;
格式:mysqldump -u [数据库用户名] -p -E [数据库用户名]>[备份文件的保存路径]
+
#     set_real_ip_from 0.0.0.0/0;
 +
#      proxy_set_header Host            $host;
 +
#      proxy_set_header X-Real-IP $remote_addr;
 +
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
导出数据库中的存储过程和函数
 
格式:mysqldump -u [数据库用户名] -p -R [数据库用户名]>[备份文件的保存路径]
 
  
从外部文件导入数据库中
+
#proxy_set_header Host            $host:$server_port;
1)使用“source”命令
+
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 +
#proxy_set_header X-NginX-Proxy true;
  
2)使用 “<” 小于符号 *************************************** ##20160819 26.5.4 改变表结果 ALTER TABLE 数据表名 更改1 [,更改2 …] #添加TELPHONE 字段 ALTER TABLE employees add TELPHONE char(20); #更改字段 change alter table employees change TELPHONE TEL char(20); ##更改字段 类型 modify alter table employees modify TEL varchar(20); ##删除 字段 drop alter table employees drop tel; #表改名 rename alter table employees rename to emp; 26.5.5 复制数据表 CREATE TABLE 新表名 LIKE 源表名 create table employees2 like employees; #只复制了表结构, 要复制结构和数据的 为 create table emp3 select * from emp; 26.5.6 删除数据表 DROP TABLE tablename; 26.6 数据管理 26.6.1查询数据 SELECT * | 字段列表 FROM 数据表 WHERE 条件; 1.所以数据 select * from emp; 2.某些字段的数据 mysql> select EMPLOYEE_ID, last_name,salary from emp;
+
#     proxy_set_header X-Real-IP        $remote_addr;
+————-+————+——–+
+
#     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
| EMPLOYEE_ID | last_name | salary |
+
#     proxy_set_header Upgrade $http_upgrade;
+————-+————+——–+
+
#     proxy_set_header Connection "upgrade";
| kyct | [email protected] | 9 |
+
    }
+————-+————+——–+
+
}
  
3,满足某些条件的数据
+
</pre>
mysql> select EMPLOYEE_ID, last_name,salary from emp where salary < 10000; +————-+————+——–+ | EMPLOYEE_ID | last_name | salary | +————-+————+——–+ | kyct | [email protected] | 9 | +————-+————+——–+ 4.查询数据的总数 mysql> select count(*) from emp;
 
+———-+
 
| count(*) |
 
+———-+
 
| 1 |
 
+———-+
 
  
26.6.2 插入
+
==使用教程==
INSERT INTO 表名(字段1, 字段2, …) VALUES (值1,值2,…);
+
[https://yuerblog.cc/2019/01/04/grafana-usage/ grafana配置与简单使用]
INSERT INTO 表名(字段1, 字段2, …) SELECT 字段1, 字段2, …) FROM 源表;
 
  
mysql> desc emp;
+
[https://blog.csdn.net/bbwangj/article/details/81109615  Grafana使用教程]
+—————+————-+——+—–+———+——-+
 
| Field | Type | Null | Key | Default | Extra |
 
+—————+————-+——+—–+———+——-+
 
| EMPLOYEE_ID | varchar(10) | NO | PRI | NULL | |
 
| FIRST_NAME | varchar(10) | NO | | NULL | |
 
| LAST_NAME | varchar(10) | NO | | NULL | |
 
| EMALL | varchar(50) | NO | | NULL | |
 
| HIRE_DATE | date | YES | | NULL | |
 
| JOB_ID | int(11) | NO | | NULL | |
 
| SALARY | int(11) | YES | | 0 | |
 
| MANAGER_ID | int(11) | YES | | NULL | |
 
| DEPARTMENT_ID | int(11) | NO | | NULL | |
 
+—————+————-+——+—–+———+——-+
 
  
mysql> insert into emp values (‘kyct’,’kyct’,’kyct@g.com’,7,’2016-08-20′,3,9,8,9);
+
[https://blog.csdn.net/Sagitarioo/article/details/102805852?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2  grafana数据可视化-使用教程]
  
insert into emp (employee_id,LAST_NAME,job_id) values (10888,’jim’,5);
+
[https://www.cnblogs.com/xkus/p/7462742.html  grafana快速入门 ]
  
2. 插入其它有的数据
+
[https://blog.csdn.net/u012062455/article/details/79214700  grafana使用教程之基本概念(basic concepts)]
mysql> create table emp2 like emp;
 
Query OK, 0 rows affected (0.34 sec)
 
  
mysql> select * from emp2;
+
[https://blog.csdn.net/weixin_42674978/article/details/102681969  Grafana从无到有的一个相当粗略的资料总结]
  
mysql> insert into emp2 select * from emp where employee_id=10888;
 
Query OK, 1 row affected, 1 warning (0.00 sec)
 
Records: 1 Duplicates: 0 Warnings: 1
 
  
mysql> select * from emp2;
+
[https://blog.csdn.net/Sagitarioo/article/details/102805852?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2  grafana数据可视化-使用教程]
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMALL | HIRE_DATE | JOB_ID | SALARY | MANAGER_ID | DEPARTMENT_ID |
 
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
| 10888 | | jim | | NULL | 5 | 0 | NULL | 0 |
 
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
  
26.6.3 更新数据
+
[https://ken.io/note/grafana-quickstart-influxdb-datasource-graph Grafana快速入门:InfluxDB数据源以及曲线图表仪表盘配置]
UPDATE 表名 SET 字段1 = 值1 [,字段2 = 值2 …] WHERE 查询条件;
 
  
mysql> select * from emp2;
 
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMALL | HIRE_DATE | JOB_ID | SALARY | MANAGER_ID | DEPARTMENT_ID |
 
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
| 10888 | | jim | | NULL | 5 | 0 | NULL | 0 |
 
+————-+————+———–+——-+———–+——–+——–+————+—————+
 
  
mysql> update emp2 set emall=’jim@gamil.com’,salary=2000 where last_name=’jim’;
+
[https://www.cnblogs.com/fatyao/p/11192234.html Grafana报警]
  
mysql> select * from emp2;
 
+————-+————+———–+—————+———–+——–+——–+————+—————+
 
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMALL | HIRE_DATE | JOB_ID | SALARY | MANAGER_ID | DEPARTMENT_ID |
 
+————-+————+———–+—————+———–+——–+——–+————+—————+
 
| 10888 | | jim | [email protected] | NULL | 5 | 2000 | NULL | 0 |
 
+————-+————+———–+—————+———–+——–+——–+————+—————+
 
  
26.6.4 删除数据
+
apached conf
DELETE FROM 表名 WHERE 查询条件;
+
<pre>
delete from emp where last_name=’jim’;
+
##/etc/httpd/conf.d/gf.conf
  
26.7 索引管理
 
  
26.7.1 创建索引
+
<VirtualHost *:80>
mysql> create table depar (
+
      ServerName gf.linuxsa.org
-> depa_id char(10) not null,
+
      ServerAlias gf.linuxsa.org
-> depa_name varchar(50) not null,
+
   
-> mana_id char(10),
+
      ProxyRequests off
-> index ind_depa01 (depa_id) //创建索引ind_depa01
+
   
-> );
+
      <Proxy *>
 +
        Order deny,allow
 +
        Allow from all
 +
      </Proxy>
 +
   
 +
      <Location />
 +
        ProxyPass http://localhost:3000/
 +
        ProxyPassReverse http://localhost:3000/
 +
      </Location>
 +
    </VirtualHost>
  
#上面为创建表depar的同时,在 depa_id 字段创建一个名为 ind_depa01 的索引
+
</pre>
如果表已存在 CREATE INDEX
 
 
 
CREATE [UNIQUE] INDEX 索引名 ON 表名 (字段1 [,字段2 …]);
 
create unique index ind_depa02 on dep(EMPLOYEE_ID);
 
 
 
#表emp 的 EMPLOYEE_ID 字段上,创建一个名为 ind_depa02 的唯一索引
 
create unique index ind_depa02 on emp(EMPLOYEE_ID);
 
 
 
26.7.2 删除索引
 
DROP INDEX 索引名 ON 表名
 
 
 
26.8 用户和权限管理
 
 
 
mysql> select host,user,password,select_priv from user;
 
+———–+——————+——————————————-+————-+
 
| host | user | password | select_priv |
 
+———–+——————+——————————————-+————-+
 
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y |
 
| debian | root | *CB0AB6862555C52CBE5D736D089D8D56A468AE12 | Y |
 
| 127.0.0.1 | root | *CB0AB6862555C52CBE5D736D089D8D56A468AE12 | Y |
 
| ::1 | root | *CB0AB6862555C52CBE5D736D089D8D56A468AE12 | Y |
 
| localhost | debian-sys-maint | *E7BF66CEE2E00177E47E00EDE25DAFADF8AADF17 | Y |
 
+———–+——————+——————————————-+————-+
 
 
 
26.8.2 用户管理
 
 
 
1.添加
 
#add user 记得要刷新权限表
 
insert into user (host,user,password) values(‘%’,’test’,password(‘123456’));
 
flush privileges;
 
 
 
2.用户查看
 
#查看所有用户 在这个新授权时非常有用 也就是看用户是不是已存在
 
mysql> SELECT user,host,password FROM mysql.user;
 
 
 
#查看MySQL的当前用户
 
mysql> SELECT USER();
 
 
 
 
 
 
 
3.更新口令
 
mysql> update user set password=password(‘1234′) where user=’test’;
 
mysql> flush privileges;
 
 
 
delete from user where user=’test’;
 
 
 
26.8.3 用户授权
 
 
 
GRANT 权限[(字段)] ON 数据库名.表名 TO 用户名@域名或者ip 地址 [ IDENTIFIED BY ‘口令’ ] [ WITH GRANT OPTION
 
];
 
 
 
1.授权数据库中所有的对象的权限
 
hr库中所有的表的查询权限授给 evan
 
grant select on hr.* to evan;
 
 
 
2.授权数据库中个别对象的权限
 
 
 
#库hr中数据表emp 的查询和更新权限授给 test用户
 
mysql> grant select on hr.emp to test;
 
 
 
mysql> grant update on hr.emp to test;
 
 
 
3.控制访问的主机
 
grant all on dbname.tablename to user@’ip’;
 
 
 
4.
 
授test 用户 hr.emp 表的删除权限,并允许test 把该项权限授其它的用户
 
grant delete on hr.emp to test with grant option;
 
 
 
5 创建用户
 
 
 
grant select on evan.emp to sam identified by ‘123’;
 
 
 
mysql> select host,user,password from user;
 
+———–+——————+——————————————-+
 
| host | user | password |
 
+———–+——————+——————————————-+
 
| % | test | *A4B6157319038724E3560894F7F932C8886EBFCF |
 
| % | evan | |
 
| % | sam | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
 
+———–+——————+——————————————-+
 
CREATE USER evan@localhost IDENTIFIED BY ‘1234’;
 
 
 
26.8.4 回收权限
 
 
 
 
 
REVOKE 权限 [( 字段)] ON dbname.tablename from user@ip
 
 
 
revoke select on hr.* from test;
 
 
 
mysql创建用户以及授权
 
http://blog.linuxchina.net/?p=1344
 
 
 
mysql授权查看
 
http://blog.linuxchina.net/?p=950
 
  
 +
=vm监控[[Node-exporter]]=
 +
可以如上的  node
 +
[[Node-exporter]]
  
 +
=Blackbox=
  
26.9 mysql 备份恢复 (5种 mysqldump,mysqlhocopy,sql,binlog,直接备份数据文件 )
+
[[Blackbox exporter]]
  
26.9.1 mysqldump
+
=pushgateway=
1. 导出指定的表,不指定将导出库中的所有表
 
mysqldump [options] dbname [table]
 
  
2.导出一个多个指定数据库中的所有表
+
[[pushgateway]]
mysqldump [options] –database dbname1 [dbname2,…]
 
  
3.导出系统中所有数据库
+
[https://www.cnblogs.com/xiao987334176/p/9933963.html  基于Prometheus的Pushgateway实战 ]
mysqldump [options] –all-databases
 
  
常用的选项
+
https://songjiayang.gitbooks.io/prometheus/content/pushgateway/how.html
–databases,-B 指定要导出的库
 
-default-character-set=charset_name 默认字符集
 
–ignore-table=dbname.tablename #忽略的表,不导出
 
–lock-all-tables, -X 导出前,锁定所以的数据表,保持系统数据的一致
 
–lock-tables, -l 锁定当前导出的数据表 #这个用处应该比较多
 
–log-error=filnename 保存错误和警告日志到文件
 
–no-create-db, -n 只导出数据,不导出CREATE TABLE 语句
 
–no-data, -d 只导出表结构,不导出数据
 
–routines, -R 导出存储过程和函数
 
  
1.备份表
+
=[[Process-exporter]]=
mysqldump -uroot -p dbname table >table.sql
 
  
2.整个库
+
=应用监控=
mysqldump -uroot -p –database dbname > db.sql
+
==redis==
 +
[[prometheus监控Redis集群]]
  
3.只导出表结构
+
[https://blog.csdn.net/weixin_43832846/article/details/90024274  pika主备部署(redis-sentinel)+监控(prometheus+grafana)]
mysqldump -uroot -p –no-data dbname table >table.sql
 
  
4.恢复数据
+
[https://blog.csdn.net/weixin_34289744/article/details/92725774?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-16.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-16.nonecase  Prometheus监控 Redis , redis-cli_exporter]
mysql -uroot -p dbanne < file.sql
 
或者 source
 
  
****************************************************************
+
==监控MQ==
 +
[https://www.rabbitmq.com/prometheus.html  Monitoring with Prometheus & Grafana ]
  
26.9.2 mysqlhotcopy 感觉不好用
+
==监控ES==
其实是使用lock tables cp scp 来完成备份的 只能备份myisam存储引擎
+
https://github.com/slok/ecs-exporter
1.备份
+
==docker==
 +
[https://blog.csdn.net/palet/article/details/82889493?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase  Prometheus+grafana监控:cAdvisor输出的容器内存相关的指标的解读]
  
2.恢复 直接是 cp -Rf src targer
+
== mysql==
 +
[https://blog.csdn.net/qq_25934401/article/details/82594478  prometheus 监控之 mysql 篇(含mysql报警规则)]
  
26.9.3 使用SQL语句备份和恢复
+
[https://jiajunhuang.com/articles/2018_12_16-prometheus_mysqld_exporter.md.html Prometheus MySQL Exporter源码阅读与分析]
BACKUP TABLE ,SELECT NITO OUTFILE
 
  
26.9.4 二进制日志(binlog)
+
[https://www.jianshu.com/p/27b979554ef8 python + promethues 监控mysql]
恢复
 
mysqlbinlog -d games_s25 --start-datetime="2016-07-25 02:05:00" --stop-datetime="2016-07-25 04:40:00" "mysql-bin.000201" | mysql -uroot -ppassword
 
  
26.9.5 直接备份数据文件 ,flush tablename with read lock;#会比较 好
+
==Spring boot==
MySQL基本操作
+
https://www.bookstack.cn/read/prometheus_practice/application-spring.md
  
  
#其它
+
[https://blog.csdn.net/liangcha007/article/details/86699013#7.%E5%85%B3%E4%BA%8Epushgateway  Prometheus基于java开发exporter样例以及pushgateway的应用]
#查看当前写入的日志
 
mysql> show master status ;
 
  
#查看某一库的字符集
+
=ng conf=
 
 
mysql> show create database test;
 
 
 
 
 
#查看MySQL支持的字符集
 
1
 
mysql> show character set ;
 
#查看默认字符集
 
 
 
mysql> show variables like '%char%';
 
 
 
查看某一表的字符集
 
mysql> show create table test.t1 \G
 
 
 
#修改字符集
 
 
 
mysql>alter database mydb character set utf-8;
 
#可以直接在配置文件中做添加,然后重启服务
 
 
 
[client]
 
character_set_server = utf8
 
 
[mysqld]
 
character_set_server = utf8  </pre>
 
 
 
==== 表操作(创建和插入)====
 
 
<pre>
 
<pre>
create table t1(name varchar(20),fa char(1));
+
cat  alert.conf
  insert into t1 values("e","m");
+
server
 +
{
 +
    listen 80;
 +
    server_name alert.com;
 +
#    access_log /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 +
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
  
create table t2(name varchar(20),fa char(1));
 
insert into t2 values("t","m");
 
  
 +
    client_max_body_size 10m;
 +
 
 +
    location / {
 +
  #      auth_basic "Prometheus";
 +
  #      auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
 +
      proxy_pass http://10.3.10.124:9093;
 +
      proxy_http_version 1.1;
  
DROP TABLE IF EXISTS `t_teacher`;
+
#s#et_real_ip_from 10.0.0.0/8;
CREATE TABLE `t_teacher` (
+
#set_real_ip_from 172.16.0.0/12;
  `id` int(11) NOT NULL,
+
#set_real_ip_from 192.168.0.0/16;
  `t_name` varchar(255) DEFAULT NULL,
+
#real_ip_header X-Forwarded-For;
  PRIMARY KEY (`id`)
+
        proxy_set_header        Host                $host;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
        proxy_set_header        X-Real-IP            $remote_addr;
 +
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 +
        proxy_set_header        X-Remote-Port        $remote_port;
 +
        proxy_set_header        X-Forwarded-Proto    $scheme;
 +
        proxy_redirect          off;
 +
          proxy_connect_timeout 1800s;
 +
          proxy_send_timeout 1800s;
 +
          proxy_read_timeout 1800s;
  
 +
      real_ip_recursive on;
 +
#      real_ip_header X-Forwarded-For;
 +
#      set_real_ip_from 0.0.0.0/0;
 +
#      proxy_set_header Host            $host;
 +
#      proxy_set_header X-Real-IP $remote_addr;
 +
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
新添加字段  del_flag之后
 
  
ALTER TABLE `wallet`.`t_wallet_biz_withdraw_apply`  ADD COLUMN `fee_fund_apply_id` varchar(30) NULL COMMENT '手续费资金申请ID' AFTER `del_flag`;
+
#proxy_set_header Host            $host:$server_port;
 +
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 +
#proxy_set_header X-NginX-Proxy true;
  
</pre>
+
#      proxy_set_header X-Real-IP        $remote_addr;
 +
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 +
#      proxy_set_header Upgrade $http_upgrade;
 +
#      proxy_set_header Connection "upgrade";
 +
    }
 +
}
  
清空数据
 
RUNCATE TABLE table
 
  
==== 表操作(update)====
 
<pre>
 
  
UPDATE t_market_timer_task set status=1 where task_id=1;
+
cat pro.conf
 +
server
 +
{
 +
    listen 80;
 +
    server_name pro.linuxsa.org;
 +
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 +
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
  
ySQL [market]> select  * from  t_market_timer_task where task_id=1;
 
+---------+--------------------------+--------------------------+-----------------+--------+-------------------------------------------------------------+---------+---------------------+-----------+---------------------+-----------+----------+
 
| task_id | task_name                | task_describe            | cron_expression | status | job_class                                                  | remarks | create_time        | create_by | update_time        | update_by | del_flag |
 
+---------+--------------------------+--------------------------+-----------------+--------+-------------------------------------------------------------+---------+---------------------+-----------+---------------------+-----------+----------+
 
| 1      | Global-MarketOverviewJob |数据拉取        | 0 0/5 * * * ?  |      1 | com.market.web.schedule.global.MarketOverviewJob | NULL    | 2011-07-30 14:39:21 | NULL      | 2011-07-30 14:39:23 | NULL      |        0 |
 
+---------+--------------------------+--------------------------+-----------------+--------+-------------------------------------------------------------+---------+---------------------+-----------+---------------------+-----------+----------+
 
1 row in set (0.01 sec)
 
  
</pre>
+
    client_max_body_size 10m;
 +
 
 +
    location / {
 +
        auth_basic "Prometheus";
 +
        auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
 +
      proxy_pass http://10.3.10.124:9090;
 +
      proxy_http_version 1.1;
  
==== 数据库及表编码查看====
+
#set_real_ip_from 10.0.0.0/8;
<pre>
+
#set_real_ip_from 172.16.0.0/12;
查看数据库编码格式
+
#set_real_ip_from 192.168.0.0/16;
show variables like 'character_set_database';
+
#real_ip_header X-Forwarded-For;
 
 
 
 
查看数据表的编码格式
 
show create table <表名>;
 
 
 
</pre>
 
[https://blog.csdn.net/mingyu1016/article/details/54017918 查看mysql数据库及表编码格式]
 
 
 
 
 
 
 
[https://blog.csdn.net/thomas0yang/article/details/8175361 MySQL数据库维护手册]
 
 
 
==常用运维脚本==
 
<pre>
 
 
 
mysql -h databases.com -uadmin -p`cat /evan/11`  < $1
 
 
 
#Usage  bash dbin.sh  你的sql脚本
 
  
 +
        proxy_set_header        Host                $host;
 +
        proxy_set_header        X-Real-IP            $remote_addr;
 +
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 +
        proxy_set_header        X-Remote-Port        $remote_port;
 +
        proxy_set_header        X-Forwarded-Proto    $scheme;
 +
        proxy_redirect          off;
  
 +
          proxy_connect_timeout 1800s;
 +
          proxy_send_timeout 1800s;
 +
          proxy_read_timeout 1800s;
  
for loop in  `cat ../li`
 
do
 
 
 
  mysql  -uroot -p'222233'  -h 127.0.0.1  sns  < $loop.sql
 
# echo  $loop
 
done
 
  
  
cat  evan/dump
+
      real_ip_recursive on;
for loop in  `cat li`
+
#      real_ip_header X-Forwarded-For;
do
+
#      set_real_ip_from 0.0.0.0/0;
+
#      proxy_set_header Host            $host;
  mysqldump    -uroot  -ppassword  -h youip  sns $loop >$loop.sql
+
#      proxy_set_header X-Real-IP $remote_addr;
#echo  $loop
+
#     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
done
 
  
  
for  loop in  cat list
+
#proxy_set_header Host            $host:$server_port;
do
+
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
 +
#proxy_set_header X-NginX-Proxy true;
  
mysql -uroot -p45EOV -h127.0.0.1 -e  " CREATE DATABASE ${loop} CHARACTER SET utf8mb4  COLLATE utf8mb4_general_ci;"
+
#      proxy_set_header X-Real-IP        $remote_addr;
 +
#    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 +
#      proxy_set_header Upgrade $http_upgrade;
 +
#      proxy_set_header Connection "upgrade";
 +
    }
 +
}
  
</pre>
 
  
==mysqldump==
+
cat blackbox.conf
<pre>
+
server
  命令行下具体用法如下:  mysqldump -u用戶名 -p密码 -d 數據库名 表名 脚本名;
+
{
远程的 记得加-h
+
    listen 80;
 +
    server_name blackbox.com;
 +
#    access_log /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
 +
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
 +
    client_max_body_size 10m;
 +
    location / {
 +
  #      auth_basic "Prometheus";
 +
  #      auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
 +
      proxy_pass http://10.3.10.124:9115;
 +
      proxy_http_version 1.1;
  
    1、导出數據库為dbname的表结构(其中用戶名為root,密码為dbpasswd,生成的脚本名為db.sql)
+
        proxy_set_header        Host                $host;
    mysqldump -uroot -pdbpasswd -d dbname >db.sql;
+
        proxy_set_header        X-Real-IP            $remote_addr;
 +
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
 +
        proxy_set_header        X-Remote-Port        $remote_port;
 +
        proxy_set_header        X-Forwarded-Proto    $scheme;
 +
        proxy_redirect          off;
  
     2、导出數據库為dbname某张表(test)结构
+
          proxy_connect_timeout 1800s;
    mysqldump -uroot -pdbpasswd -d dbname test>db.sql;
+
          proxy_send_timeout 1800s;
 +
          proxy_read_timeout 1800s;
 +
      real_ip_recursive on;
 +
     }
 +
}
  
    3、导出數據库為dbname所有表结构及表數據(不加-d)
 
    mysqldump -uroot -pdbpasswd  dbname >db.sql;
 
  
    4、导出數據库為dbname某张表(test)结构及表數據(不加-d)
 
    mysqldump -uroot -pdbpasswd dbname test>db.sql;
 
  
 
</pre>
 
</pre>
  
=== mysqldump 排队表备份--ignore-table===
+
=告警=
<pre>
 
#可以多个表 ignore
 
mysqldump --databases mytest --ignore-table=mytest.ti_o_sms > mytest.sql
 
</pre>
 
[https://blog.csdn.net/karen121l/article/details/7289486  如何用mysqldump --ignore-table多个表]
 
  
[https://www.cnblogs.com/chuanzhang053/p/10216751.html mysqldump导出数据时,某些表不导出,排除某些表,不导出某些表]
+
[[Alertmanager]]
  
[https://blog.csdn.net/weixin_34216036/article/details/93424123?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.add_param_isCf mysqldump导出数据时,某些表不导出,排除某些表,不导出某些表]
+
==telegram==
 +
  通过 prome or grafana ?
  
[https://blog.csdn.net/weixin_33919950/article/details/89795809  mysqldump排除某几张表不导出,其余都导出。]
+
[https://nova.moe/manage-host-alert-on-telegram-with-grafana/ 在 Telegram 中管理主机监控和警报信息]
  
==trouble==
+
https://github.com/inCaller/prometheus_bot
  
MySQL数据库名中划线问题
+
https://github.com/metalmatze/alertmanager-bot
  
数据库的名字中有中划线,导致名字识别失败,用了 use dbname; 依然提示No database selected
+
[https://blog.csdn.net/weixin_34242331/article/details/91875514  基于prometheus + grafana + mysql + Telegram 监控告警]
解决方案
 
  
把数据库名用反引号 `` (和命令执行同一个的)引起来就可以了
+
https://my.oschina.net/54188zz/blog/3030618
==日常报错==
 
<pre>
 
  
没认真写  fre_fund_apply_id 写成 free_fund_apply_id
+
[https://yunlzheng.gitbook.io/prometheus-book/parti-prometheus-ji-chu/alert/prometheus-alert-rule 自定义Prometheus告警规则]
ALTER TABLE `hello_wallet`.`t_wallet_biz_withdraw_apply`  ADD COLUMN `fee_fund_apply_id` varchar(30) NULL COMMENT '手续费资金申请ID' AFTER `del_flag`;
 
  
ALTER TABLE `hello_wallet`.`t_wallet_biz_withdraw_apply` ADD COLUMN `fee_coin_id` varchar(30) NULL COMMENT '手续费币种ID' AFTER `fee_fund_apply_id`;
+
[https://www.linux.org.ru/forum/general/14894302  prometheus alertmanager telegram ]
  
 +
=教程=
 +
[https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_60_prometheus_config.html  prometheus学习系列五: Prometheus配置文件 ]
  
 +
=see also=
  
 +
[https://www.jianshu.com/p/93412a925da2 规划 Prometheus 的存储用量]
  
MySQL [(none)]> ALTER TABLE `hello_wallet`.`t_wallet_biz_withdraw_apply`  ADD COLUMN `fee_fund_apply_id` varchar(30) NULL COMMENT '手续费资金申请ID' AFTER `del_flag`;
+
[https://blog.csdn.net/lemon89/article/details/104088184 深入理解监控系统——Prometheus核心特点]
ERROR 1060 (42S21): Duplicate column name 'fee_fund_apply_id'
 
MySQL [(none)]> ALTER TABLE `hello_wallet`.`t_wallet_biz_withdraw_apply` ADD COLUMN `fee_coin_id` varchar(30) NULL COMMENT '手续费币种ID' AFTER `free_fund_apply_id`;
 
ERROR 1054 (42S22): Unknown column 'free_fund_apply_id' in 't_wallet_biz_withdraw_apply'
 
 
 
</pre>
 
  
==参考==
+
[https://blog.csdn.net/qq_21816375/article/details/80462445?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.nonecase  prometheus部署node,server以及域名加告警]
http://dufei.blog.51cto.com/382644/88646
 
  
 +
[https://www.cnblogs.com/chenqionghe/p/10494868.html 从零搭建Prometheus监控报警系统]
  
[https://blog.csdn.net/hello_zhou/article/details/51864566 MySQL常用命令总结]
+
[https://www.jianshu.com/p/1f05476ebcee 使用prometheus自定义监控]
  
 +
[https://zhuanlan.zhihu.com/p/91215371 为什么说 Prometheus 是足以取代 Zabbix 的监控神器?]
  
[https://www.cnblogs.com/imyalost/p/6756975.html MySQL(十四)管理维护及性能优化]
+
[https://blog.51cto.com/wzlinux/2487300 prometheus 监控概述(一)]
  
[https://www.cnblogs.com/chenmh/p/5300370.html MySQL mysqldump数据导出详解]
+
[https://my.oschina.net/54188zz/blog/3030618 基于prometheus + grafana + mysql + Telegram 监控告警]
  
  
[[category:mysql]]
+
[[category:ops]] [[category:container]] [[category:prom]]

2020年10月15日 (四) 12:15的版本

==


book

Prometheus操作指南

进阶

以后全改成自己 docker-compose build

prometheus 监控概述(一)有常用监控警告

PromQL 内置函数(三)


prometheus python 库编写自定义指标的方法(完整代码)


promethues + python + flask监控后端服务状态

prometheus python client

使用Python和Flask编写Prometheus监控

python开发prometheus exporter

ins on docker-composer

git clone https://github.com/evan886/docker-compose-monitor.git


https://gitee.com/atompi/PrometheusStackDockerCompose

安全

 node exporter 添加防火墙

curl -Lo /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo
# yum install node_exporter

prometheus

Nginx用户密码认证配置 Basic HTTP authentication

不错的书 https://yunlzheng.gitbook.io/prometheus-book/



新型监控告警工具prometheus(普罗米修斯)的入门使用(附视频讲解)

【视频】新型监控告警工具prometheus(普罗米修斯)入门使用(附视频讲解)

为什么说 Prometheus 是足以取代 Zabbix 的监控神器?

基于Prometheus的分布式在线服务监控实践

usage

Grafana单图表告警邮件&面板图(Dashboard)日报邮件

Recording rules

https://github.com/prometheus/blackbox_exporter/blob/master/blackbox.yml

grafana

#防火墙   grafana ng 在 10.3.10.10
 firewall-cmd   --permanent --add-rich-rule="rule family="ipv4" source address="10.3.10.10" port protocol="tcp" port="3000" accept "
firewall-cmd --reload


grafana.com Run Grafana Docker image

中文 Node Exporte for Prometheus Dashboard

usage creat-->import --> id 8919

Container


https://grafana.com/grafana/dashboards/11174


docker-grafana/config.env  https://github.com/stefanwalther/docker-grafana/blob/master/config.env  

grafana 添加源和数据

使用Grafana创建可视化Dashboard

Panel plugin not found: grafana-piechart-panel


升级为7.0.0就好了 不过要看其它模板还能用么 

#这个放弃了 是在 6.x系列的  还不好用 
grafana-cli plugins install grafana-piechart-panel

docker-compose  restart  grafana 


执行过程
 grafana-cli plugins install grafana-piechart-panel
installing grafana-piechart-panel @ 1.6.1
from: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.6.1/download
into: /var/lib/grafana/plugins

✔ Installed grafana-piechart-panel successfully 

Restart grafana after installing plugins . <service grafana-server restart>

[https://github.com/unifi-poller/unifi-poller/issues/248 RESOLVED: Panel plugin not found: table-old ]


Panel plugin not found: grafana-piechart-panel

grafana 添加用户

1.Users-->  2.Invite --> 

3.进行邀请
Email or Username:输入用户邮箱,建议先跟用户名保持相同,然后在后面在写邮箱,后面会说到,这样不会报错
Name:输入用户名
Role:配置用户权限(只读Viewer 编辑Editor 管理员Admin)
Send invite email:勾选时,会将新用户的设置密码的链接发到邮箱

点击创建之后回调到新用户设置密码

 -->

4.创建好之后,点击Pending Invites
复制链接到浏览器的地址栏中访问(也可从邮件中收到链接)
进去之后是下面的界面,这里有个坑,复制的IP地址是localhost,我们这里改为自己搭建的IP地址,然后在Email填写邮箱地址,设置新用户的密码
设置完成后,会直接以新用户身份登陆


http://localhost:3000/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa

http://a.linuxsa.org/invite/PAhyq4gzfA3ugRiw0PH2RC2vsIuSTa

  -->

grafana的用户及权限的配置

grafana的用户及权限的配置

grafana-利用Google OAuth2 身份验证

ng config

cat gf.conf 
server
{
    listen 80;
    server_name gf.linuxsa.org;
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;


    client_max_body_size 10m;
  
    location / {
      proxy_pass http://10.3.10.124:3000;
      proxy_http_version 1.1;

#set_real_ip_from 10.0.0.0/8;
#set_real_ip_from 172.16.0.0/12;
#set_real_ip_from 192.168.0.0/16;
#real_ip_header X-Forwarded-For;

        proxy_set_header        Host                 $host;
        proxy_set_header        X-Real-IP            $remote_addr;
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header        X-Remote-Port        $remote_port;
        proxy_set_header        X-Forwarded-Proto    $scheme;
        proxy_redirect          off;

          proxy_connect_timeout 1800s;
          proxy_send_timeout 1800s;
          proxy_read_timeout 1800s;



      real_ip_recursive on;
#      real_ip_header X-Forwarded-For;
#      set_real_ip_from 0.0.0.0/0;
#      proxy_set_header Host             $host;
#      proxy_set_header X-Real-IP $remote_addr;
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


#proxy_set_header Host             $host:$server_port;
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
#proxy_set_header X-NginX-Proxy true;

#      proxy_set_header X-Real-IP        $remote_addr;
 #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#      proxy_set_header Upgrade $http_upgrade;
#      proxy_set_header Connection "upgrade";
    }
}

使用教程

grafana配置与简单使用

Grafana使用教程

grafana数据可视化-使用教程

grafana快速入门

grafana使用教程之基本概念(basic concepts)

Grafana从无到有的一个相当粗略的资料总结


grafana数据可视化-使用教程

Grafana快速入门:InfluxDB数据源以及曲线图表仪表盘配置


Grafana报警


apached conf
##/etc/httpd/conf.d/gf.conf


<VirtualHost *:80>
      ServerName gf.linuxsa.org
      ServerAlias gf.linuxsa.org
     
      ProxyRequests off
     
      <Proxy *>
        Order deny,allow
        Allow from all
      </Proxy>
     
      <Location />
        ProxyPass http://localhost:3000/
        ProxyPassReverse http://localhost:3000/
      </Location>
    </VirtualHost>

vm监控Node-exporter

可以如上的 node Node-exporter

Blackbox

Blackbox exporter

pushgateway

pushgateway

基于Prometheus的Pushgateway实战

https://songjiayang.gitbooks.io/prometheus/content/pushgateway/how.html

Process-exporter

应用监控

redis

prometheus监控Redis集群

pika主备部署(redis-sentinel)+监控(prometheus+grafana)

Prometheus监控 Redis , redis-cli_exporter

监控MQ

Monitoring with Prometheus & Grafana

监控ES

https://github.com/slok/ecs-exporter

docker

Prometheus+grafana监控:cAdvisor输出的容器内存相关的指标的解读

mysql

prometheus 监控之 mysql 篇(含mysql报警规则)

Prometheus MySQL Exporter源码阅读与分析

python + promethues 监控mysql

Spring boot

https://www.bookstack.cn/read/prometheus_practice/application-spring.md


Prometheus基于java开发exporter样例以及pushgateway的应用

ng conf

cat  alert.conf 
server
{
    listen 80;
    server_name alert.com;
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;


    client_max_body_size 10m;
  
    location / {
  #      auth_basic "Prometheus";
  #      auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
      proxy_pass http://10.3.10.124:9093;
      proxy_http_version 1.1;

#s#et_real_ip_from 10.0.0.0/8;
#set_real_ip_from 172.16.0.0/12;
#set_real_ip_from 192.168.0.0/16;
#real_ip_header X-Forwarded-For;
        proxy_set_header        Host                 $host;
        proxy_set_header        X-Real-IP            $remote_addr;
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header        X-Remote-Port        $remote_port;
        proxy_set_header        X-Forwarded-Proto    $scheme;
        proxy_redirect          off;
          proxy_connect_timeout 1800s;
          proxy_send_timeout 1800s;
          proxy_read_timeout 1800s;

      real_ip_recursive on;
#      real_ip_header X-Forwarded-For;
#      set_real_ip_from 0.0.0.0/0;
#      proxy_set_header Host             $host;
#      proxy_set_header X-Real-IP $remote_addr;
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


#proxy_set_header Host             $host:$server_port;
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
#proxy_set_header X-NginX-Proxy true;

#      proxy_set_header X-Real-IP        $remote_addr;
 #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#      proxy_set_header Upgrade $http_upgrade;
#      proxy_set_header Connection "upgrade";
    }
}



cat  pro.conf 
server
{
    listen 80;
    server_name pro.linuxsa.org;
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;


    client_max_body_size 10m;
  
    location / {
        auth_basic "Prometheus";
        auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
      proxy_pass http://10.3.10.124:9090;
      proxy_http_version 1.1;

#set_real_ip_from 10.0.0.0/8;
#set_real_ip_from 172.16.0.0/12;
#set_real_ip_from 192.168.0.0/16;
#real_ip_header X-Forwarded-For;

        proxy_set_header        Host                 $host;
        proxy_set_header        X-Real-IP            $remote_addr;
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header        X-Remote-Port        $remote_port;
        proxy_set_header        X-Forwarded-Proto    $scheme;
        proxy_redirect          off;

          proxy_connect_timeout 1800s;
          proxy_send_timeout 1800s;
          proxy_read_timeout 1800s;



      real_ip_recursive on;
#      real_ip_header X-Forwarded-For;
#      set_real_ip_from 0.0.0.0/0;
#      proxy_set_header Host             $host;
#      proxy_set_header X-Real-IP $remote_addr;
#      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


#proxy_set_header Host             $host:$server_port;
#proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
#proxy_set_header X-NginX-Proxy true;

#      proxy_set_header X-Real-IP        $remote_addr;
 #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#      proxy_set_header Upgrade $http_upgrade;
#      proxy_set_header Connection "upgrade";
    }
}


cat blackbox.conf 
server
{
    listen 80;
    server_name blackbox.com;
#    access_log  /var/log/nginx/test-nuxt-bcb-blockchain-website.lliao.net.log;
    #error_log /var/log/nginx/test-nux-bcb.evan.error.log;
    client_max_body_size 10m;
    location / {
  #      auth_basic "Prometheus";
  #      auth_basic_user_file "/usr/local/openresty/nginx/conf/hosts/.htpasswd";
      proxy_pass http://10.3.10.124:9115;
      proxy_http_version 1.1;

        proxy_set_header        Host                 $host;
        proxy_set_header        X-Real-IP            $remote_addr;
        proxy_set_header        X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header        X-Remote-Port        $remote_port;
        proxy_set_header        X-Forwarded-Proto    $scheme;
        proxy_redirect          off;

          proxy_connect_timeout 1800s;
          proxy_send_timeout 1800s;
          proxy_read_timeout 1800s;
      real_ip_recursive on;
    }
}



告警

Alertmanager

telegram

通过 prome or grafana ?

在 Telegram 中管理主机监控和警报信息

https://github.com/inCaller/prometheus_bot

https://github.com/metalmatze/alertmanager-bot

基于prometheus + grafana + mysql + Telegram 监控告警

https://my.oschina.net/54188zz/blog/3030618

自定义Prometheus告警规则

prometheus alertmanager telegram

教程

prometheus学习系列五: Prometheus配置文件

see also

规划 Prometheus 的存储用量

深入理解监控系统——Prometheus核心特点

prometheus部署node,server以及域名加告警

从零搭建Prometheus监控报警系统

使用prometheus自定义监控

为什么说 Prometheus 是足以取代 Zabbix 的监控神器?

prometheus 监控概述(一)

基于prometheus + grafana + mysql + Telegram 监控告警