Redis3.2.12单节点安装

一、环境
centos6.9
redis-3.2.12
二、安装
1.解压

tar -zxvf redis-3.2.12.tar.gz -C /opt/

2.编译



遇到错误


解决方法:安装gcc

yum install gcc

再次make遇到错误


解决方法:使用make MALLOC=libc编译

3.src下编译

make install

安装完成!

三、部署

1.创建文件夹

mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/ect

2.拷贝文件

cp -r /opt/redis-3.2.12/redis.conf /usr/local/redis/ect/
cd /opt/redis-3.2.12/src/
cp -r mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin/

3.启动redis服务

/usr/local/redis/bin/redis-server

该种方法是在前台启动redis,窗口关闭,redis也停止

4.修改配置文件
vi /usr/local/redis/ect/redis.conf

主要修改内容为:

#配置守护进程模式
daemonize yes
#修改redis密码(默认无密码)
requirepass redis123
#绑定内网ip
bind 10.0.0.22 127.0.0.1
#指定redis进程的pid文件存放位置
pidfile /var/run/redis.pid

5.配置redis开机启动文件
配置脚本文件vi /etc/init.d/redis 如下:

#
# redis Startup script for Redis Server
#!/bin/sh
#
# redis Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/ect/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
 if [ -e $PIDFILE ];then
 echo "$desc already running...."
 exit 1
 fi
 echo -n $"Starting $desc: "
 daemon $BIN/$prog $CONFIG
 RETVAL=$?
"/etc/rc.d/init.d/redis" 67L, 1384C written
[root@data-persistence ~]# cat /etc/init.d/redis
#!/bin/sh
#
# redis Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/ect/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
 if [ -e $PIDFILE ];then
 echo "$desc already running...."
 exit 1
 fi
 echo -n $"Starting $desc: "
 daemon $BIN/$prog $CONFIG
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
 return $RETVAL
}
stop() {
 echo -n $"Stop $desc: "
 killproc $prog
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
 return $RETVAL
}
restart() {
 stop
 start
}
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 restart)
 restart
 ;;
 condrestart)
 [ -e /var/lock/subsys/$prog ] && restart
 RETVAL=$?
 ;;
 status)
 status $prog
 RETVAL=$?
 ;;
 *)
 echo $"Usage: $0 {start|stop|restart|condrestart|status}"
 RETVAL=1
esac
exit $RETVAL

6.设置权限、启动/关闭测试、开机启动

chmod +x /etc/init.d/redis
service redis start
service redis stop
chkconfig --add redis

7.修改profile文件

vi /etc/profile
#在最后行添加:
export PATH="$PATH:/usr/local/redis/bin"
#使文件生效
source /etc/profile

8.配置内核参数
否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上

vi /etc/sysctl.conf
#添加参数
vm.overcommit_memory = 1 
#使配置生效
sysctl -p 

到此部署完毕!
以上大部分内容均摘抄于网络,经个人实践无误后发布。

你可能感兴趣的:(Redis3.2.12单节点安装)