Linux下编译安装Redis以及主从复制配置(二)

2015-07-16 12:08:51 · 作者: · 浏览: 5
bash


#


# redis - this script starts and stops the redis-server daemon


#


# chkconfig:? - 80 12


# description: Redis is a persistent key-value database


# processname: redis-server


# config:? /usr/local/redis/etc/redis.conf


# pidfile:? /usr/local/redis/var/redis.pid


?


source /etc/init.d/functions


?


BIN="/usr/local/redis/bin"


CONFIG="/usr/local/redis/etc/redis.conf"


PIDFILE="/var/run/redis.pid"


?


?


### Read configuration


[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"


?


RETVAL=0


prog="redis-server"


desc="Redis Server"


?


start() {


?


? ? if [ -e $PIDFILE ];then


? ? ? echo "$desc already running...."


? ? ? exit 1


? ? fi


?


? ? echo -n $"Starting $desc: "


?


? ? #使用中偶尔发现服务器启动后居然不转入后台,所以在最后加了一个“&”


? ? daemon $BIN/$prog $CONFIG &


?


? ? RETVAL=$?


? ? echo


? ? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog


? ? return $RETVAL


}


?


stop() {


? ? echo -n $"Stop $desc: "


? ? killproc $prog


? ? RETVAL=$?


? ? echo


? ? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE


? ? return $RETVAL


}


?


restart() {


? stop


? start


}


?


case "$1" in


start)


? ? start


? ? ;;


stop)


? ? stop


? ? ;;


restart)


? ? restart


? ? ;;


condrestart)


? ? [ -e /var/lock/subsys/$prog ] && restart


? ? RETVAL=$?


? ? ;;


status)


? ? status $prog


? ? RETVAL=$?


? ? ;;


? *)


? ? echo $"Usage: $0 {start|stop|restart|condrestart|status}"


? ? RETVAL=1


esac


?


exit $RETVAL



②、注册服务与启动


#给执行权限
chmod +x /etc/init.d/redis


#开机启动
chkconfig redis on


#启动服务
service redis start


#下面是启动记录
[root@localhost ~]# service redis start
Starting Redis Server:
[root@localhost ~]#? ? ? ? ? ? ? ? _._? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? _.-``__ ''-._? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? _.-``? ? `.? `_.? ''-._? ? ? ? ? Redis 3.0.0 (00000000/0) 64 bit
? .-`` .-```.? ```\/? ? _.,_ ''-._? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?(? ? '? ? ? ,? ? ? .-`? | `,? ? )? ? Running in stand alone mode
?|`-._`-...-` __...-.``-._|'` _.-'|? ? Port: 6379
?|? ? `-._? `._? ? /? ? _.-'? ? |? ? PID: 28584
? `-._? ? `-._? `-./? _.-'? ? _.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?|`-._`-._? ? `-.__.-'? ? _.-'_.-'|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?|? ? `-._`-._? ? ? ? _.-'_.-'? ? |? ? ? ? ? http://redis.io? ? ? ?
? `-._? ? `-._`-.__.-'_.-'? ? _.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?|`-._`-._? ? `-.__.-'? ? _.-'_.-'|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
?|? ? `-._`-._? ? ? ? _.-'_.-'? ? |? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? `-._? ? `-._`-.__.-'_.-'? ? _.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? `-._? ? `-.__.-'? ? _.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? `-._? ? ? ? _.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? `-.__.-'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?


[28584] 16 Apr 23:48:55.614 # Server started, Redis version 3.0.0
[28584] 16 Apr 23:48:55.614 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[28584] 16 Apr 23:48:55.614 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[28584] 16 Apr 23:48:55.614 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[28584] 16 Apr 23:48:55.615 * DB loaded from disk: 0.000 seconds
[28584] 16 Apr 23:48:55.615 * The server is now ready to accept connections on port 6379



#给执行权限


chmod +x /etc/init.d/redis


#开机启动


chkconfig redis on


#启动服务


service redis start



#下面是启动记录


[root@localhost ~]# serv