Centos安装Redis

214 阅读1分钟

下载源码

下载地址:redis.io/download,下载最新稳定版

image-20201124203017327

$ wget https://download.redis.io/releases/redis-6.0.9.tar.gz
$ tar xzf redis-6.0.9.tar.gz
$ cd redis-6.0.9

编译安装

$ make
$ make install

修改配置文件redis.conf

修改远程访问、后台启动和密码

  • 隐藏bind 127.0.0.1或修改为bind 0.0.0.0
  • 修改daemonize noyes
  • 修改requirepass <你的密码>

启动

$ ./src/redis-server ./redis.conf

使用systemd管理服务

/etc/systemd/system目录下新建redis.service文件,写入以下内容

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

[Service]
Type=forking
ExecStart=${安装目录}/src/redis-server ${安装目录}/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

刷新systemctl查看Redis状态

$ sudo systemctl daemon-reload
$ sudo systemctl status redis

image-20201124204509672

设置开机启动

$ sudo systemctl enable redis.service