安装依赖
apt-get install tcl make
下载安装
去 redis.io 最新版本的 redis 版本进行下载.
cd /usr/local/src
wget http://download.redis.io/releases/redis-3.2.2.tar.gz
tar -zxvf redis-3.2.2.tar.gz
cd redis-3.2.2/src
make
make test
make install
设置目录
将四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf 分别拷贝到/usr/redis下,和/etc下
mkdir -p /usr/redis/
cd /usr/local/src/redis-3.2.2/src
cp redis-server /usr/redis
cp redis-benchmark /usr/redis
cp redis-cli /usr/redis
cd ../
cp redis.conf /etc
设置 service 脚本
touch /etc/init.d/redis
chmod u+x /etc/init.d/redis
vi init.d/redis
// cp content into it
#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
EXEC=/usr/redis/redis-server
REDIS_CLI=/usr/redis/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/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|force-reload}" >&2
exit 1
esac
sysv-rc-conf redis on
取消warning
修改 sysctl.conf
echo 511 > /proc/sys/net/core/somaxconn
echo vm.overcommit_memory = 1 >> /etc/sysctl.conf
/sbin/sysctl -e -p /etc/sysctl.conf
设置文件打开数目
vi /lib/systemd/system/redis-server.service
在 [serveice] 组中增加
LimitNOFILE=65536
然后,运行:
systemctl daemon-reload
systemctl restart redis-server
systemctl enable redis-server
配置 redis
vi /etc/redis.conf
daemonize yes
requirepass foobar
bind 127.0.0.1
unixsocket /tmp/redis.sock
dir /data/redis/
pidfile /var/run/redis.pid
iptables
// 根据情况开放 iptables 端口
iptables -p tcp -m tcp --dport 6379 -j ACCEPT