#!/usr/bin/env python#-*- encoding:utf8 -*-#--------------------------------------------------- ------------------------------------# file: Gen_Redis Config.py# # usage: python_code_style.txt [-h] [copy pep 8]## description: copy python style guide and coding standard .# The default copy example is the current text .# dont.t find text on other directories .## OPTIONS: see fuction ' usage ' below # BUGS: ---# author: dr.-vision. simple (SP) # VERSION: 1.0# CREATED: 08.18.2014 - 10:15:30# REVISION: 08.20.2014# project: pde # copyritht: copyright (c) 2002-2014 python, all rights reserved#---------------------------------- -----------------------------------------------------# import python module#------------------- --------------------------------------------------------------------# define python import modules .#- --------------------------------------------------------------------------------------import os# python class comments#======== class ================= ===================================================# NAME: # DESCRIPTION: display usage information for this script.# parameter 1: ---#================================================================================== =====def gen_master_config (port): data = "" "################ ################ start ##################################### include common Configinclude /usr/local/redis/etc/redis-common.conf# listen portport % (port) s# max memorymaxmemory 16gpidfile /var/run/redis-% (port) s.pidlogfile /data/redis/logs/redis-% (port) s.log# the elimination policy used when memory is exhausted: # volatile-lru -> remove the key with an expire set using an lru algorithm# allkeys-lru -> remove any key accordingly to the lru algorithm# volatile-random -> remove a random key with an expire set# allkeys-random -> remove a random key, any key# volatile-ttl -> remove the key with the nearest expire time (Minor ttl) # noeviction -> don ' t expire at all, just return an error on write Operationsmaxmemory-policy allkeys-lru#aof Storing Files Appendfilename "appendonly-% (port) s.aof" #rdb文件, only for dynamically adding slave process dbfilename dump-% (port) S.rdb#cluster profiles ( Start auto-Generate) cluster-config-file nodes-% (port) s.conf# The Redis instance deployed on the same machine, rubbing the auto-aof-rewrite off, Prevents all Redis processes from being rewrite and consuming large amounts of memory in an instant fork auto-aof-rewrite-percentage 80-100################################ end ##################################### "" " values = {" Port ":p ort } #print (data % values) with open (' redis-%s.conf ')% (port), "W") as f: #f. Write (data % Values). Encode (' UTF8 ')) f.write (data % values) f.closedef gen_slave_config (PORT,MASTER_ADDR): data = "" "################################ start ##################################### include common configinclude /usr/local/redis/etc/redis-common.conf# listen portport % (port) s# max memorymaxmemory 16gpidfile /var/run/redis-% (port) s.pidlogfile /data/redis/logs/redis-% (port) s.log#slaveof % ( MASTER_ADDR) s# The elimination strategy used when memory is exhausted: # volatile-lru -> remove the key with an expire set using an lru algorithm# allkeys-lru -> remove any key accordingly to the LRU algorithm# volatile-random -> remove a random key with an expire set# allkeys-random - > remove a random key, any key# volatile-ttl -> remove the key with the nearest expire time (Minor ttl) # Noeviction -> don ' t expire at all, just return an error On write operationsmaxmemory-poliCy allkeys-lru#aof Store File appendfilename "appendonly-% (port) s.aof" #rdb文件, only for dynamically adding slave procedures dbfilename dump-% (port) S.rdb#cluster configuration file (Start auto-generate) cluster-config-file nodes-% (port) s.conf# deployed on the same machine Redis instance, Rub the auto-aof-rewrite, prevent the instant fork all Redis process do rewrite, occupy a lot of memory auto-aof-rewrite-percentage 80-100################### ############# end ##################################### "" " values = {"Port":p ort, "Master_addr":master_addr} #print (data % values) with open ((' redis-%s.conf ')% (port), "W") as f: #f. Write ((data % values). Encode (' UTF8 ') f.write (data % values) f.closedef gen_service_config (port): data = "" "#!/bin/bash#chkconfig: 2345 80 90## simple redis init.d script conceived to work on linux systems# as it does use Of the /proc filesystem. redisport=% (port) sredis_path= "/usr/local/redis" exec= "/usr/local/redis/bin/redis-server" CLIEXEC= "/usr/local/ Redis/bin/redis-cli "pidfile="/var/run/redis-% (port) s.pid "conf=" ${redis_path}/etc/redis-% (port) s.conf "#PASSWD =" Superredis "case " $ " in start" if [ -f $PIDFILE ] then echo "$PIDFILE Exists, process is already running or crashed " else echo "Starting redis server ..." $EXEC $CONF & echo -e "$!" >${PIDFILE} fi ;; stop) if [ ! -f $ pidfile ] then echo "$PIDFILE does not exist, Process is not running " else pid=$ (cat $PIDFILE) echo "stopping  ..." # $CLIEXEC -p $REDISPORT -a ${ passwd} shutdown $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo " WAITING FOR REDIS TO SHUTDOWN&NBSP: " sleep 1 done echo "redis stopped" fi ;; status) if [[ -f ${PIDFILE} ]];then echo "$PIDFILE exists, redis is already running " else echo "$PIDFILE is not exists" fi ;; *) echo "please use Start or stop as first argument " ;; Esac "" " values = {" Port ":p ort} #print (data % values) with open ((' redis-%s ')% (port), "W") as f: #f. Write ((data % values). Encode (' UTF8 ') f.write (data % values) f.close# python main comments#------------------------------------------------------------------------------------- --# define python main .#----------------------------------------------------- ----------------------------------if __name__ == " __main__ ": master_addr = " 192.1678.10.130 " os.chdir ('/ Usr/local/src/ssoredis ') os.chdir (' master/etc ') for i In range (6379,6387): gen_master_config (str (i)) for i in range (6379,6387): os.chdir ( '/usr/local/src/ssoredis ') os.chdir (' Master/service ') gen_service_config (str (i)) os.chdir ('/usr/local/src/ssoredis ') os.chdir (' slave/ Service ') gen_service_config (str (i)) for i in range (6379,6387): os.chdir ('/usr/local/src /ssoredis ') &nBsp; os.chdir (' slave/etc ') gen_slave_config (Port=str (i), master_addr=master_addr)
This article is from the "focus on background design" blog, make sure to keep this source http://xleft.blog.51cto.com/955567/1895598
Python generates a Redis template script