MySQL Inception For Linux安裝初探

chenfeng發表於2017-03-16
MySQL Inception是由去哪兒網的DBA大神們開發的一款用於自動稽核SQL的開源工具,一個集稽核、執行、備份及生成回滾語句於一身的MySQL自動化運維工具。

安裝過程如下:
1.下載: 選擇下載inception-master.zip,然後將它上傳到伺服器/root目錄
2.解壓並安裝:
# unzip inception-master.zip
#cd inception-master
#yum -y install cmake bison  ncurses-devel gcc gcc-c++  openssl-devel
#mkdir  /data
#mkdir -P /usr/local/inception      --這裡建立的是Inception的安裝目錄。可根據自己的情況自行決定
#mkdir -P /data/inception   --這裡建立的是Inception的資料目錄。也可根據自己的情況自行決定
#unzip master
#cd inception-master/  
#cmake .
#cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/inception  -DMYSQL_DATADIR=/data/inception   --安裝指定安裝目錄和資料目錄
#make && make install
編譯中間發現會報錯:
make[2]: * [sql/CMakeFiles/sql.dir/sql_yacc.cc.o] Error 1 
make[1]: * [sql/CMakeFiles/sql.dir/all] Error 2 
make: * [all] Error 2

解決方法:
經檢查發現已安裝bison的版本為2.1,較低,而手冊建議的版本為2.6之前的,建議用2.5.1版本。
去網址下載bison-2.5.1.tar.gz

解壓縮後編譯安裝,安裝完後的路徑為/usr/local/bin/bison,
確認版本為2.5.1後,再次進入inception-master目錄,刪除CMakeCache.txt後重新編譯:
#cd inception-master/ 
# rm CMakeCache.txt
#cmake .
#cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/inception  -DMYSQL_DATADIR=/data/inception
#make
#make install
這次沒有報錯,make install完後,
編輯/etc/inc.cnf檔案,增加如下內容:

#vim /etc/inc.cnf
[inception]
general_log=1
general_log_file=/usr/local/inception/data/inception.log
port=6669
socket=/data/workspace/inception_data/inc.socket
character-set-client-handshake=0
character-set-server=utf8
inception_remote_system_password=123456
inception_remote_system_user=root
inception_remote_backup_port=3306
inception_remote_backup_host=127.0.0.1
inception_support_charset=utf8mb4
inception_enable_nullable=0
inception_check_primary_key=1
inception_check_column_comment=1
inception_check_table_comment=1
inception_osc_min_table_size=1
inception_osc_bin_dir=/data/temp
inception_osc_chunk_time=0.1
inception_ddl_support=1
inception_enable_blob_type=1
inception_check_column_default_value=1


3.啟動inception(放後臺執行)
[root@test1 ~]# nohup /usr/local/inception/bin/Inception --defaults-file=/etc/inc.cnf &

看到nohup有如下輸出說明啟動成功:
[root@test1 ~]# cat nohup.out
2017-03-16 15:48:14 0 [Note] Welcome to use Inception2.1.50
2017-03-16 15:48:14 46451 [Note] Server hostname (bind-address): '*'; port: 6669
2017-03-16 15:48:14 46451 [Note] IPv6 is available.
2017-03-16 15:48:14 46451 [Note]   - '::' resolves to '::';
2017-03-16 15:48:14 46451 [Note] Server socket created on IP: '::'.


4.登陸inception測試:

