root># cat /etc/init.d/redis_6379 #!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.# chkconfig: 2345 90 10source /etc/init.d/functionsREDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/usr/local/redis/etc/redis_${REDISPORT}.conf"AUTH="Allwelltokok"BIND_IP='172.18.8.19' start(){ if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi } stop(){ if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -h $BIND_IP -a $AUTH -p $REDISPORT SHUTDOWN sleep 1 while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi} restart(){ stop start }status(){ ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1 if [ $? -eq 0 ];then echo "redis server is running" else echo "redis server is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2 exit 1 esac
五、启动服务
root># /etc/init.d/redis_6379 start
查看日志
root># tail -100f /var/log/redis_6379.log5563:S 29 Jun 22:14:23.236 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.12 (00000000/0) 64 bit .-`` .-```. ```// _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 5563 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 5563:S 29 Jun 22:14:23.237 # Server started, Redis version 3.2.125563:S 29 Jun 22:14:23.237 * The server is now ready to accept connections on port 63795563:S 29 Jun 22:14:23.237 * Connecting to MASTER 172.18.8.19:63795563:S 29 Jun 22:14:23.237 * MASTER <-> SLAVE sync started5563:S 29 Jun 22:14:23.237 * Non blocking connect for SYNC fired the event.5563:S 29 Jun 22:14:23.238 * Master replied to PING, replication can continue...5563:S 29 Jun 22:14:23.238 * Partial resynchronization not possible (no cached master)5563:S 29 Jun 22:14:23.239 * Full resync from master: c9f303069f87253011bf39369366732a2e88b389:15563:S 29 Jun 22:14:23.304 * MASTER <-> SLAVE sync: receiving 77 bytes from master5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Flushing old data5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Loading DB in memory5563:S 29 Jun 22:14:23.305 * MASTER <-> SLAVE sync: Finished with success5563:S 29 Jun 22:14:23.305 * Background append only file rewriting started by pid 55675563:S 29 Jun 22:14:23.329 * AOF rewrite child asks to stop sending diffs.5567:C 29 Jun 22:14:23.329 * Parent agreed to stop sending diffs. Finalizing AOF...5567:C 29 Jun 22:14:23.329 * Concatenating 0.00 MB of AOF diff received from parent.5567:C 29 Jun 22:14:23.329 * SYNC append only file rewrite performed5567:C 29 Jun 22:14:23.330 * AOF rewrite: 0 MB of memory used by copy-on-write5563:S 29 Jun 22:14:23.337 * Background AOF rewrite terminated with success5563:S 29 Jun 22:14:23.337 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)5563:S 29 Jun 22:14:23.337 * Background AOF rewrite finished successfully