#add redis user
groupadd redis
useradd redis -g redis -s /usr/sbin/nologin
#workspace
mkdir -p /etc/redis /data/redis /var/log/redis
#install
wget http://download.redis.io/releases/redis-$REDISVERSION.tar.gz -O $WORKSPACE/redis-$REDISVERSION.tar.gz
tar xf $WORKSPACE/redis-$REDISVERSION.tar.gz -C $WORKSPACE
cd $WORKSPACE/redis-$REDISVERSION && make && make test && make install
cp $WORKSPACE/redis-$REDISVERSION/*.conf /etc/redis
#configuration
sed -i ‘s/127.0.0.1/0.0.0.0/g‘ /etc/redis/redis.conf
sed -i ‘/^logfile/c logfile "/var/log/redis/redis.log"‘ /etc/redis/redis.conf
sed -i ‘/^dir .\//c dir \/data\/redis\/‘ /etc/redis/redis.conf
cat << EOF > /lib/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
[Install]
WantedBy=multi-user.target
EOF
#startup
chown -R redis.redis /etc/redis /data/redis /var/log/redis
systemctl daemon-reload
systemctl enable redis
systemctl start redis
原文地址:http://blog.51cto.com/jinliang/2107176