溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Yearning + Inception SQL審核平臺搭建方法是什么

發(fā)布時間:2021-11-08 11:10:40 來源:億速云 閱讀:133 作者:iii 欄目:MySQL數(shù)據(jù)庫

本篇內(nèi)容介紹了“Yearning + Inception SQL審核平臺搭建方法是什么”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

Yearning 安裝:

安裝Nginx
yum install nginx -y

按照順序安裝MySQL
mysql-community-common-5.7.22-1.el6.x86_64.rpm
mysql-community-libs-5.7.22-1.el6.x86_64.rpm
mysql-community-client-5.7.22-1.el6.x86_64.rpm
mysql-community-server-5.7.22-1.el6.x86_64.rpm

Python 3.6安裝

解壓
tar -xvf Python-3.6.4.tar.xz

創(chuàng)建目錄
mkdir -p /usr/local/python/3.6.4/lib

編譯
cd Python-3.6.4
./configure --enable-shared --prefix=/usr/local/python/3.6.4 LDFLAGS="-Wl,-rpath /usr/local/python/3.6.4/lib"
make && make install

軟鏈接
cp /usr/bin/python /usr/bin/python2.6.6
ln -fs /usr/local/python/3.6.4/bin/python3.6 /usr/bin/python
ln -fs /usr/local/python/3.6.4/bin/pip3 /usr/bin/pip

yum修改
vi /usr/bin/yum
將頭部 #!/usr/bin/python 修改為 #!/usr/bin/python2.6.6

Inception安裝
Inception是集審核、執(zhí)行、回滾于一體的一個自動化運(yùn)維系統(tǒng),它是根據(jù)MySQL代碼修改過來的,用它可以很明確的,詳細(xì)的,準(zhǔn)確的審核MySQL的SQL語句,它的工作模式和MySQL完全相同,可以直接使用MySQL客戶端來連接,但不需要驗(yàn)證權(quán)限,它相對應(yīng)用程序(上層審核流程系統(tǒng)等)而言,是一個服務(wù)器,在連接時需要指定服務(wù)器地址及Inception服務(wù)器的端口即可,而它相對要審核或執(zhí)行的語句所對應(yīng)的線上MySQL服務(wù)器來說,是一個客戶端,它在內(nèi)部需要實(shí)時的連接數(shù)據(jù)庫服務(wù)器來獲取所需要的信息,或者直接在在線上執(zhí)行相應(yīng)的語句及獲取binlog等,Inception就是一個中間性質(zhì)的服務(wù)。

依賴包安裝
yum install gcc gcc-c++ cmake bison openssl-devel ncurses-devel git

下載源碼包
git clone https://github.com/mysql-inception/inception.git(已經(jīng)閉源,但是網(wǎng)上還能找到閉源之前的包)

編譯安裝Inception
mkdir -p /usr/local/inception

mkdir -p /inception/{data,logs}

unzip master.zip -d /inception

cd /inception/inception-master
cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/inception -DMYSQL_DATADIR=/inception/data -DWITH_SSL=yes -DCMAKE_BUILD_TYPE=RELEASE -DWITH_ZLIB=bundled -DMY_MAINTAINER_CXX_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wno-unused-parameter -Woverloaded-virtual" -DMY_MAINTAINER_C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement"

CMake Error: The source "/inception/inception-master/CMakeLists.txt" does not match the source "/opt/inception-master/CMakeLists.txt" used to generate cache

rm -rf CMakeLists.txt再執(zhí)行

make && make install

創(chuàng)建inception配置文件
--編輯參數(shù)文件

vim /etc/inc.cnf

[inception]

general_log=1 #這個參數(shù)就是原生的MySQL的參數(shù),用來記錄在Inception服務(wù)上執(zhí)行過哪些語句,用來定位一些問題等

general_log_file=/usr/local/inception/data/inception.log #設(shè)置general log寫入的文件路徑

port=6669 #Inception的服務(wù)端口

socket=/usr/local/inception/data/inc.socket #Inception的套接字文件存放位置

