mirror of https://github.com/midoks/mdserver-web
commit
e33bdc5b7d
@ -0,0 +1,186 @@ |
||||
# coding:utf-8 |
||||
|
||||
import sys |
||||
import io |
||||
import os |
||||
import time |
||||
import subprocess |
||||
import re |
||||
import json |
||||
|
||||
sys.path.append(os.getcwd() + "/class/core") |
||||
import mw |
||||
|
||||
|
||||
if mw.isAppleSystem(): |
||||
cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\'' |
||||
info = mw.execShell(cmd) |
||||
p = "/usr/local/lib/" + info[0].strip() + "/site-packages" |
||||
sys.path.append(p) |
||||
|
||||
|
||||
app_debug = False |
||||
if mw.isAppleSystem(): |
||||
app_debug = True |
||||
|
||||
|
||||
def getPluginName(): |
||||
return 'mariadb' |
||||
|
||||
|
||||
def getPluginDir(): |
||||
return mw.getPluginDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getSPluginDir(): |
||||
return '/www/server/mdserver-web/plugins/' + getPluginName() |
||||
|
||||
|
||||
def getServerDir(): |
||||
return mw.getServerDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getConf(): |
||||
path = getServerDir() + '/etc/my.cnf' |
||||
return path |
||||
|
||||
|
||||
def getDataDir(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = 'datadir\s*=\s*(.*)' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
|
||||
def getRelayLogName(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = 'relay-log\s*=\s*(.*)' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
|
||||
def getLogBinName(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = 'log-bin\s*=\s*(.*)' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
|
||||
def binLogListLook(args): |
||||
|
||||
file = args['file'] |
||||
line = args['line'] |
||||
|
||||
data_dir = getDataDir() |
||||
my_bin = getServerDir() + '/bin' |
||||
my_binlog_cmd = my_bin + '/mysqlbinlog' |
||||
|
||||
cmd = my_binlog_cmd + ' --no-defaults ' + \ |
||||
data_dir + '/' + file + '|tail -' + str(line) |
||||
|
||||
data = mw.execShell(cmd) |
||||
|
||||
rdata = {} |
||||
rdata['cmd'] = cmd |
||||
rdata['data'] = data[0] |
||||
|
||||
return rdata |
||||
|
||||
|
||||
def binLogListLookDecode(args): |
||||
|
||||
file = args['file'] |
||||
line = args['line'] |
||||
|
||||
data_dir = getDataDir() |
||||
my_bin = getServerDir() + '/bin' |
||||
my_binlog_cmd = my_bin + '/mysqlbinlog' |
||||
|
||||
cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ |
||||
data_dir + '/' + file + '|tail -' + str(line) |
||||
|
||||
data = mw.execShell(cmd) |
||||
|
||||
rdata = {} |
||||
rdata['cmd'] = cmd |
||||
rdata['data'] = data[0] |
||||
|
||||
return rdata |
||||
|
||||
|
||||
def binLogListTraceRelay(args): |
||||
rdata = {} |
||||
file = args['file'] |
||||
line = args['line'] |
||||
|
||||
relay_name = getRelayLogName() |
||||
data_dir = getDataDir() |
||||
alist = os.listdir(data_dir) |
||||
relay_list = [] |
||||
for x in range(len(alist)): |
||||
f = alist[x] |
||||
t = {} |
||||
if f.startswith(relay_name) and not f.endswith('.index'): |
||||
relay_list.append(f) |
||||
|
||||
relay_list = sorted(relay_list, reverse=True) |
||||
if len(relay_list) == 0: |
||||
rdata['cmd'] = '' |
||||
rdata['data'] = '无Relay日志' |
||||
return rdata |
||||
|
||||
file = relay_list[0] |
||||
|
||||
my_bin = getServerDir() + '/bin' |
||||
my_binlog_cmd = my_bin + '/mysqlbinlog' |
||||
|
||||
cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ |
||||
data_dir + '/' + file + '|tail -' + str(line) |
||||
|
||||
data = mw.execShell(cmd) |
||||
|
||||
rdata['cmd'] = cmd |
||||
rdata['data'] = data[0] |
||||
|
||||
return rdata |
||||
|
||||
|
||||
def binLogListTraceBinLog(args): |
||||
rdata = {} |
||||
file = args['file'] |
||||
line = args['line'] |
||||
|
||||
data_dir = getDataDir() |
||||
log_bin_name = getLogBinName() |
||||
|
||||
alist = os.listdir(data_dir) |
||||
log_bin_l = [] |
||||
for x in range(len(alist)): |
||||
f = alist[x] |
||||
t = {} |
||||
if f.startswith(log_bin_name) and not f.endswith('.index'): |
||||
log_bin_l.append(f) |
||||
|
||||
if len(log_bin_l) == 0: |
||||
rdata['cmd'] = '' |
||||
rdata['data'] = '无BINLOG' |
||||
return rdata |
||||
|
||||
log_bin_l = sorted(log_bin_l, reverse=True) |
||||
file = log_bin_l[0] |
||||
|
||||
my_bin = getServerDir() + '/bin' |
||||
my_binlog_cmd = my_bin + '/mysqlbinlog' |
||||
|
||||
cmd = my_binlog_cmd + ' --no-defaults --base64-output=decode-rows -vvvv ' + \ |
||||
data_dir + '/' + file + '|tail -' + str(line) |
||||
|
||||
data = mw.execShell(cmd) |
||||
|
||||
rdata['cmd'] = cmd |
||||
rdata['data'] = data[0] |
||||
|
||||
return rdata |
@ -0,0 +1,108 @@ |
||||
[client] |
||||
user = root |
||||
#password = your_password |
||||
port = 33206 |
||||
socket = {$SERVER_APP_PATH}/mysql.sock |
||||
default-character-set = UTF8MB4 |
||||
|
||||
[mysqld] |
||||
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf |
||||
|
||||
authentication_policy=mysql_native_password |
||||
pid-file = {$SERVER_APP_PATH}/data/mysql.pid |
||||
user = mysql |
||||
port = 33206 |
||||
mysqlx_port = 33260 |
||||
socket = {$SERVER_APP_PATH}/mysql.sock |
||||
datadir = {$SERVER_APP_PATH}/data |
||||
log-error = {$SERVER_APP_PATH}/data/error.log |
||||
server-id = {$SERVER_ID} |
||||
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES |
||||
|
||||
default_storage_engine = InnoDB |
||||
|
||||
key_buffer_size = 8M |
||||
table_open_cache = 32 |
||||
sort_buffer_size = 256K |
||||
net_buffer_length = 4K |
||||
read_buffer_size = 128K |
||||
read_rnd_buffer_size = 256K |
||||
myisam_sort_buffer_size = 4M |
||||
thread_cache_size = 4 |
||||
lower_case_table_names=1 |
||||
tmp_table_size = 8M |
||||
character-set-server = UTF8MB4 |
||||
|
||||
max_connections = 500 |
||||
max_connect_errors = 100 |
||||
open_files_limit = 2560 |
||||
max_allowed_packet = 128M |
||||
|
||||
#skip-external-locking |
||||
#skip-grant-tables |
||||
#loose-skip-innodb |
||||
#skip-networking |
||||
#skip-name-resolve |
||||
|
||||
log-bin=mysql-bin |
||||
binlog_format=mixed |
||||
slow_query_log=1 |
||||
slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log |
||||
long_query_time=3 |
||||
#log_queries_not_using_indexes=on |
||||
|
||||
relay-log=mdserver |
||||
relay-log-index=mdserver |
||||
|
||||
#master |
||||
#sync_binlog=1 |
||||
|
||||
#binlog-do-db |
||||
binlog-ignore-db = test |
||||
binlog-ignore-db = mysql |
||||
binlog-ignore-db = information_schema |
||||
binlog-ignore-db = performance_schema |
||||
|
||||
#slave |
||||
log_replica_updates |
||||
#replicate-do-db |
||||
slave_skip_errors=1062,1396 |
||||
replicate-ignore-db = information_schema |
||||
replicate-ignore-db = performance_schema |
||||
replicate-ignore-db = mysql |
||||
replicate-ignore-db = test |
||||
|
||||
master_info_repository = table |
||||
relay_log_info_repository = table |
||||
|
||||
default_storage_engine = InnoDB |
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data |
||||
innodb_data_file_path = ibdata1:10M:autoextend |
||||
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data |
||||
innodb_buffer_pool_size = 16M |
||||
innodb_redo_log_capacity=10485760 |
||||
innodb_log_buffer_size = 8M |
||||
innodb_flush_log_at_trx_commit = 1 |
||||
innodb_lock_wait_timeout = 120 |
||||
innodb_max_dirty_pages_pct = 90 |
||||
innodb_read_io_threads = 1 |
||||
innodb_write_io_threads = 1 |
||||
innodb_file_per_table=1 |
||||
binlog_expire_logs_seconds=2592000 |
||||
|
||||
secure-file-priv={$SERVER_APP_PATH}/tmp |
||||
|
||||
[mysqldump] |
||||
quick |
||||
|
||||
[mysql] |
||||
no-auto-rehash |
||||
|
||||
[myisamchk] |
||||
key_buffer_size = 20M |
||||
sort_buffer_size = 20M |
||||
read_buffer = 2M |
||||
write_buffer = 2M |
||||
|
||||
[mysqlhotcopy] |
||||
interactive-timeout |
@ -0,0 +1,140 @@ |
||||
# -*- coding: utf-8 -*- |
||||
#!/bin/bash |
||||
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||
export PATH |
||||
export DEBIAN_FRONTEND=noninteractive |
||||
|
||||
# https://downloads.mysql.com/archives/community/ |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
sysName=`uname` |
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl |
||||
myDir=${serverPath}/source/mysql-apt |
||||
|
||||
bash ${rootPath}/scripts/getos.sh |
||||
OSNAME=`cat ${rootPath}/data/osname.pl` |
||||
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'` |
||||
|
||||
# cd /www/server/mdserver-web/plugins/mysql-apt && bash install.sh install 8.0 |
||||
|
||||
# 暂时debian12没有标准版,先用11使用 |
||||
if [ "$OSNAME" == 'debian' ] && [ "$VERSION_ID" == '12' ] ;then |
||||
echo "暂时不支持该${OSNAME}${VERSION_ID}" > $install_tmp |
||||
exit 1 |
||||
fi |
||||
|
||||
|
||||
ARCH="amd64" |
||||
TMP_ARCH=`arch` |
||||
if [ "$TMP_ARCH" == "x86_64" ];then |
||||
ARCH="amd64" |
||||
elif [ "$TMP_ARCH" == "aarch64" ];then |
||||
ARCH="arm64" |
||||
else |
||||
ARCH="amd64" |
||||
fi |
||||
|
||||
if [ "$ARCH" != "amd64" ];then |
||||
echo "暂时不支持该${ARCH}" > $install_tmp |
||||
exit 1 |
||||
fi |
||||
|
||||
|
||||
MYSQL_VER=8.2.0 |
||||
SUFFIX_NAME=${MYSQL_VER}-1${OSNAME}${VERSION_ID}_${ARCH} |
||||
|
||||
|
||||
# /lib/systemd/system/mysql.service |
||||
# /etc/mysql/my.cnf |
||||
|
||||
APT_INSTALL() |
||||
{ |
||||
######## |
||||
mkdir -p $myDir |
||||
mkdir -p $serverPath/mysql-apt/bin |
||||
|
||||
wget --no-check-certificate -O ${myDir}/mysql-server_${SUFFIX_NAME}.deb-bundle.tar https://cdn.mysql.com/archives/mysql-8.2/mysql-server_${SUFFIX_NAME}.deb-bundle.tar |
||||
chmod +x ${myDir}/mysql-server_${SUFFIX_NAME}.deb-bundle.tar |
||||
cd ${myDir} && tar vxf ${myDir}/mysql-server_${SUFFIX_NAME}.deb-bundle.tar |
||||
|
||||
apt update -y |
||||
apt install -y libnuma1 libaio1 libmecab2 |
||||
|
||||
# 安装 |
||||
dpkg -X mysql-common_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
|
||||
|
||||
|
||||
dpkg -X mysql-community-client-plugins_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
dpkg -X mysql-community-client-core_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
dpkg -X mysql-community-client_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
dpkg -X mysql-client_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
|
||||
dpkg -X mysql-community-server-core_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
|
||||
dpkg -X mysql-community-server_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
dpkg -X mysql-server_${SUFFIX_NAME}.deb $serverPath/mysql-apt/bin |
||||
|
||||
# 测试时可关闭 |
||||
rm -rf $myDir |
||||
####### |
||||
} |
||||
|
||||
APT_UNINSTALL() |
||||
{ |
||||
### |
||||
rm -rf $myDir |
||||
# apt remove -y mysql-server |
||||
### |
||||
} |
||||
|
||||
|
||||
Install_mysql() |
||||
{ |
||||
echo '正在安装脚本文件...' > $install_tmp |
||||
if id mysql &> /dev/null ;then |
||||
echo "mysql uid is `id -u mysql`" |
||||
echo "mysql shell is `grep "^mysql:" /etc/passwd |cut -d':' -f7 `" |
||||
else |
||||
groupadd mysql |
||||
useradd -g mysql mysql |
||||
fi |
||||
|
||||
isApt=`which apt` |
||||
if [ "$isApt" != "" ];then |
||||
APT_INSTALL |
||||
fi |
||||
|
||||
if [ "$?" == "0" ];then |
||||
mkdir -p $serverPath/mysql-apt |
||||
echo '8.0' > $serverPath/mysql-apt/version.pl |
||||
echo '安装完成' > $install_tmp |
||||
else |
||||
echo '8.0' > $serverPath/mysql-apt/version.pl |
||||
echo "暂时不支持该系统" > $install_tmp |
||||
fi |
||||
} |
||||
|
||||
Uninstall_mysql() |
||||
{ |
||||
|
||||
isApt=`which apt` |
||||
if [ "$isApt" != "" ];then |
||||
APT_UNINSTALL |
||||
fi |
||||
|
||||
rm -rf $serverPath/mysql-apt |
||||
echo '卸载完成' > $install_tmp |
||||
} |
||||
|
||||
action=$1 |
||||
if [ "${1}" == 'install' ];then |
||||
Install_mysql |
||||
else |
||||
Uninstall_mysql |
||||
fi |
@ -0,0 +1,49 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||
export PATH |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
sourcePath=${serverPath}/source |
||||
sysName=`uname` |
||||
install_tmp=${rootPath}/tmp/mw_install.pl |
||||
|
||||
|
||||
#获取信息和版本 |
||||
# bash /www/server/mdsever-web/scripts/getos.sh |
||||
bash ${rootPath}/scripts/getos.sh |
||||
OSNAME=`cat ${rootPath}/data/osname.pl` |
||||
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'` |
||||
|
||||
version=8.3 |
||||
PHP_VER=83 |
||||
|
||||
|
||||
Install_php() |
||||
{ |
||||
#------------------------ install start ------------------------------------# |
||||
apt -y install php${version} php${version}-fpm php${version}-dev |
||||
if [ "$?" == "0" ];then |
||||
mkdir -p $serverPath/php-apt/${PHP_VER} |
||||
fi |
||||
|
||||
#------------------------ install end ------------------------------------# |
||||
} |
||||
|
||||
Uninstall_php() |
||||
{ |
||||
#------------------------ uninstall start ------------------------------------# |
||||
apt -y remove php${version} php${version}-* |
||||
rm -rf $serverPath/php-apt/${PHP_VER} |
||||
echo "卸载php-${version}..." > $install_tmp |
||||
#------------------------ uninstall start ------------------------------------# |
||||
} |
||||
|
||||
action=${1} |
||||
if [ "${1}" == 'install' ];then |
||||
Install_php |
||||
else |
||||
Uninstall_php |
||||
fi |
Loading…
Reference in new issue