编译安装 redis

下载当前最新 release 版本 redis 源码包:

http://download.redis.io/releases/

编译安装命令:

官方的安装命令:

https://redis.io/download

# pwd

/usr/local/src

# tar xf redis-5.0.3.tar.gz

# cd redis-5.0.3

# make PREFIX=/apps/redis install #指定 redis 安装目录

# ll /usr/local/redis/total 0

drwxr-xr-x 2 root root 134 Dec 13 09:21 bin

# mkdir /apps/redis/{etc,logs,data,run} #创建配置文件、日志、数据等目录

# cp /usr/local/src/redis-5.0.3/redis.conf  /apps/redis/etc/

 

前台启动 redis

# /apps/redis/bin/redis-server  /apps/redis/etc/redis.conf

 

 

 

编译安装redis_第1张图片 

 

 

编辑 redis 服务启动脚本:

[root@s1 ~]# cat /usr/lib/systemd/system/redis.service

[Unit]

Description=Redis persistent key-value database

After=network.target

After=network-online.target

Wants=network-online.target

[Service]

#ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd

ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

Type=notify

User=redis

Group=redis

RuntimeDirectory=redisRuntimeDirectoryMode=0755

[Install]

WantedBy=multi-user.target

 

创建 redis 用户和数据目录:

# groupadd -g 1000 redis && useradd -u 1000 -g 1000 redis -s /sbin/nologin

# mkdir -pv /apps/redis/{etc,logs,data,run}

# chown redis.redis -R /apps/redis