[root@test1 ~]# mysql -uroot -h127.0.0.1 -P6669
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: Inception2.1.50 1


Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MySQL [(none)]>
MySQL [(none)]>
MySQL [(none)]>
MySQL [(none)]> inception get variables;
+------------------------------------------+-------------------------------------------+
| Variable_name                            | Value                                     |
+------------------------------------------+-------------------------------------------+
| autocommit                               | OFF                                       |
| bind_address                             | *                                         |
| character_set_system                     | utf8                                      |
| character_sets_dir                       | /usr/local/inception/bin/share/charsets/  |
| connect_timeout                          | 10                                        |
| date_format                              | %Y-%m-%d                                  |
| datetime_format                          | %Y-%m-%d %H:%i:%s                         |
| general_log                              | ON                                        |
| general_log_file                         | /usr/local/inception/data/inception.log   |
| inception_check_autoincrement_datatype   | ON                                        |
| inception_check_autoincrement_init_value | ON                                        |
| inception_check_autoincrement_name       | ON                                        |
| inception_check_column_comment           | ON                                        |
| inception_check_column_default_value     | ON                                        |
| inception_check_dml_limit                | ON                                        |
| inception_check_dml_orderby              | ON                                        |
| inception_check_dml_where                | ON                                        |
| inception_check_identifier               | ON                                        |
| inception_check_index_prefix             | ON                                        |
| inception_check_insert_field             | ON                                        |
| inception_check_primary_key              | ON                                        |
| inception_check_table_comment            | ON                                        |
| inception_check_timestamp_default        | ON                                        |
| inception_ddl_support                    | ON                                        |
| inception_enable_autoincrement_unsigned  | ON                                        |
| inception_enable_blob_type               | ON                                        |
| inception_enable_column_charset          | OFF                                       |
| inception_enable_enum_set_bit            | OFF                                       |
| inception_enable_foreign_key             | OFF                                       |
| inception_enable_identifer_keyword       | OFF                                       |
| inception_enable_not_innodb              | OFF                                       |
| inception_enable_nullable                | OFF                                       |
| inception_enable_orderby_rand            | OFF                                       |
| inception_enable_partition_table         | OFF                                       |
| inception_enable_pk_columns_only_int     | OFF                                       |
| inception_enable_select_star             | OFF                                       |
| inception_enable_sql_statistic           | ON                                        |
| inception_max_char_length                | 16                                        |
| inception_max_key_parts                  | 5                                         |
| inception_max_keys                       | 16                                        |
| inception_max_primary_key_parts          | 5                                         |
| inception_max_update_rows                | 10000                                     |
| inception_merge_alter_table              | ON                                        |
| inception_osc_alter_foreign_keys_method  | none                                      |
| inception_osc_bin_dir                    | /data/temp                                |
| inception_osc_check_alter                | ON                                        |
| inception_osc_check_interval             | 5.000000                                  |
| inception_osc_check_replication_filters  | ON                                        |
| inception_osc_chunk_size                 | 1000                                      |
| inception_osc_chunk_size_limit           | 4.000000                                  |
| inception_osc_chunk_time                 | 0.100000                                  |
| inception_osc_critical_thread_connected  | 1000                                      |
| inception_osc_critical_thread_running    | 80                                        |
| inception_osc_drop_new_table             | ON                                        |
| inception_osc_drop_old_table             | ON                                        |
| inception_osc_max_lag                    | 3.000000                                  |
| inception_osc_max_thread_connected       | 1000                                      |
| inception_osc_max_thread_running         | 80                                        |
| inception_osc_min_table_size             | 1                                         |
| inception_osc_on                         | ON                                        |
| inception_osc_print_none                 | ON                                        |
| inception_osc_print_sql                  | ON                                        |
| inception_osc_recursion_method           | processlist                               |
| inception_password                       |                                           |
| inception_read_only                      | OFF                                       |
| inception_remote_backup_host             | 127.0.0.1                                 |
| inception_remote_backup_port             | 3306                                      |
| inception_remote_system_password         | *4086D17D857F0000F04C5A0000000000210A0078 |
| inception_remote_system_user             | root                                      |
| inception_support_charset                | utf8mb4                                   |
| inception_user                           |                                           |
| interactive_timeout                      | 28800                                     |
| max_allowed_packet                       | 1073741824                                |
| max_connect_errors                       | 100                                       |
| max_connections                          | 151                                       |
| net_buffer_length                        | 16384                                     |
| net_read_timeout                         | 30                                        |
| net_write_timeout                        | 60                                        |
| port                                     | 6669                                      |
| query_alloc_block_size                   | 8192                                      |
| query_prealloc_size                      | 8192                                      |
| socket                                   | /data/workspace/inception_data/inc.socket |
| thread_handling                          | one-thread-per-connection                 |
| thread_stack                             | 262144                                    |
| time_format                              | %H:%i:%s                                  |
| version                                  | Inception2.1.50                           |
| version_comment                          | Source distribution                       |
| version_compile_machine                  | x86_64                                    |
| version_compile_os                       | Linux                                     |
| wait_timeout                             | 28800                                     |
+------------------------------------------+-------------------------------------------+
90 rows in set (0.00 sec)

