標籤:
Redis安裝
從官方下載最新Redis進行安裝,官網地址:http://redis.io/download
$ wget http://download.redis.io/releases/redis-3.2.3.tar.gz$ tar xzf redis-3.2.3.tar.gz$ cd redis-3.2.3$ make$ make install
Redis啟動
RedisServer /path/to/redis.conf
Redis關閉(預設port為6379)
RedisCli -p port -a Password shutdown
查看Reids進程
ps -ef|grep redis
設定Redis開機啟動1:配置init指令碼,把代碼存為Reids,放到/etc/init.d/
############################ chkconfig: 2345 90 10# description: Redis is a persistent key-value databasePATH=/usr/local/binREDISPORT=6379EXEC=/usr/local/bin/redis-serverREDIS_CLI=/usr/local/bin/redis-cli#Redis密碼PASSWORD=yourPasswordPIDFILE=/var/run/redis.pidCONF="/usr/local/reids/conf/redis.conf" case "$1" in 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 ..." $REDIS_CLI -p $REDISPORT -a $PASSWORD SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1esac##############################
注意事項:
1) 最上面的注釋的意思是,redis服務必須在運行級2,3,4,5下被啟動或關閉,啟動的優先順序是90,關閉的優先順序是10。
2) 如果執行命令出現$‘/r‘:command not found,這個問題是在Windows下換行和linux下換行不同,可以通過Nodepad++進行轉換。
2:設定指令碼許可權
chmod +x /etc/init.d/redis
3:設定開機啟動
sudo chkconfig redis on
4:使用方法
service redis start #或者 /etc/init.d/redis startservice redis stop #或者 /etc/init.d/redis stop
CenterOS中安裝Redis及開機啟動設定