1.下载redis安装包(我这里用的是redis-3.2.1.tar.gz)
2.将redis安装包放到/tmp 目录下
3.解压redis安装包 tar xf redis-3.2.1.tar.gz
4.切换至解压目录 cd redis-3.2.1
5.编译和安装 (依次执行以下命令)
mkdir –p /opt/redis
make PREFIX=/opt/redis USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes install
make MALLOC=libc
再次执行
make PREFIX=/opt/redis USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes install
6.创建配置文件和文件夹
mkdir -p /opt/redis/etc
mkdir -p /opt/redis/run
mkdir -p /opt/redis/data/6379
mkdir -p /opt/redis/log
cp redis的解压路径/redis.conf /opt/redis/etc/redis.conf
cp /opt/redis/etc/redis.conf /opt/redis/etc/redis_6379.conf
7.修改配置文件
vim /opt/redis/etc/redis_6379.conf
-------------------修改内容--------------------
daemonize yes
pidfile /opt/redis/run/redis_6379.pid
dir /opt/redis/data/6379
logfile /opt/redis/log/redis_6379.log
vim之后 设置 密码 /requirepass 设置 redis6379 :wq保存退出
8.创建服务脚本
cp 【已撰写好】/redis /etc/init.d/redis
(redis要覆盖)设置密码修改
vim /etc/init.d/redis
以下是服务脚本(redis)
1 #!/bin/sh 2 PATH="/opt/redis/bin:PATH" 3 EXEC="/opt/redis/bin/redis-server" 4 CLIEXEC="/opt/redis/bin/redis-cli" 5 PIDFILE="/opt/redis/run/redis_6379.pid" 6 CONF="/opt/redis/etc/redis_6379.conf" 7 REDISPORT="6379" 8 9 case "$1" in 10 start) 11 if [ -f $PIDFILE ] 12 then 13 echo "$PIDFILE exists,process is already running or crashed" 14 else 15 echo "Starting Redis server..." 16 $EXEC $CONF 17 fi 18 ;; 19 stop) 20 if [ ! -f $PIDFILE ] 21 then 22 echo "$PIDFILE does not exist,process is not running." 23 else 24 PID=$(/bin/cat $PIDFILE) 25 echo "Stopping..." 26 $CLIEXEC -p $REDISPORT shutdown 27 while [ -x /proc/${PID} ] 28 do 29 echo "Waiting for Redis to shutdown..." 30 /bin/sleep 1 31 done 32 echo "Redis stopped." 33 fi 34 ;; 35 *) 36 echo "Usage:$0 {start|stop}" >&2 37 exit 1 38 ;; 39 esac
chmod +x /etc/init.d/redis
9.修改sysctl.conf
vim /etc/sysctl.conf
-------------------修改内容 最后添加--------------------
vm.overcommit_memory = 1
10.生效内核参数 sysctl –p
启动服务 /etc/init.d/redis start
11.测试服务是否启动
ps aux | grep redis