character-set-server=utf8 #mysql原生參數(shù)

#Inception 審核規(guī)則

inception_check_autoincrement_datatype=1 #當(dāng)建表時自增列的類型不為int或者bigint時報錯

inception_check_autoincrement_init_value=1 #當(dāng)建表時自增列的值指定的不為1,則報錯

inception_check_autoincrement_name=1 #建表時,如果指定的自增列的名字不為ID,則報錯,說明是有意義的,給提示

inception_check_column_comment=1 #建表時,列沒有注釋時報錯

inception_check_column_default_value=0 #檢查在建表、修改列、新增列時,新的列屬性是不是要有默認(rèn)值

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 #打開與關(guān)閉Inception對SQL語句中各種名字的檢查,如果設(shè)置為ON,則如果發(fā)現(xiàn)名字中存在除數(shù)字、字母、下劃線之外的字符時,會報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=0 #建表時,表沒有注釋時報錯

inception_check_timestamp_default=0 #建表時,如果沒有為timestamp類型指定默認(rèn)值,則報錯

inception_enable_autoincrement_unsigned=1 #自增列是不是要為無符號型

inception_enable_blob_type=0 #檢查是不是支持BLOB字段,包括建表、修改列、新增列操作 默認(rèn)開啟

inception_enable_column_charset=0 #允許列自己設(shè)置字符集

inception_enable_enum_set_bit=0 #是不是支持enum,set,bit數(shù)據(jù)類型

inception_enable_foreign_key=0 #是不是支持外鍵

inception_enable_identifer_keyword=0 #檢查在SQL語句中,是不是有標(biāo)識符被寫成MySQL的關(guān)鍵字,默認(rèn)值為報警。

inception_enable_not_innodb=0 #建表指定的存儲引擎不為Innodb,不報錯

inception_enable_nullable=0 #創(chuàng)建或者新增列時如果列為NULL,不報錯

inception_enable_orderby_rand=0 #order by rand時是不是報錯

inception_enable_partition_table=0 #是不是支持分區(qū)表

inception_enable_select_star=0 #Select*時是不是要報錯

inception_enable_sql_statistic=1 #設(shè)置是不是支持統(tǒng)計Inception執(zhí)行過的語句中,各種語句分別占多大比例,如果打開這個參數(shù),則每次執(zhí)行的情況都會在備份數(shù)據(jù)庫實(shí)例中的inception庫的statistic表中以一錄存儲這次操作的統(tǒng)計情況,每次操作對應(yīng)一條記錄,這條記錄中含有的信息是各種類型的語句執(zhí)行次數(shù)情況。

inception_max_char_length=16 #當(dāng)char類型的長度大于這個值時,就提示將其轉(zhuǎn)換為VARCHAR

inception_max_key_parts=5 #一個索引中,列的最大個數(shù),超過這個數(shù)目則報錯

inception_max_keys=16 #一個表中,最大的索引數(shù)目,超過這個數(shù)則報錯

inception_max_update_rows=10000 #在一個修改語句中,預(yù)計影響的最大行數(shù),超過這個數(shù)就報錯

inception_merge_alter_table=1 #在多個改同一個表的語句出現(xiàn)是,報錯,提示合成一個

#inception 支持 OSC 參數(shù)

inception_osc_bin_dir=/user/bin #用于指定pt-online-schema-change腳本的位置,不可修改,在配置文件中設(shè)置

inception_osc_check_interval=5 #對應(yīng)OSC參數(shù)--check-interval,意義是Sleep time between checks for --max-lag.

inception_osc_chunk_size=1000 #對應(yīng)OSC參數(shù)--chunk-size

inception_osc_chunk_size_limit=4 #對應(yīng)OSC參數(shù)--chunk-size-limit

inception_osc_chunk_time=0.1 #對應(yīng)OSC參數(shù)--chunk-time

inception_osc_critical_thread_connected=1000 #對應(yīng)參數(shù)--critical-load中的thread_connected部分

inception_osc_critical_thread_running=80 #對應(yīng)參數(shù)--critical-load中的thread_running部分

