redis 主从配置识别

pull/504/head
Mr Chen 2 years ago
parent 1996cb03ce
commit 15e6ca97e1
  1. 1
      plugins/redis/index.html
  2. 78
      plugins/redis/index.py
  3. 7
      plugins/redis/init.d/redis.tpl
  4. 90
      plugins/redis/tpl/redis_slave.conf
  5. 1
      scripts/install/macos.sh

@ -4,6 +4,7 @@
<div class="bt-w-menu"> <div class="bt-w-menu">
<p class="bgw" onclick="pluginService('redis');">服务</p> <p class="bgw" onclick="pluginService('redis');">服务</p>
<p onclick="pluginInitD('redis');">自启动</p> <p onclick="pluginInitD('redis');">自启动</p>
<p onclick="pluginConfigTpl('redis',$('.plugin_version').attr('version'));">配置修改[DEV]</p>
<p onclick="pluginConfig('redis');">配置修改</p> <p onclick="pluginConfig('redis');">配置修改</p>
<p onclick="getRedisConfig($('.plugin_version').attr('version'));">性能调整</p> <p onclick="getRedisConfig($('.plugin_version').attr('version'));">性能调整</p>
<p onclick="redisStatus($('.plugin_version').attr('version'));">负载状态</p> <p onclick="redisStatus($('.plugin_version').attr('version'));">负载状态</p>

