Linux 安装Redis

Linux版本信息:

[root@VM-0-12-centos bin]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 

下载Redis:Redis下载地址

wget http://download.redis.io/releases/redis-6.0.8.tar.gz

安装gcc环境:

[root@VM-0-12-centos bin]# yum install gcc

Centos7默认gcc4,Redis6需要gcc9

解压到安装目录:

[root@VM-0-12-centos]# tar -zxvf redis-6.0.8.tar.gz -C /usr/local/
[root@VM-0-12-centos]# mv /usr/local/redis-6.0.8/ /usr/local/redis
[root@VM-0-12-centos]# cd /usr/local/redis

编译安装:

[root@VM-0-12-centos]# make
[root@VM-0-12-centos]# make install PREFIX=/usr/local/redis

启动Redis:

[root@VM-0-12-centos]# cd bin/
[root@VM-0-12-centos]# ls
dump.rdb  redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@VM-0-12-centos]# ./redis-server 

配置后台启动Redis,并加入开机启动:
开放远程访问,开启守护进程,关闭守护模式
修改 redis.conf 文件,把 daemonize no 改为 daemonize yes

[root@VM-0-12-centos redis-6.0.8]# vi /usr/local/redis/redis-6.0.8/redis.conf 

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 -::1

# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

添加开启启动服务(systemctl):

[root@VM-0-12-centos]# vi /etc/systemd/system/redis.service

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

# 重新加载启动项,设为开启启动,启动Redis
systemctl daemon-reload
systemctl enable redis.service
systemctl start redis.service

测试:

# 创建软连接
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

[root@VM-0-12-centos]# redis
127.0.0.1:6379> ping
PONG
posted @ 2020-09-14 03:33  宁川  阅读(225)  评论(0)    收藏  举报