1.orzdba_monitor.sh脚本使用
- ./orzdba_monitor.sh 主要是用nohup同时在后台调用orzdba,启动下面三个命令
[root@node02 scripts]# ps -ef |grep orzdba
root 19887 1 0 17:40 ? 00:00:00 /usr/bin/perl -w /scripts/orzdba -i 10 -t -mysql -innodb_rows -L /r2/monitor/log_orzdba_mysql -logfile_by_day
root 19888 1 0 17:40 ? 00:00:00 /usr/bin/perl -w /scripts/orzdba -i 10 -t -sys -d sda -L /r2/monitor/log_orzdba_sys -logfile_by_day
root 19889 1 0 17:40 ? 00:00:00 /usr/bin/perl -w /scripts/orzdba -i 10 -processlist -L /r2/monitor/log_orzdba_proc -logfile_by_day
-
根据实际情况,需要修改变量:
- SCRIPTS_FILE=/scripts --脚本所在目录
- MONITOR=/r2/monitor --监控日志保存目录
- DEVICE_NAME="sda" --数据库所在的硬盘盘符
- DELETE_DAYS=15 --日志保存天数
-
添加权限
[root@node02 scripts]# chmod 755 orzdba
[root@node02 scripts]# chmod 755 orzdba_monitor.sh
-
计划任务
- crontab -e
- 每5分钟执行一次脚本,如果没有进程就启动
- */5 * * * * /scripts/orzdba_monitor.sh >/dev/null 2>&1
-
日志,分别生成三个日志,根据日期截断日志,可以设置保存日志的天数
- 日志目录显示如下:
[root@node01 monitor]# ll /r2/monitor/
total 194052
-rw-r--r-- 1 root root 225257 Apr 24 15:36 log_orzdba_mysql.2018-04-24
-rw-r--r-- 1 root root 180040747 Apr 24 15:36 log_orzdba_proc.2018-04-24
-rw-r--r-- 1 root root 202990 Apr 24 15:36 log_orzdba_sys.2018-04-24
-rw-r--r-- 1 root root 114 Apr 24 15:35 orzdba.log
2.orzdba
- 根据实际情况,在orzdba中修改帐号信息。
my $user="root"; # -u --mysql帐号
my $pass="iforgot"; # -p --mysql密码
my $host="localhost"; # -h --mysqlhost
- 验证帐号如下:
[root@node02 scripts]# ./orzdba -u root -p iforgot -h localhost -innodb -C 5 -i 2 2>/dev/null
.=================================================.
| Welcome to use the dba tool ! |
'=============== Date : 2018-04-23 ==============='
Local_Host: node02.mysql.com Local_IP: 192.168.49.247
MySQL_Host: localhost
MySQL_DB :
ttt
MySQL_Var :
binlog_format[ROW] character_set_server[utf8] enforce_gtid_consistency[ON] gtid_mode[ON]
log_bin[ON] max_allowed_packet[4194304] max_binlog_cache_size[17179869184G] max_binlog_size[1G]
max_connect_errors[100000] max_connections[10000] max_user_connections[9990] open_files_limit[50000]
skip_name_resolve[ON] sync_binlog[0] table_definition_cache[912] table_open_cache[1024]
thread_cache_size[64] wait_timeout[31536000]
innodb_adaptive_flushing[ON] innodb_adaptive_hash_index[ON] innodb_buffer_pool_size[4G] innodb_file_per_table[ON]
innodb_flush_log_at_trx_commit[2] innodb_flush_method[O_DIRECT] innodb_io_capacity[200] innodb_lock_wait_timeout[5]
innodb_log_buffer_size[16M] innodb_log_file_size[2G] innodb_log_files_in_group[2] innodb_max_dirty_pages_pct[75.000000]
innodb_open_files[1024] innodb_read_io_threads[4] innodb_thread_concurrency[64] innodb_write_io_threads[4]
-------- ---innodb bp pages status-- -----innodb data status---- --innodb log-- his --log(byte)-- read ---query---
time | data free dirty flush| reads writes read written|fsyncs written| list uflush uckpt view inside que|
18:08:12| 0 0 0 0| 0 0 0 0| 0 0| 0 0 0 0 0 0|
18:08:14| 104298 157834 3 0| 0 0 0 0| 0 0| 61 0 9 0 0 0|
18:08:16| 104298 157834 0 1| 0 1 0 24k| 0 0| 61 0 9 0 0 0|
- 帮助命令(./orzdba -I)
Usage :
Command line options :
-I,--help Print Help Info.
-i,--interval Time(second) Interval.
-C,--count Times.
-t,--time Print The Current Time.
-nocolor Print NO Color.
-l,--load Print Load Info.
-c,--cpu Print Cpu Info.
-s,--swap Print Swap Info.
-d,--disk Print Disk Info.
-n,--net Print Net Info.
-u MySQL User(default root).
-P MySQL Password(default iforgot).
-P,--port Port number to use for mysql connection(default 3306).
-S,--socket Socket file to use for mysql connection.
-h,--host Host (hostname/IP).
-mysql Print MySQLInfo (include -t,-com,-hit,-T,-B).
-innodb Print InnodbInfo(include -t,-innodb_pages,-innodb_data,-innodb_log,-innodb_status)
-com Print MySQL Status(Com_select,Com_insert,Com_update,Com_delete).
-hit Print Innodb Hit%.
-processlist Print Show Full Processlist
-innodb_rows Print Innodb Rows Status(Innodb_rows_inserted/updated/deleted/read).
-innodb_pages Print Innodb Buffer Pool Pages Status(Innodb_buffer_pool_pages_data/free/dirty/flushed)
-innodb_data Print Innodb Data Status(Innodb_data_reads/writes/read/written)
-innodb_log Print Innodb Log Status(Innodb_os_log_fsyncs/written)
-innodb_status Print Innodb Status from Command: 'Show Engine Innodb Status';
(history list/ log unflushed/uncheckpointed bytes/ read views/ queries inside/queued)
-T,--threads Print Threads Status(Threads_running,Threads_connected,Threads_created,Threads_cached).
-B,--bytes Print Bytes received from/send to MySQL(Bytes_received,Bytes_sent).
-rt Print MySQL DB RT(us).
-sys Print SysInfo (include -t,-l,-c,-s).
-lazy Print Info (include -t,-l,-c,-s,-com,-hit).
-L,--logfile Print to Logfile.
-logfile_by_day One day a logfile,the suffix of logfile is 'yyyy-mm-dd';
and is valid with -L.
Sample :
shell> ./orzdba -u xxxxx -p xxxxx -innodb -C 5 -i 2 2>/dev/null
shell> ./orzdba -u xxxxx -p xxxxx -lazy -d sda -C 5 -i 2 2>/dev/null
shell> ./orzdba -h xxxxx -u xxxxx -p xxxxx -processlist -C 5 -i 2 2>/dev/null
shell> nohup ./orzdba -u xxxxx -p xxxxx -lazy -d sda -C 5 -i 2 -L /tmp/orzdba.log > /dev/null 2>&1 &