一、安装
//在终端中安装Redis服务器端
sudo apt-get install redis-server
安装完成后,Redis服务器会自动启动,我们检查Redis服务器程序
//在终端中检查Redis服务器系统进程
ps -aux|grep redis
//在终端中通过启动命令检查Redis服务器状态
netstat -nlt|grep 6379
//通过启动命令检查Redis服务器状态
sudo /etc/init.d/redis-server status
二、访问Redis
安装Redis服务器,会自动地一起安装Redis命令行客户端程序。
启动redis—server
/usr/bin/redis-server
在本机输入redis-cli命令就可以启动,客户端程序访问Redis服务器。
三、Ubuntu14.04下安装redis-3.2.0以及开机自启动
设置开机自启动
- 修改redis.conf
#打开后台运行选项 daemonize yes #设置日志文件路径 logfile "/var/log/redis.log"
- 编写脚本
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo touch /etc/init.d/redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo vim /etc/init.d/redis
下面是脚本的内容
#!/bin/sh # chkconfig: 2345 10 90 # description: Start and Stop redis PATH=/usr/local/bin REDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pid CONF="/etc/redis/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 exists, process is not running." else PID=$(cat $PIDFILE) echo "Stopping..." $REDIS_CLI -p $REDISPORT 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|fore-reload}" exit 1 esac
- 添加脚本的执行权限
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo chmod +x /etc/init.d/redis
- 设置开机自动启动
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo update-rc.d redis defaults
- 使用脚本启动服务
开启redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis start 停止redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis stop 重启redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis restart
- 将机器关机,重新启动
方式一:通过命令redis-server 启动,可在命令后加上`&`号使redis以后台程序方式运行;
方式二:通过指定配置文件启动;redis-server /etc/redis/redis.conf