下载源码包
wget https://github.com/redis/redis/archive/7.2.0.tar.gz
tar -zxf 7.2.0.tar.gz
编译编码
编译编码
cd redis-7.2.0
make && make install
此时默认redis-server redis-cli等命令行安装到目录/usr/local/bin/目录中。
如果你想安装命令行到指定目录中你可以指定位置 如 make install PREFIX=/usr/local/redis
修改redis.conf
后台启动
daemonize yes
支持远程连接 注释或者指定为0.0.0.0
bind 127.0.0.1 -::1
protected-mode no
设置密码
requirepass 12345
设置开机自启动
Linix目前有2中服务管理的方法 一种是Init.d 一种是systemd。centos7+已经推荐systemd。接下来分别用这2种方法实验一下,一般我们只需要用一种方法就行啦。
方法一init.d
vi /etc/init.d/redis
#!/bin/bash
#
# chkconfig: 2345 10 90
# description: redis service manager
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"
AUTH="123456"
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
sleep 2
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
设置redis 权限
chmod 755 /etc/init.d/redis
启动redis
/etc/init.d/redis start
设置开机启动
cd /etc/init.d/
chkconfig redis on
方法二 systemd
创建redis.service服务文件
sudo vim /etc/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
User=nobody
Group=nogroup
RuntimeDirectory=redis
RuntimeDirectoryMode=2755
[Install]
WantedBy=default.target
刷新redis服务
systemctl daemon-reload
启动redis
systemctl start redis
设置开机启动文章来源:https://www.toymoban.com/news/detail-689656.html
systemctl enable redis文章来源地址https://www.toymoban.com/news/detail-689656.html
到了这里,关于redis7.2.0 centos源码编译安装并设置开机自启动的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!