mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 01:29:26 +08:00
manticoresearch初始化
This commit is contained in:
@@ -0,0 +1,486 @@
|
||||
# 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
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/mysql'
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/mysql'
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + '/etc/my.cnf'
|
||||
return path
|
||||
|
||||
def getDbPort():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'port\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
def getSocketFile():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'socket\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mysql.db'
|
||||
name = 'mysql'
|
||||
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
def pMysqlDb():
|
||||
# pymysql
|
||||
db = mw.getMyORM()
|
||||
|
||||
db.setPort(getDbPort())
|
||||
db.setSocket(getSocketFile())
|
||||
# db.setCharset("utf8")
|
||||
db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root'))
|
||||
return db
|
||||
|
||||
class sphinxMake():
|
||||
|
||||
pdb = None
|
||||
psdb = None
|
||||
|
||||
pkey_name_cache = {}
|
||||
delta = 'sph_counter'
|
||||
ver = ''
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.pdb = pMysqlDb()
|
||||
|
||||
def setDeltaName(self, name):
|
||||
self.delta = name
|
||||
return True
|
||||
|
||||
def setVersion(self, ver):
|
||||
self.ver = ver
|
||||
|
||||
def createSql(self, db):
|
||||
conf = '''
|
||||
CREATE TABLE IF NOT EXISTS `{$DB_NAME}`.`{$TABLE_NAME}` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`table` varchar(200) NOT NULL,
|
||||
`max_id` bigint(20) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `table_uniq` (`table`),
|
||||
KEY `table` (`table`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 CHARSET=utf8mb4;
|
||||
'''
|
||||
conf = conf.replace("{$TABLE_NAME}", self.delta)
|
||||
conf = conf.replace("{$DB_NAME}", db)
|
||||
return conf
|
||||
|
||||
def eqVerField(self, field):
|
||||
ver = self.ver.replace(".1",'')
|
||||
if float(ver) >= 3.6:
|
||||
if field == 'sql_attr_timestamp':
|
||||
return 'attr_bigint'
|
||||
|
||||
if field == 'sql_attr_bigint':
|
||||
return 'attr_bigint'
|
||||
|
||||
if field == 'sql_attr_float':
|
||||
return 'attr_float'
|
||||
|
||||
if field == 'sql_field_string':
|
||||
return 'field_string'
|
||||
|
||||
if float(ver) >= 3.3:
|
||||
if field == 'sql_attr_timestamp':
|
||||
return 'sql_attr_bigint'
|
||||
|
||||
return field
|
||||
|
||||
def pathVerName(self):
|
||||
ver = self.ver.replace(".1",'')
|
||||
# if float(ver) >= 3.6:
|
||||
# return 'datadir'
|
||||
return 'path'
|
||||
|
||||
def getTablePk(self, db, table):
|
||||
key = db+'_'+table
|
||||
if key in self.pkey_name_cache:
|
||||
return self.pkey_name_cache[key]
|
||||
|
||||
# SHOW INDEX FROM bbs.bbs_ucenter_vars WHERE Key_name = 'PRIMARY'
|
||||
pkey_sql = "SHOW INDEX FROM {}.{} WHERE Key_name = 'PRIMARY';".format(db,table,);
|
||||
pkey_data = self.pdb.query(pkey_sql)
|
||||
|
||||
# print(db, table)
|
||||
# print(pkey_data)
|
||||
key = ''
|
||||
if len(pkey_data) == 1:
|
||||
pkey_name = pkey_data[0]['Column_name']
|
||||
sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}' and `COLUMN_NAME`='{}';"
|
||||
sql = sql.format(db,table,pkey_name,)
|
||||
# print(sql)
|
||||
fields = self.pdb.query(sql)
|
||||
|
||||
if len(fields) == 1:
|
||||
# print(fields[0]['DATA_TYPE'])
|
||||
if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], fields[0]['DATA_TYPE']):
|
||||
key = pkey_name
|
||||
return key
|
||||
|
||||
|
||||
def getTableFieldStr(self, db, table):
|
||||
sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';"
|
||||
sql = sql.format(db,table,)
|
||||
fields = self.pdb.query(sql)
|
||||
|
||||
field_str = ''
|
||||
for x in range(len(fields)):
|
||||
field_str += '`'+fields[x]['COLUMN_NAME']+'`,'
|
||||
|
||||
field_str = field_str.strip(',')
|
||||
return field_str
|
||||
|
||||
def makeSphinxHeader(self):
|
||||
conf = '''
|
||||
indexer
|
||||
{
|
||||
mem_limit = 128M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$server_dir}/sphinx/index/searchd.log
|
||||
query_log = {$server_dir}/sphinx/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$server_dir}/sphinx/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$server_dir}/sphinx/index/binlog
|
||||
}
|
||||
'''
|
||||
conf = conf.replace("{$server_dir}", mw.getServerDir())
|
||||
return conf
|
||||
|
||||
def makeSphinxDbSourceRangeSql(self, db, table):
|
||||
pkey_name = self.getTablePk(db,table)
|
||||
sql = "SELECT min("+pkey_name+"), max("+pkey_name+") FROM "+table
|
||||
return sql
|
||||
|
||||
def makeSphinxDbSourceQuerySql(self, db, table):
|
||||
pkey_name = self.getTablePk(db,table)
|
||||
field_str = self.getTableFieldStr(db,table)
|
||||
# print(field_str)
|
||||
if pkey_name == 'id':
|
||||
sql = "SELECT " + field_str + " FROM " + table + " where id >= $start AND id <= $end"
|
||||
else:
|
||||
sql = "SELECT `"+pkey_name+'` as `id`,' + field_str + " FROM " + table + " where "+pkey_name+" >= $start AND "+pkey_name+" <= $end"
|
||||
return sql
|
||||
|
||||
|
||||
def makeSphinxDbSourceDeltaRange(self, db, table):
|
||||
pkey_name = self.getTablePk(db,table)
|
||||
conf = "SELECT (SELECT max_id FROM `{$SPH_TABLE}` where `table`='{$TABLE_NAME}') as min, (SELECT max({$PK_NAME}) FROM {$TABLE_NAME}) as max"
|
||||
conf = conf.replace("{$DB_NAME}", db)
|
||||
conf = conf.replace("{$TABLE_NAME}", table)
|
||||
conf = conf.replace("{$SPH_TABLE}", self.delta)
|
||||
conf = conf.replace("{$PK_NAME}", pkey_name)
|
||||
return conf
|
||||
|
||||
def makeSphinxDbSourcePost(self, db, table):
|
||||
pkey_name = self.getTablePk(db,table)
|
||||
conf = "sql_query_post = UPDATE {$SPH_TABLE} SET max_id=(SELECT MAX({$PK_NAME}) FROM {$TABLE_NAME}) where `table`='{$TABLE_NAME}'"
|
||||
# conf = "REPLACE INTO {$SPH_TABLE} (`table`,`max_id`) VALUES ('{$TABLE_NAME}',(SELECT MAX({$PK_NAME}) FROM {$TABLE_NAME}))"
|
||||
conf = conf.replace("{$DB_NAME}", db)
|
||||
conf = conf.replace("{$TABLE_NAME}", table)
|
||||
conf = conf.replace("{$SPH_TABLE}", self.delta)
|
||||
conf = conf.replace("{$PK_NAME}", pkey_name)
|
||||
return conf
|
||||
|
||||
def makeSphinxDbSourceDelta(self, db, table):
|
||||
conf = '''
|
||||
source {$DB_NAME}_{$TABLE_NAME}_delta:{$DB_NAME}_{$TABLE_NAME}
|
||||
{
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query_range = {$DELTA_RANGE}
|
||||
sql_query = {$DELTA_QUERY}
|
||||
{$DELTA_UPDATE}
|
||||
|
||||
{$SPH_FIELD}
|
||||
}
|
||||
|
||||
index {$DB_NAME}_{$TABLE_NAME}_delta:{$DB_NAME}_{$TABLE_NAME}
|
||||
{
|
||||
source = {$DB_NAME}_{$TABLE_NAME}_delta
|
||||
{$PATH_NAME} = {$server_dir}/sphinx/index/db/{$DB_NAME}.{$TABLE_NAME}/delta
|
||||
|
||||
html_strip = 1
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
|
||||
{$SPH_FIELD_INDEX}
|
||||
}
|
||||
''';
|
||||
conf = conf.replace("{$server_dir}", mw.getServerDir())
|
||||
conf = conf.replace("{$PATH_NAME}", self.pathVerName())
|
||||
|
||||
conf = conf.replace("{$DB_NAME}", db)
|
||||
conf = conf.replace("{$TABLE_NAME}", table)
|
||||
|
||||
delta_range = self.makeSphinxDbSourceDeltaRange(db, table)
|
||||
conf = conf.replace("{$DELTA_RANGE}", delta_range)
|
||||
|
||||
delta_query = self.makeSphinxDbSourceQuerySql(db, table)
|
||||
conf = conf.replace("{$DELTA_QUERY}", delta_query)
|
||||
|
||||
delta_update = self.makeSphinxDbSourcePost(db, table)
|
||||
conf = conf.replace("{$DELTA_UPDATE}", delta_update)
|
||||
|
||||
|
||||
sph_field = self.makeSqlToSphinxTable(db, table)
|
||||
conf = self.makeSphinxDbFieldRepalce(conf, sph_field)
|
||||
|
||||
return conf;
|
||||
|
||||
def makeSphinxDbSource(self, db, table, create_sphinx_table = False):
|
||||
db_info = pSqliteDb('databases').field('username,password').where('name=?', (db,)).find()
|
||||
port = getDbPort()
|
||||
|
||||
conf = '''
|
||||
source {$DB_NAME}_{$TABLE_NAME}
|
||||
{
|
||||
type = mysql
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = {$DB_USER}
|
||||
sql_pass = {$DB_PASS}
|
||||
sql_db = {$DB_NAME}
|
||||
sql_port = {$DB_PORT}
|
||||
|
||||
sql_query_pre = SET NAMES utf8
|
||||
|
||||
{$UPDATE}
|
||||
|
||||
sql_query_range = {$DB_RANGE_SQL}
|
||||
sql_range_step = 1000
|
||||
|
||||
sql_query = {$DB_QUERY_SQL}
|
||||
|
||||
{$SPH_FIELD}
|
||||
}
|
||||
|
||||
index {$DB_NAME}_{$TABLE_NAME}
|
||||
{
|
||||
source = {$DB_NAME}_{$TABLE_NAME}
|
||||
{$PATH_NAME} = {$server_dir}/sphinx/index/db/{$DB_NAME}.{$TABLE_NAME}/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
|
||||
{$SPH_FIELD_INDEX}
|
||||
}
|
||||
'''
|
||||
conf = conf.replace("{$server_dir}", mw.getServerDir())
|
||||
conf = conf.replace("{$PATH_NAME}", self.pathVerName())
|
||||
|
||||
conf = conf.replace("{$DB_NAME}", db)
|
||||
conf = conf.replace("{$TABLE_NAME}", table)
|
||||
conf = conf.replace("{$DB_USER}", db_info['username'])
|
||||
conf = conf.replace("{$DB_PASS}", db_info['password'])
|
||||
conf = conf.replace("{$DB_PORT}", port)
|
||||
|
||||
range_sql = self.makeSphinxDbSourceRangeSql(db, table)
|
||||
conf = conf.replace("{$DB_RANGE_SQL}", range_sql)
|
||||
|
||||
query_sql = self.makeSphinxDbSourceQuerySql(db, table)
|
||||
conf = conf.replace("{$DB_QUERY_SQL}", query_sql)
|
||||
|
||||
sph_field = self.makeSqlToSphinxTable(db, table)
|
||||
# conf = conf.replace("{$SPH_FIELD}", sph_field)
|
||||
|
||||
|
||||
conf = self.makeSphinxDbFieldRepalce(conf, sph_field)
|
||||
|
||||
if create_sphinx_table:
|
||||
update = self.makeSphinxDbSourcePost(db, table)
|
||||
conf = conf.replace("{$UPDATE}", update)
|
||||
else:
|
||||
conf = conf.replace("{$UPDATE}", '')
|
||||
|
||||
if create_sphinx_table:
|
||||
sph_sql = self.createSql(db)
|
||||
self.pdb.query(sph_sql)
|
||||
sql_find = "select * from {}.{} where `table`='{}'".format(db,self.delta,table)
|
||||
find_data = self.pdb.query(sql_find)
|
||||
if len(find_data) == 0:
|
||||
insert_sql = "insert into `{}`.`{}`(`table`,`max_id`) values ('{}',{}) ".format(db,self.delta,table,0)
|
||||
# print(insert_sql)
|
||||
self.pdb.execute(insert_sql)
|
||||
conf += self.makeSphinxDbSourceDelta(db,table)
|
||||
|
||||
# print(ver)
|
||||
# print(conf)
|
||||
|
||||
return conf
|
||||
|
||||
def makeSphinxDbFieldRepalce(self, content, sph_field):
|
||||
ver = self.ver.replace(".1",'')
|
||||
ver = float(ver)
|
||||
if ver >= 3.6:
|
||||
content = content.replace("{$SPH_FIELD}", '')
|
||||
content = content.replace("{$SPH_FIELD_INDEX}", '')
|
||||
else:
|
||||
content = content.replace("{$SPH_FIELD}", sph_field)
|
||||
content = content.replace("{$SPH_FIELD_INDEX}", '')
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def makeSqlToSphinxDb(self, db, table = [], is_delta = False):
|
||||
conf = ''
|
||||
|
||||
|
||||
for tn in table:
|
||||
pkey_name = self.getTablePk(db,tn)
|
||||
if pkey_name == '':
|
||||
continue
|
||||
conf += self.makeSphinxDbSource(db, tn,is_delta)
|
||||
|
||||
if len(table) == 0:
|
||||
tables = self.pdb.query("show tables in "+ db)
|
||||
for x in range(len(tables)):
|
||||
key = 'Tables_in_'+db
|
||||
table_name = tables[x][key]
|
||||
pkey_name = self.getTablePk(db, table_name, is_delta)
|
||||
if pkey_name == '':
|
||||
continue
|
||||
|
||||
if self.makeSqlToSphinxTableIsHaveFulltext(db, table_name):
|
||||
conf += self.makeSphinxDbSource(db, table_name)
|
||||
return conf
|
||||
|
||||
def makeSqlToSphinxTableIsHaveFulltext(self, db, table):
|
||||
sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';"
|
||||
sql = sql.format(db,table,)
|
||||
cols = self.pdb.query(sql)
|
||||
cols_len = len(cols)
|
||||
|
||||
for x in range(cols_len):
|
||||
data_type = cols[x]['DATA_TYPE']
|
||||
column_name = cols[x]['COLUMN_NAME']
|
||||
|
||||
if mw.inArray(['varchar'], data_type):
|
||||
return True
|
||||
if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type):
|
||||
return True
|
||||
return False
|
||||
|
||||
def makeSqlToSphinxTable(self,db,table):
|
||||
pkey_name = self.getTablePk(db,table)
|
||||
sql = "select COLUMN_NAME,DATA_TYPE from information_schema.COLUMNS where `TABLE_SCHEMA`='{}' and `TABLE_NAME` = '{}';"
|
||||
sql = sql.format(db,table,)
|
||||
cols = self.pdb.query(sql)
|
||||
cols_len = len(cols)
|
||||
conf = ''
|
||||
run_pos = 0
|
||||
for x in range(cols_len):
|
||||
data_type = cols[x]['DATA_TYPE']
|
||||
column_name = cols[x]['COLUMN_NAME']
|
||||
# print(column_name+":"+data_type)
|
||||
|
||||
# if mw.inArray(['tinyint'], data_type):
|
||||
# conf += 'sql_attr_bool = '+ column_name + "\n"
|
||||
|
||||
if pkey_name == column_name:
|
||||
# run_pos += 1
|
||||
# conf += '\tsql_attr_bigint = '+column_name+"\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['enum'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_attr_string')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['decimal'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_attr_float')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['bigint','smallint','tinyint','int','mediumint'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_attr_bigint')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
|
||||
if mw.inArray(['float'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_attr_float')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['char'], data_type):
|
||||
conf += '\t'+self.eqVerField('sql_attr_string')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['varchar'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_field_string')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['text','mediumtext','tinytext','longtext'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_field_string')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
if mw.inArray(['datetime','date'], data_type):
|
||||
run_pos += 1
|
||||
conf += '\t'+self.eqVerField('sql_attr_timestamp')+' = '+ column_name + "\n"
|
||||
continue
|
||||
|
||||
return conf
|
||||
|
||||
def checkDbName(self, db):
|
||||
filter_db = ['information_schema','performance_schema','sys','mysql']
|
||||
if db in filter_db:
|
||||
return False
|
||||
return True
|
||||
|
||||
def makeSqlToSphinx(self, db, tables = [], is_delta = False):
|
||||
conf = ''
|
||||
conf += self.makeSphinxHeader()
|
||||
conf += self.makeSqlToSphinxDb(db, tables, is_delta)
|
||||
return conf
|
||||
|
||||
def makeSqlToSphinxAll(self):
|
||||
filter_db = ['information_schema','performance_schema','sys','mysql']
|
||||
|
||||
dblist = self.pdb.query('show databases')
|
||||
|
||||
conf = ''
|
||||
conf += self.makeSphinxHeader()
|
||||
|
||||
# conf += makeSqlToSphinxDb(pdb, 'bbs')
|
||||
for x in range(len(dblist)):
|
||||
dbname = dblist[x]['Database']
|
||||
if mw.inArray(filter_db, dbname):
|
||||
continue
|
||||
conf += self.makeSqlToSphinxDb(dbname)
|
||||
return conf
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
}
|
||||
|
||||
index mydocs
|
||||
{
|
||||
type = rt
|
||||
path = {$SERVER_APP}/bin/doc
|
||||
rt_field = title
|
||||
rt_attr_json = j
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Executable
+36
@@ -0,0 +1,36 @@
|
||||
|
||||
<style>
|
||||
|
||||
#table xm-select{
|
||||
min-height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
#table xm-select *{
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('sphinx');">服务</p>
|
||||
<p onclick="pluginInitD('sphinx');">自启动</p>
|
||||
<p onclick="pluginConfigTpl('sphinx','', 'conf','config_tpl','read_config_tpl',tryRebuildIndex);">配置修改</p>
|
||||
<p onclick="pluginLogs('sphinx','','run_log',30);">运行日志</p>
|
||||
<p onclick="pluginLogs('sphinx','','query_log', 30);">查询日志</p>
|
||||
<p onclick="runStatus();">运行状态</p>
|
||||
<p onclick="commonFunc();">常用功能</p>
|
||||
<p onclick="readme();">说明</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con" style="height:425px;overflow: auto;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinHeight(500);
|
||||
$.getScript( "/plugins/file?name=sphinx&f=js/sphinx.js", function(){
|
||||
pluginService('sphinx');
|
||||
});
|
||||
</script>
|
||||
Executable
+483
@@ -0,0 +1,483 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import string
|
||||
import subprocess
|
||||
|
||||
web_dir = os.getcwd() + "/web"
|
||||
if os.path.exists(web_dir):
|
||||
sys.path.append(web_dir)
|
||||
os.chdir(web_dir)
|
||||
|
||||
import core.mw as mw
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
def getPluginName():
|
||||
return 'manticoresearch'
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() +"/class")
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getConfTpl():
|
||||
path = getPluginDir() + "/conf/sphinx.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + "/sphinx.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def configTpl():
|
||||
path = getPluginDir() + '/tpl'
|
||||
pathFile = os.listdir(path)
|
||||
tmp = []
|
||||
for one in pathFile:
|
||||
file = path + '/' + one
|
||||
tmp.append(file)
|
||||
return mw.getJson(tmp)
|
||||
|
||||
|
||||
def readConfigTpl():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
content = mw.readFile(args['file'])
|
||||
content = contentReplace(content)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getFatherDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP}', service_path + '/sphinx')
|
||||
return content
|
||||
|
||||
|
||||
def status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep sphinx |grep -v grep | grep -v mdserver-web | awk '{print $2}'")
|
||||
# print(data)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def mkdirAll():
|
||||
content = mw.readFile(getConf())
|
||||
rep = r'path\s*=\s*(.*)'
|
||||
p = re.compile(rep)
|
||||
tmp = p.findall(content)
|
||||
|
||||
for x in tmp:
|
||||
if x.find('binlog') != -1:
|
||||
mw.execShell('mkdir -p ' + x)
|
||||
else:
|
||||
mw.execShell('mkdir -p ' + os.path.dirname(x))
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = mw.getServerDir()
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
conf_bin = getConf()
|
||||
if not os.path.exists(conf_bin):
|
||||
conf_content = mw.readFile(getConfTpl())
|
||||
conf_content = contentReplace(conf_content)
|
||||
mw.writeFile(getServerDir() + '/sphinx.conf', conf_content)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/sphinx.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/sphinx.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
mkdirAll()
|
||||
return file_bin
|
||||
|
||||
|
||||
def checkIndexSph():
|
||||
content = mw.readFile(getConf())
|
||||
rep = r'path\s*=\s*(.*)'
|
||||
p = re.compile(rep)
|
||||
tmp = p.findall(content)
|
||||
for x in tmp:
|
||||
if x.find('binlog') != -1:
|
||||
continue
|
||||
else:
|
||||
p = x + '.sph'
|
||||
if os.path.exists(p):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def sphOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' sphinx')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def start():
|
||||
# import tool_cron
|
||||
# tool_cron.createBgTask()
|
||||
return sphOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
# import tool_cron
|
||||
# tool_cron.removeBgTask()
|
||||
return sphOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
return sphOp('restart')
|
||||
|
||||
|
||||
def reload():
|
||||
return sphOp('reload')
|
||||
|
||||
|
||||
def rebuild():
|
||||
file = initDreplace()
|
||||
cmd = file + ' rebuild'
|
||||
data = mw.execShell(cmd)
|
||||
if data[0].find('successfully')<0:
|
||||
return data[0].replace("\n","<br/>")
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
shell_cmd = 'systemctl status sphinx | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl enable sphinx')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl disable sphinx')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
path = getConf()
|
||||
content = mw.readFile(path)
|
||||
rep = r'log\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def getPort():
|
||||
path = getConf()
|
||||
content = mw.readFile(path)
|
||||
rep = r'listen\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def queryLog():
|
||||
path = getConf()
|
||||
content = mw.readFile(path)
|
||||
rep = r'query_log\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def runStatus():
|
||||
s = status()
|
||||
if s != 'start':
|
||||
return mw.returnJson(False, '没有启动程序')
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import sphinxapi
|
||||
|
||||
sh = sphinxapi.SphinxClient()
|
||||
port = getPort()
|
||||
sh.SetServer('127.0.0.1', port)
|
||||
info_status = sh.Status()
|
||||
|
||||
rData = {}
|
||||
for x in range(len(info_status)):
|
||||
rData[info_status[x][0]] = info_status[x][1]
|
||||
|
||||
return mw.returnJson(True, 'ok', rData)
|
||||
|
||||
|
||||
def sphinxConfParse():
|
||||
file = getConf()
|
||||
bin_dir = getServerDir()
|
||||
content = mw.readFile(file)
|
||||
rep = r'index\s(.*)'
|
||||
sindex = re.findall(rep, content)
|
||||
indexlen = len(sindex)
|
||||
cmd = {}
|
||||
cmd['cmd'] = bin_dir + '/bin/bin/indexer -c ' + bin_dir + '/sphinx.conf'
|
||||
|
||||
cmd['index'] = []
|
||||
cmd_index = []
|
||||
cmd_delta = []
|
||||
if indexlen > 0:
|
||||
for x in range(indexlen):
|
||||
name = sindex[x].strip()
|
||||
if name == '':
|
||||
continue
|
||||
if name.find(':') != -1:
|
||||
cmd_delta.append(name.strip())
|
||||
else:
|
||||
cmd_index.append(name.strip())
|
||||
|
||||
# print(cmd_index)
|
||||
# print(cmd_delta)
|
||||
|
||||
for ci in cmd_index:
|
||||
val = {}
|
||||
val['index'] = ci
|
||||
|
||||
for cd in cmd_delta:
|
||||
cd = cd.replace(" ", '')
|
||||
if cd.find(":"+ci) > -1:
|
||||
val['delta'] = cd.split(":")[0].strip()
|
||||
break
|
||||
|
||||
cmd['index'].append(val)
|
||||
return cmd
|
||||
|
||||
|
||||
def sphinxCmd():
|
||||
data = sphinxConfParse()
|
||||
if 'index' in data:
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
else:
|
||||
return mw.returnJson(False, 'no index')
|
||||
|
||||
def makeDbToSphinxTest():
|
||||
conf_file = getConf()
|
||||
import sphinx_make
|
||||
sph_make = sphinx_make.sphinxMake()
|
||||
conf = sph_make.makeSqlToSphinxAll()
|
||||
|
||||
mw.writeFile(conf_file,conf)
|
||||
print(conf)
|
||||
# makeSqlToSphinxTable()
|
||||
return True
|
||||
|
||||
def makeDbToSphinx():
|
||||
args = getArgs()
|
||||
check = checkArgs(args, ['db','tables','is_delta','is_cover'])
|
||||
if not check[0]:
|
||||
return check[1]
|
||||
|
||||
db = args['db']
|
||||
tables = args['tables']
|
||||
is_delta = args['is_delta']
|
||||
is_cover = args['is_cover']
|
||||
|
||||
if is_cover != 'yes':
|
||||
return mw.returnJson(False,'暂时仅支持覆盖!')
|
||||
|
||||
sph_file = getConf()
|
||||
|
||||
import sphinx_make
|
||||
sph_make = sphinx_make.sphinxMake()
|
||||
|
||||
version_pl = getServerDir() + "/version.pl"
|
||||
if os.path.exists(version_pl):
|
||||
version = mw.readFile(version_pl).strip()
|
||||
sph_make.setVersion(version)
|
||||
|
||||
if not sph_make.checkDbName(db):
|
||||
return mw.returnJson(False,'保留数据库名称,不可用!')
|
||||
is_delta_bool = False
|
||||
if is_delta == 'yes':
|
||||
is_delta_bool = True
|
||||
if is_cover == 'yes':
|
||||
tables = tables.split(',')
|
||||
content = sph_make.makeSqlToSphinx(db, tables, is_delta_bool)
|
||||
mw.writeFile(sph_file,content)
|
||||
return mw.returnJson(True,'设置成功!')
|
||||
|
||||
return mw.returnJson(True,'测试中')
|
||||
|
||||
|
||||
# 全量更新
|
||||
def updateAll():
|
||||
data = sphinxConfParse()
|
||||
cmd = data['cmd']
|
||||
if not 'index' in data:
|
||||
return '无更新'
|
||||
index = data['index']
|
||||
|
||||
for x in range(len(index)):
|
||||
cmd_index = cmd + ' ' + index[x]['index'] + ' --rotate'
|
||||
print(cmd_index)
|
||||
os.system(cmd_index)
|
||||
return ''
|
||||
|
||||
#增量更新
|
||||
def updateDelta():
|
||||
data = sphinxConfParse()
|
||||
cmd = data['cmd']
|
||||
if not 'index' in data:
|
||||
return '无更新'
|
||||
index = data['index']
|
||||
|
||||
for x in range(len(index)):
|
||||
if 'delta' in index[x]:
|
||||
cmd_index = cmd + ' ' + index[x]['delta'] + ' --rotate'
|
||||
print(cmd_index)
|
||||
os.system(cmd_index)
|
||||
|
||||
cmd_index_merge = cmd + ' --merge ' + index[x]['index'] + ' ' + index[x]['delta'] + ' --rotate'
|
||||
print(cmd_index_merge)
|
||||
os.system(cmd_index_merge)
|
||||
else:
|
||||
print(index[x]['index'],'no delta')
|
||||
|
||||
return ''
|
||||
|
||||
def installPreInspection(version):
|
||||
data = mw.execShell('arch')
|
||||
if data[0].strip().startswith('aarch'):
|
||||
return '不支持aarch架构'
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
version = "3.1.1"
|
||||
version_pl = getServerDir() + "/version.pl"
|
||||
if os.path.exists(version_pl):
|
||||
version = mw.readFile(version_pl).strip()
|
||||
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'rebuild':
|
||||
print(rebuild())
|
||||
elif func == 'initd_status':
|
||||
print(initdStatus())
|
||||
elif func == 'initd_install':
|
||||
print(initdInstall())
|
||||
elif func == 'initd_uninstall':
|
||||
print(initdUinstall())
|
||||
elif func == 'install_pre_inspection':
|
||||
print(installPreInspection(version))
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'config_tpl':
|
||||
print(configTpl())
|
||||
elif func == 'read_config_tpl':
|
||||
print(readConfigTpl())
|
||||
elif func == 'run_log':
|
||||
print(runLog())
|
||||
elif func == 'query_log':
|
||||
print(queryLog())
|
||||
elif func == 'run_status':
|
||||
print(runStatus())
|
||||
elif func == 'sphinx_cmd':
|
||||
print(sphinxCmd())
|
||||
elif func == 'db_to_sphinx':
|
||||
print(makeDbToSphinx())
|
||||
elif func == 'update_all':
|
||||
print(updateAll())
|
||||
elif func == 'update_delta':
|
||||
print(updateDelta())
|
||||
else:
|
||||
print('error')
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "是一个高性能开源搜索引擎,基于C++开发,由SphinxSearch项目演变而来,专注于提升搜索效率与扩展性",
|
||||
"name": "manticoresearch",
|
||||
"title": "manticoresearch",
|
||||
"shell": "install.sh",
|
||||
"versions":["7.4.6"],
|
||||
"tip": "soft",
|
||||
"install_pre_inspection":true,
|
||||
"checks": "server/manticoresearch",
|
||||
"path": "server/manticoresearch",
|
||||
"display": 1,
|
||||
"author": "manticoresoftware",
|
||||
"date": "2025-07-21",
|
||||
"home": "https://github.com/manticoresoftware/manticoresearch/",
|
||||
"doc1": "https://manual.manticoresearch.com/Introduction",
|
||||
"type": 0,
|
||||
"pid": "2"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Open Source Search Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart={$SERVER_PATH}/sphinx/bin/bin/searchd -c {$SERVER_PATH}/sphinx/sphinx.conf
|
||||
ExecReload=/bin/kill -USR2 $MAINPID
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,82 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# searchd: sphinx Daemon
|
||||
#
|
||||
# chkconfig: - 90 25
|
||||
# description: sphinx Daemon
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: sphinx
|
||||
# Required-Start: $syslog
|
||||
# Required-Stop: $syslog
|
||||
# Should-Start: $local_fs
|
||||
# Should-Stop: $local_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: sphinx - Document Index Daemon
|
||||
# Description: sphinx - Document Index Daemon
|
||||
### END INIT INFO
|
||||
|
||||
APP_PATH={$SERVER_APP}
|
||||
APP_CONF={$SERVER_APP}/sphinx.conf
|
||||
prog="sphinx"
|
||||
|
||||
start () {
|
||||
echo -n $"Starting $prog: "
|
||||
${APP_PATH}/bin/bin/searchd -c ${APP_CONF}
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
}
|
||||
|
||||
rebuild () {
|
||||
${APP_PATH}/bin/bin/indexer -c ${APP_CONF} --all --rotate
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
echo -n $"Stopping $prog: "
|
||||
if [ ! -e ${APP_PATH}/index/searchd.pid ]; then
|
||||
echo -n $"$prog is not running."
|
||||
exit 1
|
||||
fi
|
||||
kill `cat ${APP_PATH}/index/searchd.pid`
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
rm -f ${APP_PATH}/index/searchd.pid
|
||||
echo " done"
|
||||
fi
|
||||
}
|
||||
|
||||
restart () {
|
||||
$0 stop
|
||||
sleep 2
|
||||
$0 start
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart|reload)
|
||||
restart
|
||||
;;
|
||||
rebuild)
|
||||
rebuild
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart|reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit $?
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
sysArch=`arch`
|
||||
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
ACTION=$1
|
||||
VERSION=$2
|
||||
|
||||
which apt
|
||||
if [ "$?" == "0" ];then
|
||||
sh -x $curPath/versions/apt/install.sh $1 $2
|
||||
fi
|
||||
|
||||
which yum
|
||||
if [ "$?" == "0" ];then
|
||||
sh -x $curPath/versions/yum/install.sh $1 $2
|
||||
fi
|
||||
Executable
+311
@@ -0,0 +1,311 @@
|
||||
function spPostMin(method, args, callback){
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'sphinx';
|
||||
req_data['func'] = method;
|
||||
|
||||
if (typeof(args) != 'undefined' && args!=''){
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/run', req_data, function(data) {
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function myPost(method, args, callback, title){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var _title = '正在获取...';
|
||||
if (typeof(title) != 'undefined'){
|
||||
_title = title;
|
||||
}
|
||||
|
||||
$.post('/plugins/run', {name:'mysql', func:method, args:_args}, function(data) {
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function spPost(method, args, callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
spPostMin(method,args,function(data){
|
||||
layer.close(loadT);
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function commonFunc(){
|
||||
var con = '<button class="btn btn-default btn-sm" onclick="confirmRebuildIndex();">重建索引</button>';
|
||||
con += ' <button class="btn btn-default btn-sm" onclick="autoMakeConf();">自动创建配置</button>';
|
||||
$(".soft-man-con").html(con);
|
||||
}
|
||||
|
||||
function autoMakeConf(){
|
||||
var xm_db_list;
|
||||
|
||||
var con = '<ul class="help-info-text c7">';
|
||||
con += '<li style="color:red;">如果数据量比较大,第一次启动会失败!(可通过手动建立索引)</li>';
|
||||
con += '<li style="color:red;">以下内容,需手动加入计划任务。</li>';
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['380px','350px'],
|
||||
title: '自动创建配置',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
btn:["提交","关闭"],
|
||||
content: "<form class='bt-form pd20'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>选择数据库</span>\
|
||||
<div class='info-r'>\
|
||||
<select class='bt-input-text mr5' name='dbname' style='width:100%'>\
|
||||
<option value=''>无</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>选择表</span>\
|
||||
<div class='info-r'>\
|
||||
<div id='table'></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>是否增量</span>\
|
||||
<div class='info-r'>\
|
||||
<select class='bt-input-text mr5' name='is_delta' style='width:100px'>\
|
||||
<option value='no'>否</option>\
|
||||
<option value='yes'>是</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>是否覆盖配置</span>\
|
||||
<div class='info-r'>\
|
||||
<select class='bt-input-text mr5' name='is_cover' style='width:100px'>\
|
||||
<option value='yes'>是</option>\
|
||||
<option value='no'>否</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<ul class='help-info-text c7'>\
|
||||
<li style='color:red;'>具体配置,仍须手动修改!!!</li>\
|
||||
<li style='color:red;'>增量索引,需要有更新权限,主从分离时,需要主库配置</li>\
|
||||
</ul>\
|
||||
</form>\
|
||||
",
|
||||
|
||||
success:function(l,i){
|
||||
$(l).find('.layui-layer-content').css('overflow','visible');
|
||||
|
||||
xm_db_list = xmSelect.render({
|
||||
el: '#table',
|
||||
repeat: false,
|
||||
toolbar: {show: true},
|
||||
data: [],
|
||||
});
|
||||
|
||||
myPost('get_db_list', {"page":1,"page_size":20}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var dblist = rdata.data;
|
||||
|
||||
var db_html = '';
|
||||
for (var i = 0; i < dblist.length; i++) {
|
||||
db_html += "<option value='"+dblist[i]['name']+"'>"+dblist[i]['name']+"</option>";
|
||||
}
|
||||
|
||||
if (dblist.length > 0){
|
||||
initDbSelect(dblist[0]['name']);
|
||||
}
|
||||
$('select[name="dbname"]').html(db_html);
|
||||
});
|
||||
|
||||
$('select[name="dbname"]').change(function(){
|
||||
var db = $('select[name="dbname"]').val();
|
||||
initDbSelect(db);
|
||||
});
|
||||
|
||||
},
|
||||
yes:function(index){
|
||||
var args = {}
|
||||
args['db'] = $('select[name="dbname"]').val();
|
||||
args['is_delta'] = $('select[name="is_delta"]').val();
|
||||
args['is_cover'] = $('select[name="is_cover"]').val();
|
||||
args['tables'] = xm_db_list.getValue('value').join(',');
|
||||
// console.log(args);
|
||||
spPost('db_to_sphinx', args, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
// console.log(rdata);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
layer.close(index);
|
||||
confirmRebuildIndex();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function initDbSelect(db){
|
||||
if (db == ''){
|
||||
return;
|
||||
}
|
||||
getDbInfo(db, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var tables = rdata.tables;
|
||||
|
||||
var idx_db = [];
|
||||
for (var i = 0; i < tables.length; i++) {
|
||||
var t = {};
|
||||
t['name'] = tables[i]['table_name'];
|
||||
t['value'] = tables[i]['table_name'];
|
||||
idx_db.push(t);
|
||||
}
|
||||
xm_db_list = xmSelect.render({el: '#table', filterable: true,repeat: false,toolbar: {show: true},data: idx_db,});
|
||||
});
|
||||
}
|
||||
|
||||
function getDbInfo(db_name, callback){
|
||||
myPost('get_db_info', {name:db_name}, function(data){
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function rebuildIndex(){
|
||||
spPost('rebuild', '', function(data){
|
||||
if (data.data == 'ok'){
|
||||
layer.msg('重建成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
} else {
|
||||
layer.msg(data.data,{icon:2,time:10000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function confirmRebuildIndex(){
|
||||
layer.confirm("是否重建索引?", {icon:3,closeBtn: 1} , function(){
|
||||
rebuildIndex();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function tryRebuildIndex(){
|
||||
layer.confirm("修改配置后,是否尝试重建索引!", {icon:3,closeBtn: 1} , function(){
|
||||
rebuildIndex();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function secToTime(s) {
|
||||
var t;
|
||||
if(s > -1){
|
||||
var hour = Math.floor(s/3600);
|
||||
var min = Math.floor(s/60) % 60;
|
||||
var sec = s % 60;
|
||||
if(hour < 10) {
|
||||
t = '0'+ hour + ":";
|
||||
} else {
|
||||
t = hour + ":";
|
||||
}
|
||||
|
||||
if(min < 10){t += "0";}
|
||||
t += min + ":";
|
||||
if(sec < 10){t += "0";}
|
||||
t += sec.toFixed(2);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
function runStatus(){
|
||||
spPost('run_status', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata['status']){
|
||||
layer.msg(rdata['msg'],{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
var idata = rdata.data;
|
||||
|
||||
var tbody = '';
|
||||
for (var i in idata) {
|
||||
tbody += '<tr><th>'+i+'</th><td>' + idata[i] + '</td><td colspan="2">'+i+'</td></tr>';
|
||||
}
|
||||
|
||||
var con = '<div class="divtable"><table class="table table-hover table-bordered" style="margin-bottom:10px;background-color:#fafafa">\
|
||||
<tbody>\
|
||||
<tr><th>运行时间</th><td>' + secToTime(idata.uptime) + '</td><th>每秒查询</th><td>' + parseInt(parseInt(idata.queries) / parseInt(idata.uptime)) + '</td></tr>\
|
||||
<tr><th>总连接次数</th><td>' + idata.connections + '</td><th>work_queue_length</th><td>' +idata.work_queue_length + '</td></tr>\
|
||||
<tr><th>agent_connect</th><td>' + idata.agent_connect+ '</td><th>workers_active</th><td>' + idata.workers_active + '</td></tr>\
|
||||
<tr><th>agent_retry</th><td>' + idata.agent_retry + '</td><th>workers_total</th><td>' + idata.workers_total + '</td></tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
<table class="table table-hover table-bordered">\
|
||||
<thead style="display:none;"><th></th><th></th><th></th><th></th></thead>\
|
||||
<tbody>\
|
||||
'+tbody+'\
|
||||
<tbody>\
|
||||
</table>\
|
||||
</div>';
|
||||
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
}
|
||||
|
||||
function readme(){
|
||||
spPost('sphinx_cmd', '', function(data){
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata['status']){
|
||||
layer.msg(rdata['msg'],{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(rdata['data']);
|
||||
var con = '<ul class="help-info-text c7">';
|
||||
|
||||
con += '<li style="color:red;">如果数据量比较大,第一次启动会失败!(可通过手动建立索引)</li>';
|
||||
con += '<li style="color:red;">以下内容,需手动加入计划任务。</li>';
|
||||
|
||||
con += '<li>全量:' + rdata['data']['cmd'] + ' --all --rotate</li>';
|
||||
|
||||
//主索引
|
||||
for (var i = 0; i < rdata['data']['index'].length; i++) {
|
||||
var index_kv = rdata['data']['index'][i];
|
||||
var index = index_kv['index'];
|
||||
// console.log(index);
|
||||
con += '<li>主索引 :' + rdata['data']['cmd'] + ' '+ index +' --rotate</li>';
|
||||
if (typeof(index_kv['delta']) != 'undefined'){
|
||||
var delta = index_kv['delta'];
|
||||
con += '<li>增量索引 :' + rdata['data']['cmd'] + ' '+ delta +' --rotate</li>';
|
||||
con += '<li>合并索引 :' + rdata['data']['cmd'] + ' --merge '+ index + ' ' + delta +' --rotate</li>';
|
||||
}
|
||||
}
|
||||
con += '</ul>';
|
||||
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
|
||||
web_dir = os.getcwd() + "/web"
|
||||
if os.path.exists(web_dir):
|
||||
sys.path.append(web_dir)
|
||||
os.chdir(web_dir)
|
||||
|
||||
import core.mw as mw
|
||||
from utils.crontab import crontab as MwCrontab
|
||||
|
||||
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'manticoresearch'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getTaskConf():
|
||||
conf = getServerDir() + "/cron_config.json"
|
||||
return conf
|
||||
|
||||
def getTaskDeltaConf():
|
||||
conf = getServerDir() + "/cron_delta_config.json"
|
||||
return conf
|
||||
|
||||
def getConfigData():
|
||||
conf = getTaskConf()
|
||||
if os.path.exists(conf):
|
||||
return json.loads(mw.readFile(getTaskConf()))
|
||||
return {
|
||||
"task_id": -1,
|
||||
"period": "day-n",
|
||||
"where1": "1",
|
||||
"hour": "0",
|
||||
"minute": "15",
|
||||
}
|
||||
|
||||
def getConfigDeltaData():
|
||||
conf = getTaskDeltaConf()
|
||||
if os.path.exists(conf):
|
||||
return json.loads(mw.readFile(getTaskDeltaConf()))
|
||||
return {
|
||||
"task_id": -1,
|
||||
"period": "minute-n",
|
||||
"where1": "3",
|
||||
"hour": "0",
|
||||
"minute": "0",
|
||||
}
|
||||
|
||||
|
||||
def createBgTask():
|
||||
removeBgTask()
|
||||
removeDeltaBgTask()
|
||||
|
||||
createBgTaskByName(getPluginName())
|
||||
createBgTaskDeltaByName(getPluginName())
|
||||
return True
|
||||
|
||||
|
||||
def createBgTaskByName(name):
|
||||
args = getConfigData()
|
||||
_name = "[勿删]Sphinx全量更新[" + name + "]"
|
||||
res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find()
|
||||
if res:
|
||||
return True
|
||||
|
||||
if "task_id" in args and args["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where("id=?", (args["task_id"],)).find()
|
||||
if res and res["id"] == args["task_id"]:
|
||||
print("计划任务已经存在!")
|
||||
return True
|
||||
|
||||
mw_dir = mw.getPanelDir()
|
||||
cmd = '''
|
||||
mw_dir=%s
|
||||
rname=%s
|
||||
plugin_path=%s
|
||||
script_path=%s
|
||||
logs_file=$plugin_path/${rname}.log
|
||||
''' % (mw_dir, name, getServerDir(), getPluginDir())
|
||||
cmd += 'echo "★【`date +"%Y-%m-%d %H:%M:%S"`】 STSRT★" >> $logs_file' + "\n"
|
||||
cmd += 'echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> $logs_file' + "\n"
|
||||
cmd += 'echo "python3 $script_path/index.py update_all"' + "\n"
|
||||
cmd += 'cd $mw_dir && python3 $script_path/index.py update_all' + "\n"
|
||||
cmd += 'echo "【`date +"%Y-%m-%d %H:%M:%S"`】 END★" >> $logs_file' + "\n"
|
||||
cmd += 'echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file' + "\n"
|
||||
|
||||
params = {
|
||||
'name': _name,
|
||||
'type': args['period'],
|
||||
'week': "",
|
||||
'where1': args['where1'],
|
||||
'hour': args['hour'],
|
||||
'minute': args['minute'],
|
||||
'save': "",
|
||||
'backup_to': "",
|
||||
'stype': "toShell",
|
||||
'sname': '',
|
||||
'sbody': cmd,
|
||||
'url_address': '',
|
||||
}
|
||||
|
||||
task_id = MwCrontab.instance().add(params)
|
||||
if task_id > 0:
|
||||
args["task_id"] = task_id
|
||||
args["name"] = name
|
||||
mw.writeFile(getTaskConf(), json.dumps(args))
|
||||
|
||||
def createBgTaskDeltaByName(name):
|
||||
args = getConfigDeltaData()
|
||||
_name = "[勿删]Sphinx增量更新[" + name + "]"
|
||||
res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find()
|
||||
if res:
|
||||
return True
|
||||
|
||||
if "task_id" in args and args["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where("id=?", (args["task_id"],)).find()
|
||||
if res and res["id"] == args["task_id"]:
|
||||
print("计划任务已经存在!")
|
||||
return True
|
||||
|
||||
mw_dir = mw.getPanelDir()
|
||||
cmd = '''
|
||||
mw_dir=%s
|
||||
rname=%s
|
||||
plugin_path=%s
|
||||
script_path=%s
|
||||
logs_file=$plugin_path/${rname}.log
|
||||
''' % (mw_dir, name, getServerDir(), getPluginDir())
|
||||
cmd += 'echo "★【`date +"%Y-%m-%d %H:%M:%S"`】 STSRT★" >> $logs_file' + "\n"
|
||||
cmd += 'echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> $logs_file' + "\n"
|
||||
cmd += 'echo "python3 $script_path/index.py update_delta"' + "\n"
|
||||
cmd += 'cd $mw_dir && python3 $script_path/index.py update_delta' + "\n"
|
||||
cmd += 'echo "【`date +"%Y-%m-%d %H:%M:%S"`】 END★" >> $logs_file' + "\n"
|
||||
cmd += 'echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file' + "\n"
|
||||
|
||||
params = {
|
||||
'name': _name,
|
||||
'type': args['period'],
|
||||
'week': "",
|
||||
'where1': args['where1'],
|
||||
'hour': args['hour'],
|
||||
'minute': args['minute'],
|
||||
'save': "",
|
||||
'backup_to': "",
|
||||
'stype': "toShell",
|
||||
'sname': '',
|
||||
'sbody': cmd,
|
||||
'url_address': '',
|
||||
}
|
||||
|
||||
task_id = MwCrontab.instance().add(params)
|
||||
if task_id > 0:
|
||||
args["task_id"] = task_id
|
||||
args["name"] = name
|
||||
mw.writeFile(getTaskConf(), json.dumps(args))
|
||||
|
||||
|
||||
def removeBgTask():
|
||||
cfg = getConfigData()
|
||||
if "task_id" in cfg and cfg["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where(
|
||||
"id=?", (cfg["task_id"],)).find()
|
||||
if res and res["id"] == cfg["task_id"]:
|
||||
data = MwCrontab.instance().delete(cfg["task_id"])
|
||||
if data[0]:
|
||||
cfg["task_id"] = -1
|
||||
mw.writeFile(getTaskConf(), json.dumps(cfg))
|
||||
return True
|
||||
return False
|
||||
|
||||
def removeDeltaBgTask():
|
||||
cfg = getConfigDeltaData()
|
||||
if "task_id" in cfg and cfg["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where(
|
||||
"id=?", (cfg["task_id"],)).find()
|
||||
if res and res["id"] == cfg["task_id"]:
|
||||
data = MwCrontab.instance().delete(cfg["task_id"])
|
||||
if data[0]:
|
||||
cfg["task_id"] = -1
|
||||
mw.writeFile(getTaskDeltaConf(), json.dumps(cfg))
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
action = sys.argv[1]
|
||||
if action == "remove":
|
||||
removeBgTask()
|
||||
removeDeltaBgTask()
|
||||
elif action == "add":
|
||||
createBgTask()
|
||||
@@ -0,0 +1,127 @@
|
||||
#
|
||||
# Discuz Sphinx Config File
|
||||
#
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 32M
|
||||
write_buffer = 64M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
}
|
||||
|
||||
|
||||
source pre_forum_thread
|
||||
{
|
||||
type = mysql
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = bbs
|
||||
sql_pass = bbs
|
||||
sql_db = bbs
|
||||
sql_port = 3306
|
||||
sql_query_pre = SET NAMES UTF8
|
||||
sql_query_pre = SET SESSION query_cache_type=OFF
|
||||
sql_query_pre = REPLACE INTO bbs_common_sphinxcounter SELECT 1, MAX(tid) FROM bbs_forum_thread
|
||||
sql_query = SELECT t.tid as id,t.tid,t.subject,t.digest,t.displayorder,t.authorid,t.lastpost,t.special \
|
||||
FROM bbs_forum_thread AS t WHERE t.tid>=$start AND t.tid<=$end
|
||||
sql_query_range = SELECT (SELECT MIN(tid) FROM bbs_forum_thread),maxid FROM bbs_common_sphinxcounter WHERE indexid=1
|
||||
|
||||
sql_range_step = 5000
|
||||
sql_attr_uint = tid
|
||||
|
||||
sql_attr_uint = digest
|
||||
sql_attr_uint = displayorder
|
||||
sql_attr_uint = authorid
|
||||
sql_attr_uint = special
|
||||
sql_attr_timestamp =lastpost
|
||||
}
|
||||
|
||||
index pre_forum_thread
|
||||
{
|
||||
source = pre_forum_thread
|
||||
path = {$SERVER_APP}/index/db/pre_forum_thread/index
|
||||
|
||||
min_word_len = 2
|
||||
html_strip = 1
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
|
||||
|
||||
# threads_minute
|
||||
source pre_forum_thread_minute : pre_forum_thread
|
||||
{
|
||||
sql_query_pre = SET NAMES UTF8
|
||||
sql_query_pre = SET SESSION query_cache_type=OFF
|
||||
sql_query_range = SELECT maxid-1,(SELECT MAX(tid) FROM bbs_forum_thread) FROM bbs_common_sphinxcounter WHERE indexid=1
|
||||
}
|
||||
|
||||
# threads_minute
|
||||
index pre_forum_thread_minute : pre_forum_thread
|
||||
{
|
||||
source = pre_forum_thread_minute
|
||||
path = {$SERVER_APP}/index/db/pre_forum_thread/pre_forum_thread_minute
|
||||
}
|
||||
|
||||
#posts
|
||||
source pre_forum_post : pre_forum_thread
|
||||
{
|
||||
type = mysql
|
||||
sql_query_pre =
|
||||
sql_query_pre = SET NAMES UTF8
|
||||
sql_query_pre = SET SESSION query_cache_type=OFF
|
||||
sql_query_pre = REPLACE INTO bbs_common_sphinxcounter SELECT 2, MAX(pid) FROM bbs_forum_post
|
||||
sql_query = SELECT p.pid AS id,p.tid,p.subject,p.message,t.digest,t.displayorder,t.authorid,t.lastpost,t.special \
|
||||
FROM bbs_forum_post AS p LEFT JOIN bbs_forum_thread AS t USING(tid) where p.pid >=$start and p.pid <=$end \
|
||||
AND p.first=1
|
||||
sql_query_range = SELECT (SELECT MIN(pid) FROM bbs_forum_post),maxid FROM bbs_common_sphinxcounter WHERE indexid=2
|
||||
sql_range_step = 5000
|
||||
sql_attr_uint = tid
|
||||
sql_attr_uint = digest
|
||||
sql_attr_uint= displayorder
|
||||
sql_attr_uint = authorid
|
||||
sql_attr_uint = special
|
||||
sql_attr_timestamp = lastpost
|
||||
}
|
||||
|
||||
#posts
|
||||
index pre_forum_post
|
||||
{
|
||||
source = pre_forum_post
|
||||
path = {$SERVER_APP}/index/db/pre_forum_thread/pre_forum_post
|
||||
|
||||
min_word_len = 2
|
||||
html_strip = 1
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
|
||||
#pre_forum_post_minute
|
||||
source pre_forum_post_minute : pre_forum_post
|
||||
{
|
||||
sql_query_pre = SET NAMES UTF8
|
||||
sql_query_pre = SET SESSION query_cache_type=OFF
|
||||
sql_query_range = SELECT maxid-1,(SELECT MAX(pid) FROM bbs_forum_post) FROM bbs_common_sphinxcounter WHERE indexid=2
|
||||
}
|
||||
|
||||
#pre_forum_post_minute
|
||||
index pre_forum_post_minute : pre_forum_post
|
||||
{
|
||||
source = pre_forum_thread
|
||||
path = {$SERVER_APP}/index/db/pre_forum_thread/pre_forum_post_minute
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
#
|
||||
# Maccms Sphinx Config File
|
||||
#
|
||||
|
||||
# 创建统计表
|
||||
# CREATE TABLE `sph_counter` ( `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT, `counter_id` bigint(20) unsigned NOT NULL,`max_doc_id` bigint(20) unsigned NOT NULL,PRIMARY KEY (`id`))
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 32M
|
||||
write_buffer = 64M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
}
|
||||
|
||||
|
||||
# -------- maccms 全量更新 start --------
|
||||
|
||||
source mac_vod
|
||||
{
|
||||
type = mysql
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = maccms
|
||||
sql_pass = maccms
|
||||
sql_db = maccms
|
||||
sql_port = 3306
|
||||
sql_query_range = SELECT min(vod_id), max(vod_id) FROM mac_vod
|
||||
sql_query_pre = SET NAMES UTF8
|
||||
sql_query_pre = SET SESSION query_cache_type=OFF
|
||||
sql_query = SELECT vod_id as id, vod_name, vod_tag, vod_class, vod_actor, vod_director, vod_time,vod_time_add FROM mac_vod WHERE vod_status=1 and vod_id>=$start AND vod_id<=$end
|
||||
sql_range_step = 1000
|
||||
|
||||
|
||||
sql_attr_uint = vod_id
|
||||
sql_attr_timestamp = vod_time
|
||||
sql_attr_timestamp = vod_time_add
|
||||
sql_field_string = vod_name
|
||||
|
||||
sql_query_post = UPDATE sph_counter SET max_doc_id=(SELECT MAX(vod_id) FROM mac_vod) where counter_id=1
|
||||
}
|
||||
|
||||
index mac_vod
|
||||
{
|
||||
source = mac_vod
|
||||
path = {$SERVER_APP}/index/db/maccms/index
|
||||
|
||||
min_word_len = 2
|
||||
html_strip = 1
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
|
||||
# -------- maccms 全量更新 end --------
|
||||
|
||||
|
||||
# -------- maccms 增量更新 start --------
|
||||
|
||||
|
||||
source mac_vod_delta : mac_vod
|
||||
{
|
||||
sql_query_pre = SET NAMES utf8
|
||||
|
||||
sql_query_range = SELECT (SELECT max_doc_id FROM `sph_counter` where counter_id=1) as min, (SELECT max(vod_id) FROM mac_vod) as max
|
||||
|
||||
sql_query = SELECT vod_id as id, vod_name, vod_tag, vod_class, vod_actor, vod_director, vod_time,vod_time_add FROM mac_vod WHERE vod_status=1 and vod_id>=$start AND vod_id<=$end
|
||||
|
||||
sql_query_post = UPDATE sph_counter SET max_doc_id=(SELECT MAX(vod_id) FROM mac_vod) where counter_id=1
|
||||
}
|
||||
|
||||
index mac_vod_delta : mac_vod
|
||||
{
|
||||
source = mac_vod_delta
|
||||
path = {$SERVER_APP}/index/db/maccms_delta/index
|
||||
|
||||
min_word_len = 2
|
||||
html_strip = 1
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
|
||||
# -------- maccms 增量更新 end --------
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
}
|
||||
|
||||
index mydocs
|
||||
{
|
||||
type = rt
|
||||
path = {$SERVER_APP}/bin/doc
|
||||
rt_field = title
|
||||
rt_attr_json = j
|
||||
}
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 32M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/binlog
|
||||
}
|
||||
|
||||
source qbittorrent
|
||||
{
|
||||
type = mysql
|
||||
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = qbittorrent
|
||||
sql_pass = qbittorrent
|
||||
sql_db = qbittorrent
|
||||
sql_port = 3306 # optional, default is 3306
|
||||
|
||||
sql_query_range = SELECT min(id), max(id) FROM pl_hash_list
|
||||
sql_range_step = 1000
|
||||
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = SELECT id, name, UNIX_TIMESTAMP(create_time) AS create_time \
|
||||
FROM pl_hash_list where status=0 and id >= $start AND id <= $end
|
||||
|
||||
sql_attr_timestamp = create_time
|
||||
}
|
||||
|
||||
|
||||
index qbittorrent
|
||||
{
|
||||
source = qbittorrent
|
||||
path = {$SERVER_APP}/index/db/qbittorrent/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 32M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
}
|
||||
|
||||
source search_hash
|
||||
{
|
||||
type = mysql
|
||||
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = ssbc
|
||||
sql_pass = ssbc
|
||||
sql_db = ssbc
|
||||
sql_port = 3306 # optional, default is 3306
|
||||
|
||||
sql_query_range = SELECT min(id), max(id) FROM search_hash
|
||||
sql_range_step = 1000
|
||||
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = \
|
||||
SELECT id, name, CRC32(category) AS category, length, UNIX_TIMESTAMP(create_time) AS create_time, UNIX_TIMESTAMP(last_seen) AS last_seen\
|
||||
FROM search_hash where id >= $start AND id <= $end AND is_has=1
|
||||
|
||||
sql_attr_bigint = length
|
||||
sql_attr_timestamp = create_time
|
||||
sql_attr_timestamp = last_seen
|
||||
sql_attr_uint = category
|
||||
|
||||
}
|
||||
|
||||
|
||||
index search_hash
|
||||
{
|
||||
source = search_hash
|
||||
path = {$SERVER_APP}/index/db/search_hash/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 128M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/index/binlog
|
||||
}
|
||||
|
||||
source search_hash
|
||||
{
|
||||
type = mysql
|
||||
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = ssbc
|
||||
sql_pass = ssbc
|
||||
sql_db = ssbc
|
||||
sql_port = 3306 # optional, default is 3306
|
||||
|
||||
sql_query_pre = UPDATE sph_counter SET max_doc_id=(SELECT MAX(id) FROM search_hash) where counter_id=1
|
||||
|
||||
sql_query_range = SELECT min(id), max(id) FROM search_hash
|
||||
sql_range_step = 1000
|
||||
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = SELECT * from ( SELECT s1.id id, s1.name name, s1.category category, s1.length length, UNIX_TIMESTAMP(s1.create_time) as create_time, UNIX_TIMESTAMP(s1.last_seen) as last_seen, s2.file_list file_list, s1.info_hash info_hash FROM search_hash s1 left join search_filelist s2 on s1.info_hash=s2.info_hash where s1.is_has=1 and s1.id >= $start AND s1.id <= $end ) as s WHERE s.file_list is not null
|
||||
|
||||
sql_attr_bigint = length
|
||||
sql_attr_timestamp = create_time
|
||||
sql_attr_timestamp = last_seen
|
||||
sql_attr_uint = category
|
||||
}
|
||||
|
||||
source search_hash_delta : search_hash
|
||||
{
|
||||
sql_query_range = SELECT (SELECT max_doc_id FROM `sph_counter` where counter_id=1) as min, (SELECT max(id) FROM search_hash) as max
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = SELECT * from ( SELECT s1.id id, s1.name name, s1.category category, s1.length length, UNIX_TIMESTAMP(s1.create_time) as create_time, UNIX_TIMESTAMP(s1.last_seen) as last_seen, s2.file_list file_list, s1.info_hash info_hash FROM search_hash s1 left join search_filelist s2 on s1.info_hash=s2.info_hash where s1.is_has=1 and s1.id >= $start AND s1.id <= $end ) as s WHERE s.file_list is not null
|
||||
sql_attr_bigint = length
|
||||
sql_attr_timestamp = create_time
|
||||
sql_attr_timestamp = last_seen
|
||||
sql_attr_uint = category
|
||||
sql_query_post = UPDATE sph_counter SET max_doc_id=(SELECT MAX(id) FROM search_hash) where counter_id=1
|
||||
}
|
||||
|
||||
|
||||
index search_hash
|
||||
{
|
||||
source = search_hash
|
||||
path = {$SERVER_APP}/index/db/search_hash/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
|
||||
index search_hash_delta : search_hash
|
||||
{
|
||||
source = search_hash_delta
|
||||
path = {$SERVER_APP}/index/db/search_hash_delta/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# Minimal Sphinx configuration sample (clean, simple, functional)
|
||||
#
|
||||
|
||||
indexer
|
||||
{
|
||||
mem_limit = 32M
|
||||
}
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
log = {$SERVER_APP}/index/searchd.log
|
||||
query_log = {$SERVER_APP}/index/query.log
|
||||
read_timeout = 5
|
||||
max_children = 0
|
||||
pid_file = {$SERVER_APP}/index/searchd.pid
|
||||
seamless_rotate = 1
|
||||
preopen_indexes = 1
|
||||
unlink_old = 1
|
||||
#workers = threads # for RT to work
|
||||
binlog_path = {$SERVER_APP}/binlog
|
||||
}
|
||||
|
||||
source sp_video
|
||||
{
|
||||
type = mysql
|
||||
|
||||
sql_host = 127.0.0.1
|
||||
sql_user = video_spider
|
||||
sql_pass = video_spider
|
||||
sql_db = video_spider
|
||||
sql_port = 3306 # optional, default is 3306
|
||||
|
||||
sql_query_range = SELECT min(id), max(id) FROM sp_video
|
||||
sql_range_step = 1000
|
||||
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = SELECT id, name, UNIX_TIMESTAMP(create_time) AS create_time, UNIX_TIMESTAMP(update_time) AS update_time \
|
||||
FROM sp_video where id >= $start AND id <= $end
|
||||
|
||||
sql_attr_bigint = length
|
||||
sql_attr_timestamp = create_time
|
||||
sql_attr_timestamp = update_time
|
||||
sql_attr_uint = category
|
||||
|
||||
}
|
||||
|
||||
|
||||
index sp_video
|
||||
{
|
||||
source = sp_video
|
||||
path = {$SERVER_APP}/index/db/sp_video/index
|
||||
|
||||
ngram_len = 1
|
||||
ngram_chars = U+3000..U+2FA1F
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
sysArch=`arch`
|
||||
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild
|
||||
# cd /www/server/mdserver-web/plugins/sphinx && bash install.sh install 3.6.1
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx && /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate
|
||||
# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py sphinx_cmd
|
||||
|
||||
# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py start
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
# echo "bash ${rootPath}/scripts/getos.sh"
|
||||
OSNAME="macos"
|
||||
if [ -f ${rootPath}/data/osname.pl ];then
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
fi
|
||||
|
||||
if [ "${OSNAME}" == "centos" ] ||
|
||||
[ "${OSNAME}" == "fedora" ] ||
|
||||
[ "${OSNAME}" == "alma" ]; then
|
||||
yum install -y postgresql-libs unixODBC
|
||||
fi
|
||||
|
||||
# http://sphinxsearch.com/files/sphinx-3.7.1-da9f8a4-linux-amd64.tar.gz
|
||||
|
||||
VERSION=$2
|
||||
|
||||
# echo $VERSION
|
||||
|
||||
if [ "$VERSION" == "3.1.1" ];then
|
||||
VERSION_NUM=${VERSION}-612d99f
|
||||
elif [ "$VERSION" == "3.2.1" ]; then
|
||||
VERSION_NUM=${VERSION}-f152e0b
|
||||
elif [ "$VERSION" == "3.3.1" ]; then
|
||||
VERSION_NUM=${VERSION}-b72d67b
|
||||
elif [ "$VERSION" == "3.4.1" ]; then
|
||||
VERSION_NUM=${VERSION}-efbcc65
|
||||
elif [ "$VERSION" == "3.5.1" ]; then
|
||||
VERSION_NUM=${VERSION}-82c60cb
|
||||
elif [ "$VERSION" == "3.6.1" ]; then
|
||||
VERSION_NUM=${VERSION}-c9dbeda
|
||||
elif [ "$VERSION" == "3.7.1" ]; then
|
||||
VERSION_NUM=${VERSION}-da9f8a4
|
||||
elif [ "$VERSION" == "3.8.1" ]; then
|
||||
VERSION_NUM=${VERSION}-d25e0bb
|
||||
fi
|
||||
|
||||
# echo $VERSION_NUM
|
||||
|
||||
Install_App()
|
||||
{
|
||||
echo '正在安装Sphinx...'
|
||||
mkdir -p $serverPath/sphinx
|
||||
|
||||
SPHINX_DIR=${serverPath}/source/sphinx
|
||||
mkdir -p $SPHINX_DIR
|
||||
|
||||
SPH_NAME=amd64
|
||||
if [ "$sysArch" == "arm64" ];then
|
||||
SPH_NAME=amd64
|
||||
elif [ "$sysArch" == "x86_64" ]; then
|
||||
SPH_NAME=amd64
|
||||
elif [ "$sysArch" == "aarch64" ]; then
|
||||
SPH_NAME=aarch64
|
||||
fi
|
||||
|
||||
if [ "$sysName" == "Darwin" ] && [ "$VERSION" == "3.7.1" ];then
|
||||
SPH_NAME=aarch64
|
||||
fi
|
||||
|
||||
SPH_SYSNAME=linux
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
SPH_SYSNAME=darwin
|
||||
elif [ "$sysName" == "aarch64" ]; then
|
||||
SPH_NAME=aarch64
|
||||
elif [ "$sysName" == "freebsd" ]; then
|
||||
SPH_NAME=freebsd
|
||||
fi
|
||||
|
||||
if [ "$SPH_SYSNAME" == "linux" ];then
|
||||
glibc_ver=`ldd --version | grep libc | awk -F ')' '{print $2}'|awk '{gsub(/^\s+|\s+$/, "");print}'`
|
||||
if [ "$VERSION" == "3.7.1" ] && [ `echo "2.29 > $glibc_ver " | bc` -eq 1 ];then
|
||||
SPH_NAME=${SPH_NAME}-glibc2.17
|
||||
fi
|
||||
if [ "$VERSION" == "3.6.1" ] && [ `echo "2.29 > $glibc_ver " | bc` -eq 1 ];then
|
||||
SPH_NAME=${SPH_NAME}-glibc2.17
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
FILE_NAME=sphinx-${VERSION_NUM}-${SPH_SYSNAME}-${SPH_NAME}
|
||||
FILE_TGZ=${FILE_NAME}.tar.gz
|
||||
|
||||
echo $FILE_TGZ
|
||||
# curl -sSLo ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ}
|
||||
if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then
|
||||
wget --no-check-certificate -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ}
|
||||
fi
|
||||
|
||||
cd ${SPHINX_DIR} && tar -zxvf ${FILE_TGZ}
|
||||
|
||||
if [ "$?" == "0" ];then
|
||||
mkdir -p $SPHINX_DIR
|
||||
cp -rf ${SPHINX_DIR}/sphinx-${VERSION}/ $serverPath/sphinx/bin
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/sphinx ];then
|
||||
echo "${VERSION}" > $serverPath/sphinx/version.pl
|
||||
echo '安装Sphinx完成'
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py start
|
||||
|
||||
if [ $sysName != 'Darwin' ]; then
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py initd_install
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d ${SPHINX_DIR}/sphinx-${VERSION} ];then
|
||||
rm -rf ${SPHINX_DIR}/sphinx-${VERSION}
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
if [ -f /usr/lib/systemd/system/sphinx.service ] || [ -f /lib/systemd/system/sphinx.service ];then
|
||||
systemctl stop sphinx
|
||||
systemctl disable sphinx
|
||||
|
||||
if [ -f /usr/lib/systemd/system/sphinx.service ];then
|
||||
rm -rf /usr/lib/systemd/system/sphinx.service
|
||||
fi
|
||||
|
||||
if [ -f /lib/systemd/system/sphinx.service ];then
|
||||
rm -rf /lib/systemd/system/sphinx.service
|
||||
fi
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
if [ -f $serverPath/sphinx/initd/sphinx ];then
|
||||
$serverPath/sphinx/initd/sphinx stop
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/sphinx ];then
|
||||
echo "rm -rf $serverPath/sphinx"
|
||||
rm -rf $serverPath/sphinx
|
||||
fi
|
||||
|
||||
echo "卸载sphinx成功"
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
sysArch=`arch`
|
||||
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py rebuild
|
||||
# cd /www/server/mdserver-web/plugins/sphinx && bash install.sh install 3.6.1
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py db_to_sphinx && /www/server/sphinx/bin/bin/indexer -c /www/server/sphinx/sphinx.conf --all --rotate
|
||||
# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py sphinx_cmd
|
||||
|
||||
# /Users/midoks/Desktop/mwdev/server/sphinx/bin/bin/indexer /Users/midoks/Desktop/mwdev/server/sphinx/sphinx.conf --all --rotate
|
||||
|
||||
# cd /www/server/mdserver-web && source bin/activate && python3 plugins/sphinx/index.py start
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
# echo "bash ${rootPath}/scripts/getos.sh"
|
||||
OSNAME="macos"
|
||||
if [ -f ${rootPath}/data/osname.pl ];then
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
fi
|
||||
|
||||
if [ "${OSNAME}" == "centos" ] ||
|
||||
[ "${OSNAME}" == "fedora" ] ||
|
||||
[ "${OSNAME}" == "alma" ]; then
|
||||
yum install -y postgresql-libs unixODBC
|
||||
fi
|
||||
|
||||
# http://sphinxsearch.com/files/sphinx-3.7.1-da9f8a4-linux-amd64.tar.gz
|
||||
|
||||
VERSION=$2
|
||||
|
||||
# echo $VERSION
|
||||
|
||||
if [ "$VERSION" == "3.1.1" ];then
|
||||
VERSION_NUM=${VERSION}-612d99f
|
||||
elif [ "$VERSION" == "3.2.1" ]; then
|
||||
VERSION_NUM=${VERSION}-f152e0b
|
||||
elif [ "$VERSION" == "3.3.1" ]; then
|
||||
VERSION_NUM=${VERSION}-b72d67b
|
||||
elif [ "$VERSION" == "3.4.1" ]; then
|
||||
VERSION_NUM=${VERSION}-efbcc65
|
||||
elif [ "$VERSION" == "3.5.1" ]; then
|
||||
VERSION_NUM=${VERSION}-82c60cb
|
||||
elif [ "$VERSION" == "3.6.1" ]; then
|
||||
VERSION_NUM=${VERSION}-c9dbeda
|
||||
elif [ "$VERSION" == "3.7.1" ]; then
|
||||
VERSION_NUM=${VERSION}-da9f8a4
|
||||
elif [ "$VERSION" == "3.8.1" ]; then
|
||||
VERSION_NUM=${VERSION}-d25e0bb
|
||||
fi
|
||||
|
||||
# echo $VERSION_NUM
|
||||
|
||||
Install_App()
|
||||
{
|
||||
echo '正在安装Sphinx...'
|
||||
mkdir -p $serverPath/sphinx
|
||||
|
||||
SPHINX_DIR=${serverPath}/source/sphinx
|
||||
mkdir -p $SPHINX_DIR
|
||||
|
||||
SPH_NAME=amd64
|
||||
if [ "$sysArch" == "arm64" ];then
|
||||
SPH_NAME=amd64
|
||||
elif [ "$sysArch" == "x86_64" ]; then
|
||||
SPH_NAME=amd64
|
||||
elif [ "$sysArch" == "aarch64" ]; then
|
||||
SPH_NAME=aarch64
|
||||
fi
|
||||
|
||||
if [ "$sysName" == "Darwin" ] && [ "$VERSION" == "3.7.1" ];then
|
||||
SPH_NAME=aarch64
|
||||
fi
|
||||
|
||||
SPH_SYSNAME=linux
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
SPH_SYSNAME=darwin
|
||||
elif [ "$sysName" == "aarch64" ]; then
|
||||
SPH_NAME=aarch64
|
||||
elif [ "$sysName" == "freebsd" ]; then
|
||||
SPH_NAME=freebsd
|
||||
fi
|
||||
|
||||
if [ "$SPH_SYSNAME" == "linux" ];then
|
||||
glibc_ver=`ldd --version | grep libc | awk -F ')' '{print $2}'|awk '{gsub(/^\s+|\s+$/, "");print}'`
|
||||
if [ "$VERSION" == "3.7.1" ] && [ `echo "2.29 > $glibc_ver " | bc` -eq 1 ];then
|
||||
SPH_NAME=${SPH_NAME}-glibc2.17
|
||||
fi
|
||||
if [ "$VERSION" == "3.6.1" ] && [ `echo "2.29 > $glibc_ver " | bc` -eq 1 ];then
|
||||
SPH_NAME=${SPH_NAME}-glibc2.17
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
FILE_NAME=sphinx-${VERSION_NUM}-${SPH_SYSNAME}-${SPH_NAME}
|
||||
FILE_TGZ=${FILE_NAME}.tar.gz
|
||||
|
||||
echo $FILE_TGZ
|
||||
# curl -sSLo ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ}
|
||||
if [ ! -f ${SPHINX_DIR}/${FILE_TGZ} ];then
|
||||
wget --no-check-certificate -O ${SPHINX_DIR}/${FILE_TGZ} http://sphinxsearch.com/files/${FILE_TGZ}
|
||||
fi
|
||||
|
||||
cd ${SPHINX_DIR} && tar -zxvf ${FILE_TGZ}
|
||||
|
||||
if [ "$?" == "0" ];then
|
||||
mkdir -p $SPHINX_DIR
|
||||
cp -rf ${SPHINX_DIR}/sphinx-${VERSION}/ $serverPath/sphinx/bin
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/sphinx ];then
|
||||
echo "${VERSION}" > $serverPath/sphinx/version.pl
|
||||
echo '安装Sphinx完成'
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py start
|
||||
|
||||
if [ $sysName != 'Darwin' ]; then
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/sphinx/index.py initd_install
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d ${SPHINX_DIR}/sphinx-${VERSION} ];then
|
||||
rm -rf ${SPHINX_DIR}/sphinx-${VERSION}
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
if [ -f /usr/lib/systemd/system/sphinx.service ] || [ -f /lib/systemd/system/sphinx.service ];then
|
||||
systemctl stop sphinx
|
||||
systemctl disable sphinx
|
||||
|
||||
if [ -f /usr/lib/systemd/system/sphinx.service ];then
|
||||
rm -rf /usr/lib/systemd/system/sphinx.service
|
||||
fi
|
||||
|
||||
if [ -f /lib/systemd/system/sphinx.service ];then
|
||||
rm -rf /lib/systemd/system/sphinx.service
|
||||
fi
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
if [ -f $serverPath/sphinx/initd/sphinx ];then
|
||||
$serverPath/sphinx/initd/sphinx stop
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/sphinx ];then
|
||||
echo "rm -rf $serverPath/sphinx"
|
||||
rm -rf $serverPath/sphinx
|
||||
fi
|
||||
|
||||
echo "卸载sphinx成功"
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
Reference in New Issue
Block a user