inception_osc_drop_new_table=1 #對應(yīng)參數(shù)--[no]drop-new-table

inception_osc_drop_old_table=1 #對應(yīng)參數(shù)--[no]drop-old-table

inception_osc_max_lag=3 #對應(yīng)參數(shù)--max-lag

inception_osc_max_thread_connected=1000 #對應(yīng)參數(shù)--max-load中的thread_connected部分

inception_osc_max_thread_running=80 #對應(yīng)參數(shù)--max-load中的thread_running部分

inception_osc_min_table_size=0 # 這個參數(shù)實(shí)際上是一個OSC的開關(guān),如果設(shè)置為0,則全部ALTER語句都走OSC,如果設(shè)置為非0,則當(dāng)這個表占用空間大小大于這個值時才使用OSC方式。單位為M,這個表大小的計算方式是通過語句:"select (DATA_LENGTH + INDEX_LENGTH)/1024/1024 from information_schema.tables where table_schema = 'dbname' and table_name = 'tablename'"來實(shí)現(xiàn)的

inception_osc_on=0 #一個全局的OSC開關(guān),默認(rèn)是打開的,如果想要關(guān)閉則設(shè)置為OFF,這樣就會直接修改

inception_osc_print_none=1 #用來設(shè)置在Inception返回結(jié)果集中,對于原來OSC在執(zhí)行過程的標(biāo)準(zhǔn)輸出信息是不是要打印到結(jié)果集對應(yīng)的錯誤信息列中,如果設(shè)置為1,就不打印,如果設(shè)置為0,就打印。而如果出現(xiàn)錯誤了,則都會打印

inception_osc_print_sql=1 #對應(yīng)參數(shù)--print

#備份服務(wù)器信息,注意改成你的機(jī)器.用于回滾。

inception_remote_system_password=P@ssw0rd

inception_remote_system_user=incep_rw

inception_remote_backup_port=3306

inception_remote_backup_host=10.10.3.70

inception_support_charset=utf8 #表示在建表或者建庫時支持的字符集,如果需要多個,則用逗號分隔,影響的范圍是建表、設(shè)置會話字符集、修改表字符集屬性等


啟動Inception程序
cd /usr/local/inception/bin

./Inception --defaults-file=/etc/inc.cnf &
[1] 11179
[root@b28-11-92 bin]# 2019-06-21 15:00:31 0 [Note] Welcome to use Inception2.1.50
2019-06-21 15:00:31 11179 [Note] Server hostname (bind-address): '*'; port: 6669
2019-06-21 15:00:31 11179 [Note] IPv6 is available.
2019-06-21 15:00:31 11179 [Note] - '::' resolves to '::';
2019-06-21 15:00:31 11179 [Note] Server socket created on IP: '::'.

查看Inception進(jìn)程
ps -ef | grep Inception
root 11179 30011 0 15:00 pts/1 00:00:00 ./Inception --defaults-file=/etc/inc.cnf

測試
mysql -uroot -h227.0.0.1 -P6669
連接成功后執(zhí)行 inception get variables;
輸出了所有的變量,表示已經(jīng)啟動成功了

Yearning 安裝
git clone https://github.com/cookieY/Yearning.git

登錄MySQL創(chuàng)建庫yearning庫
create database Yearning DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

安裝相應(yīng)python依賴庫
cd Yearning/src
pip install -r requirements.txt 
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting Django==2.1.5 (from -r requirements.txt (line 1))
Could not fetch URL https://pypi.python.org/simple/django/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement Django==2.1.5 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Django==2.1.5 (from -r requirements.txt (line 1))

修改Setup文件 
Python-3.6.4/Modules

vim Setup
#Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

#Socket module helper for SSL support; you must comment out the other
#socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

重新編譯
cd Python-3.6.4
./configure --enable-shared --prefix=/usr/local/python/3.6.4 LDFLAGS="-Wl,-rpath /usr/local/python/3.6.4/lib"
make
make install


