1.下载redis安装包
sudo wget http://download.redis.io/releases/redis-3.2.6.tar.gz
2.解压
tar -zxvf redis-3.2.6.tar.gz
3.会在当前目录下生成文件夹redis-3.2.6,我把它移动到了/usr/local/redis目录下:
4.如果没有安装gcc,需要先安装:下面编译make时候需要用到
进入到redis-3.2.6目录下,依次执行下面两条命令:
sudo make
sudo make install
5.
现在进入先前解压后得到的文件夹(我的在/usr/local/redis),复制配置文件redis.conf到/etc/redis/下,并用vi命令编辑该文件,将“daemonize no”修改为“daemonize yes”,即设置成作为后台进程运行,修改完成后保存退出。
进入到/usr/local/bin目录下,执行命令:(默认端口6379)
redis-server /etc/redis/redis.conf
redis-cli -p 6379
然后执行命令ping,若输出为pong,则证明服务成功启动。
执行quit命令退出,现在可以通过下面的命令查看到该进程:
2.设置为开机启动
编写脚本,在目录/etc/init.d/目录下面
vim /etc/init.d/redis
1 #!/bin/sh 2 # chkconfig: 2345 10 90 3 # description: Start and Stop redis 4 5 PATH=/usr/local/bin 6 REDISPORT=6379 7 EXEC=/usr/local/bin/redis-server 8 REDIS_CLI=/usr/local/bin/redis-cli 9 PIDFILE=/var/run/redis.pid 10 CONF="/etc/redis/redis.conf" 11 12 case "$1" in 13 start) 14 if [ -f $PIDFILE ] 15 then 16 echo "$PIDFILE exists, process is already running or crashed." 17 else 18 echo "Starting Redis server..." 19 $EXEC $CONF 20 fi 21 if [ "$?"="0" ] 22 then 23 echo "Redis is running..." 24 fi 25 ;; 26 stop) 27 if [ ! -f $PIDFILE ] 28 then 29 echo "$PIDFILE exists, process is not running." 30 else 31 PID=$(cat $PIDFILE) 32 echo "Stopping..." 33 $REDIS_CLI -p $REDISPORT SHUTDOWN 34 while [ -x $PIDFILE ] 35 do 36 echo "Waiting for Redis to shutdown..." 37 sleep 1 38 done 39 echo "Redis stopped" 40 fi 41 ;; 42 restart|force-reload) 43 ${0} stop 44 ${0} start 45 ;; 46 *) 47 echo "Usage: /etc/init.d/redis {start|stop|restart|fore-reload}" 48 exit 1 49 esac
添加脚本的执行权限
sudo chmod 777 /etc/init.d/redis
设置开机自动启动
sudo update-rc.d redis defaults
报错:
insserv: warning: script 'K01redis' missing LSB tags and overrides
insserv: warning: script 'redis' missing LSB tags and overrides
解决办法:
1).insserv: warning: script 'K01redis' missing LSB tags and overrides
安装一个中文语言,系统就知道zh_CN.UTF-8
了,这个时候用perl就不会报错了
sudo apt-get install language-pack-zh-hans
2)insserv: warning: script 'redis' missing LSB tags and overrides
修改目录/etc/init.d/
下面的redis
文件,在文件头部#!/bin/sh
下面添加如下内容:
### BEGIN INIT INFO
# Provides: OSSEC HIDS
# Required-Start: $network $remote_fs $syslog $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OSSEC HIDS
### END INIT INFO
设置后似乎不起作用:记几个命令: 手动启动命令:
redis-server /etc/redis/redis.conf
密码进入:
redis-cli -h 192.168.111.128 -p 6379 -a 123456