操做系統:centos7c++
redis版本:http://download.redis.io/releases/redis-3.2.9.tar.gzredis
[root@localhost softs]# tar -zxvf redis-3.2.9.tar.gz [root@localhost softs]# mv redis-3.2.9 redis
這一步是將redis解壓後重命名爲rediscentos
[root@localhost redis]# yum install -y gcc g++ gcc-c++ make
[root@localhost redis]# make install
[root@localhost redis]# ls 00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-sentinel src utils BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests [root@localhost redis]# cd utils/ [root@localhost utils]# [root@localhost utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
按照默認一直回車便可。ui
進入/etc/init.d/查看一下文件:this
[root@localhost init.d]# ls functions netconsole network README redis_6379 [root@localhost init.d]#
在這裏有一個redis_6379的文件,如今可使用這個文件來啓動或者中止rediscentos7
# 啓動redis服務
/etc/init.d/redis_6379 start
# 查看進程
netstat -apn|grep redis
# 中止redis服務
/etc/init.d/redis_6379 stopspa
# 重啓redis服務
/etc/init.d/redis_6379 restart操作系統
註釋:#bind 127.0.0.1命令行
去掉註釋並設置密碼: requirepass redisrest
設置就將redis的密碼設置成了redis
使用命令行進入redis
[root@localhost ~]# redis-cli -h 127.0.0.1 -p 6379
注意:若是設置了redis的密碼則在使用/etc/init.d/redis_6379 start|stop|restart 時不成功。此時須要修改
/etc/init.d/redis_6379
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT -h 127.0.0.1 -a redis shutdown
-a redis 表示redis的密碼是字符串"redis"