@ -71,15 +71,60 @@ def getArgs():
tmp[t[0]] = t[1] tmp[t[0]] = t[1]
return tmp 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 status():
data = mw.execShell(
"ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
if data[0] == '': 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 getPidFile():
file = getConf()
content = mw.readFile(file)
rep = 'pidfile\s*(.*)'
tmp = re.search(rep, content)
return tmp.groups()[0].strip()
def status():
pid_file = getPidFile()
if not os.path.exists(pid_file):
return 'stop' return 'stop'
# data = mw.execShell(
# "ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
# if data[0] == '':
# return 'stop'
return 'start' return 'start'
def contentReplace(content):
service_path = mw.getServerDir()
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
content = content.replace('{$SERVER_PATH}', service_path)
content = content.replace('{$SERVER_APP}', service_path + '/redis')
content = content.replace('{$REDIS_PASS}', mw.getRandomString(10))
return content
def initDreplace(): def initDreplace():
@ -298,13 +343,15 @@ def getRedisConfInfo():
conf = getServerDir() + '/redis.conf' conf = getServerDir() + '/redis.conf'
gets = [ gets = [
{'name': 'bind', 'type': 2, 'ps': '绑定IP(修改绑定IP可能会存在安全隐患)'}, {'name': 'bind', 'type': 2, 'ps': '绑定IP(修改绑定IP可能会存在安全隐患)','must_show':1},
{'name': 'port', 'type': 2, 'ps': '绑定端口'}, {'name': 'port', 'type': 2, 'ps': '绑定端口','must_show':1},
{'name': 'timeout', 'type': 2, 'ps': '空闲链接超时时间,0表示不断开'}, {'name': 'timeout', 'type': 2, 'ps': '空闲链接超时时间,0表示不断开','must_show':1},
{'name': 'maxclients', 'type': 2, 'ps': '最大输入时间'}, {'name': 'maxclients', 'type': 2, 'ps': '最大输入时间','must_show':1},
{'name': 'databases', 'type': 2, 'ps': '数据库数量'}, {'name': 'databases', 'type': 2, 'ps': '数据库数量','must_show':1},
{'name': 'requirepass', 'type': 2, 'ps': 'redis密码,留空代表没有设置密码'}, {'name': 'requirepass', 'type': 2, 'ps': 'redis密码,留空代表没有设置密码','must_show':1},
{'name': 'maxmemory', 'type': 2, 'ps': 'MB,最大使用内存,0表示不限制'} {'name': 'maxmemory', 'type': 2, 'ps': 'MB,最大使用内存,0表示不限制','must_show':1},
{'name': 'slaveof', 'type': 2, 'ps': '同步主库地址','must_show':0},
{'name': 'masterauth', 'type': 2, 'ps': '同步主库密码', 'must_show':0}
] ]
content = mw.readFile(conf) content = mw.readFile(conf)
@ -313,6 +360,9 @@ def getRedisConfInfo():
rep = "^(" + g['name'] + ')\s*([.0-9A-Za-z_& ~]+)' rep = "^(" + g['name'] + ')\s*([.0-9A-Za-z_& ~]+)'
tmp = re.search(rep, content, re.M) tmp = re.search(rep, content, re.M)
if not tmp: if not tmp:
if g['must_show'] == 0:
continue
g['value'] = '' g['value'] = ''
result.append(g) result.append(g)
continue continue
@ -331,7 +381,7 @@ def getRedisConf():
def submitRedisConf(): def submitRedisConf():
gets = ['bind', 'port', 'timeout', 'maxclients', gets = ['bind', 'port', 'timeout', 'maxclients',
'databases', 'requirepass', 'maxmemory'] 'databases', 'requirepass', 'maxmemory','slaveof','masterauth']
args = getArgs() args = getArgs()
conf = getServerDir() + '/redis.conf' conf = getServerDir() + '/redis.conf'
content = mw.readFile(conf) content = mw.readFile(conf)
@ -383,5 +433,9 @@ if __name__ == "__main__":
print(getRedisConf()) print(getRedisConf())
elif func == 'submit_redis_conf': elif func == 'submit_redis_conf':
print(submitRedisConf()) print(submitRedisConf())
elif func == 'config_tpl':
print(configTpl())
elif func == 'read_config_tpl':
print(readConfigTpl())
else: else:
print('error') print('error')

@ -25,6 +25,10 @@ EXEC={$SERVER_PATH}/redis/bin/redis-server
CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS" CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS"
PIDFILE={$SERVER_PATH}/redis/redis_6379.pid PIDFILE={$SERVER_PATH}/redis/redis_6379.pid
echo $REDISPASS
echo $REDISPORT
echo $CLIEXEC
mkdir -p {$SERVER_PATH}/redis/data mkdir -p {$SERVER_PATH}/redis/data
redis_start(){ redis_start(){
@ -42,13 +46,14 @@ redis_stop(){
else else
PID=$(cat $PIDFILE) PID=$(cat $PIDFILE)
echo "Stopping ..." echo "Stopping ..."
$CLIEXEC shutdown $CLIEXEC shutdown save 2>/dev/null
while [ -x /proc/${PID} ] while [ -x /proc/${PID} ]
do do
echo "Waiting for Redis to shutdown ..." echo "Waiting for Redis to shutdown ..."
sleep 1 sleep 1
done done
echo "Redis stopped" echo "Redis stopped"
kill -9 $PID
rm -rf $PIDFILE rm -rf $PIDFILE
fi fi
} }

@ -0,0 +1,90 @@
daemonize yes
pidfile {$SERVER_PATH}/redis/redis_6379.pid
loglevel notice
logfile {$SERVER_PATH}/redis/data/redis.log
databases 16
timeout 0
tcp-keepalive 0
bind 127.0.0.1
port 6379
requirepass {$REDIS_PASS}
################################ SNAPSHOTTING #################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir {$SERVER_PATH}/redis/data/
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
# 填写主库信息
#slaveof 127.0.0.1 6379
#masterauth master_pwd
################################## SECURITY ###################################
################################### LIMITS ####################################
maxclients 10000
#maxmemory-samples 3
maxmemory 218mb
maxmemory-policy volatile-ttl
############################## APPEND ONLY MODE ###############################
#appendonly no
# appendfsync always
#appendfsync everysec
# appendfsync no
#no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

@ -22,6 +22,7 @@ if [ "$?" != "0" ];then
brew install mysql brew install mysql
fi fi
brew install coreutils
brew install md5sum libevent pidof bison brew install md5sum libevent pidof bison
brew install libzip bzip2 gcc openssl re2c cmake brew install libzip bzip2 gcc openssl re2c cmake

Loading…
Cancel
Save