配置,編輯Yearning/src/deploy.conf文件
[mysql]
db = 所創(chuàng)建的庫名
address = 數(shù)據(jù)庫地址
port = 數(shù)據(jù)庫端口
password = 數(shù)據(jù)庫密碼
username = 數(shù)據(jù)庫用戶

[host]
ipaddress = 服務(wù)器ip地址:端口 (涉及跨域十分重要!!設(shè)置不正確將無法登陸!!)
如 本機(jī)地址為192.168.137.13 nginx設(shè)置端口為80
則應(yīng)填寫為 192.168.137.13:80 之后通過該地址訪問平臺。

[Inception]
ip = Inception地址
port = Inception端口
user = Inception用戶名
password = Inception密碼
backupdb = 備份數(shù)據(jù)庫地址
backupport = 備份數(shù)據(jù)庫端口
backupuser = 備份數(shù)據(jù)庫用戶名
backuppassword = 備份數(shù)據(jù)庫密碼

[LDAP] LDAP相關(guān)設(shè)置
LDAP_SERVER = LDAP服務(wù)地址
LDAP_SCBASE = LDAP dc 設(shè)置 如 dc=xxx,dc=com
LDAP_DOMAIN = LDAP域名 如 xxx.com

[email] 郵箱推送相關(guān)設(shè)置
username = 郵箱發(fā)件賬號 如 xxxx@163.com
password = 郵箱發(fā)件賬號密碼
smtp_server = 郵箱stmp地址, 具體地址請咨詢對應(yīng)郵箱提供者

初始化數(shù)據(jù)庫
python manage.py makemigrations
python manage.py migrate

若報錯ModuleNotFoundError: No module named 'Crypto'
pip install pycrypto
重新初始化數(shù)據(jù)庫
python manage.py makemigrations

python manage.py migrate

添加初始化用戶
echo "from core.models import Account;Account.objects.create_user(username='admin', password='admin123456', group='admin',is_staff=1)" | python manage.py shell

初始化權(quán)限
echo "from core.models import grained;grained.objects.get_or_create(username='admin', permissions={'ddl': '1', 'ddlcon': [], 'dml': '1', 'dmlcon': [], 'dic': '1', 'diccon': [], 'dicedit': '0', 'query': '1', 'querycon': [], 'user': '1', 'base': '1', 'dicexport': '0'})" | python manage.py shell

復(fù)制編譯好的靜態(tài)文件到nginx html目錄下(dist目錄通過npm run build生成)
cd Yearning/webpage/dist
cp -rf * /usr/share/nginx/html/

/etc/init.d/nginx restart

啟動django
cd Yearning/src

python manage.py runserver 0.0.0.0:8000

訪問首頁http://192.168.17.77


注意事項(xiàng):
使用默認(rèn)賬號: admin 密碼:admin123456登陸即可使用,可能會出現(xiàn)登陸不了的情況(無法跳轉(zhuǎn)頁面),這是由于跨域的問題,解決這個問題可以參考:http://blog.csdn.net/apple9005/article/details/54427902

注意事項(xiàng)
默認(rèn)超級管理員只擁有各個頁面的訪問權(quán)限,其他的權(quán)限需自行增加!詳情請查看使用說明用戶管理
由于Inception 并不原生支持pymysql,所以需更改pymysql相關(guān)源碼
修改 $PYTHON_HOME/lib/python3.6/site-packages/pymysql下
connections.py 和 cursors.py 兩個文件

找到 connections.py 786行
if int(self.server_version.split('.', 1)[0]) >= 5:

self.client_flag |= CLIENT.MULTI_RESULTS

更改為:
try:

if int(self.server_version.split('.', 1)[0]) >= 5:

self.client_flag |= CLIENT.MULTI_RESULTS

except:

if self.server_version.split('.', 1)[0] >= 'Inception2':

self.client_flag |= CLIENT.MULTI_RESULTS

找到 cursors.py

if self._result and (self._result.has_next or not self._result.warning_count):

return

更改為
if self._result:

return

“Yearning + Inception SQL審核平臺搭建方法是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

sql
AI