輸出了所有的變數,說明Inception啟動成功。


附:(variables的引數解釋):
[inception]
general_log=1 #這個引數就是原生的MySQL的引數,用來記錄在Inception服務上執行過哪些語句,用來定位一些問題等
general_log_file=/usr/local/inception/data/inception.log #設定general log寫入的檔案路徑
port=6669   #Inception的服務埠
socket=/data/inception/inc.socket #Inception的套接字檔案存放位置
character-set-server=utf8 #mysql原生引數
#Inception 稽核規則
inception_check_autoincrement_datatype=1 #當建表時自增列的型別不為int或者bigint時報錯
inception_check_autoincrement_init_value=1 #當建表時自增列的值指定的不為1,則報錯
inception_check_autoincrement_name=1 #建表時,如果指定的自增列的名字不為ID,則報錯,說明是有意義的,給提示
inception_check_column_comment=1 #建表時,列沒有註釋時報錯
inception_check_column_default_value=0 #檢查在建表、修改列、新增列時,新的列屬性是不是要有預設值
inception_check_dml_limit=1 #在DML語句中使用了LIMIT時,是不是要報錯
inception_check_dml_orderby=1 #在DML語句中使用了Order By時,是不是要報錯
inception_check_dml_where=1 #在DML語句中沒有WHERE條件時,是不是要報錯
inception_check_identifier=1 #開啟與關閉Inception對SQL語句中各種名字的檢查,如果設定為ON,則如果發現名字中存在除數字、字母、下劃線之外的字元時,會報Identifier "invalidname" is invalid, valid options: [a-z,A-Z,0-9,_].
inception_check_index_prefix=1 #是不是要檢查索引名字字首為"idx_",檢查唯一索引字首是不是"uniq_"
inception_check_insert_field=1  #是不是要檢查插入語句中的列連結串列的存在性
inception_check_primary_key=1 #建表時,如果沒有主鍵,則報錯
inception_check_table_comment=1 #建表時,表沒有註釋時報錯
inception_check_timestamp_default=0 #建表時,如果沒有為timestamp型別指定預設值,則報錯
inception_enable_autoincrement_unsigned=1 #自增列是不是要為無符號型
inception_enable_blob_type=0 #檢查是不是支援BLOB欄位,包括建表、修改列、新增列操作 預設開啟
inception_enable_column_charset=0 #允許列自己設定字符集
inception_enable_enum_set_bit=0 #是不是支援enum,set,bit資料型別
inception_enable_foreign_key=0 #是不是支援外來鍵
inception_enable_identifer_keyword=0 #檢查在SQL語句中,是不是有識別符號被寫成MySQL的關鍵字,預設值為報警。
inception_enable_not_innodb=0 #建表指定的儲存引擎不為Innodb,不報錯
inception_enable_nullable=0 #建立或者新增列時如果列為NULL,不報錯
inception_enable_orderby_rand=0 #order by rand時是不是報錯
inception_enable_partition_table=0 #是不是支援分割槽表
inception_enable_select_star=0 #Select*時是不是要報錯
inception_enable_sql_statistic=1 #設定是不是支援統計Inception執行過的語句中,各種語句分別佔多大比例,如果開啟這個引數,則每次執行的情況都會在備份資料庫例項中的inception庫的statistic表中以一條記錄儲存這次操作的統計情況,每次操作對應一條記錄,這條記錄中含有的資訊是各種型別的語句執行次數情況。
inception_max_char_length=16 #當char型別的長度大於這個值時,就提示將其轉換為VARCHAR
inception_max_key_parts=5 #一個索引中,列的最大個數,超過這個數目則報錯
inception_max_keys=16 #一個表中,最大的索引數目,超過這個數則報錯
inception_max_update_rows=10000 #在一個修改語句中,預計影響的最大行數,超過這個數就報錯
inception_merge_alter_table=1 #在多個改同一個表的語句出現是,報錯,提示合成一個
#inception 支援 OSC 引數
inception_osc_bin_dir=/data/temp #用於指定pt-online-schema-change指令碼的位置,不可修改,在配置檔案中設定
inception_osc_check_interval=5 #對應OSC引數--check-interval,意義是Sleep time between checks for --max-lag.
inception_osc_chunk_size=1000 #對應OSC引數--chunk-size
inception_osc_chunk_size_limit=4 #對應OSC引數--chunk-size-limit
inception_osc_chunk_time=0.1 #對應OSC引數--chunk-time
inception_osc_critical_thread_connected=1000 #對應引數--critical-load中的thread_connected部分
inception_osc_critical_thread_running=80 #對應引數--critical-load中的thread_running部分
inception_osc_drop_new_table=1 #對應引數--[no]drop-new-table
inception_osc_drop_old_table=1 #對應引數--[no]drop-old-table
inception_osc_max_lag=3 #對應引數--max-lag
inception_osc_max_thread_connected=1000 #對應引數--max-load中的thread_connected部分
inception_osc_max_thread_running=80 #對應引數--max-load中的thread_running部分
inception_osc_min_table_size=1 # 這個引數實際上是一個OSC的開關,如果設定為0,則全部ALTER語句都走OSC,如果設定為非0,則當這個表佔用空間大小大於這個值時才使用OSC方式。單位為M,這個表大小的計算方式是透過語句:"select (DATA_LENGTH + INDEX_LENGTH)/1024/1024 from information_schema.tables where table_schema = 'dbname' and table_name = 'tablename'"來實現的
inception_osc_on=1 #一個全域性的OSC開關,預設是開啟的,如果想要關閉則設定為OFF,這樣就會直接修改
inception_osc_print_none=1 #用來設定在Inception返回結果集中,對於原來OSC在執行過程的標準輸出資訊是不是要列印到結果集對應的錯誤資訊列中,如果設定為1,就不列印,如果設定為0,就列印。而如果出現錯誤了,則都會列印
inception_osc_print_sql=1 #對應引數--print
#inception_user #這個使用者名稱在配置之後,在連線Inception的選項中可以不指定user,這樣線上資料庫的使用者名稱及密碼就可以不暴露了,可以做為臨時使用的一種方式,但這個使用者現在只能是用來稽核,也就是說,即使在選項中指定--enable-execute,也不能執行,這個是隻能用來稽核的帳號。
#inception_password #與上面的引數是一對,這個引數對應的是選項中的password,設定這個引數之後,可以在選項中不指定password
inception_read_only=0 #設定當前Inception伺服器是不是隻讀的,這是為了防止一些人具有修改許可權的帳號時,透過Inception誤修改一些資料,如果inception_read_only設定為ON,則即使開了enable-execute,同時又有執行許可權,也不會去執行,稽核完成即返回
#備份伺服器資訊
inception_remote_system_password=123456
inception_remote_system_user=root
inception_remote_backup_port=3306
inception_remote_backup_host=192.168.1.54
inception_support_charset=utf8 #表示在建表或者建庫時支援的字符集,如果需要多個,則用逗號分隔,影響的範圍是建表、設定會話字符集、修改表字符集屬性等

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2135483/,如需轉載,請註明出處,否則將追究法律責任。

相關文章