一、方式一
1、安装Redis
1)更新系统
root@debian:~# apt update -y
2)安装Redis
root@debian:~# apt -y install redis-server
注意:Redis安装完成后,默认已启动,默认开机启动。
3)查看Redis状态
root@debian:~# systemctl status redis
2、验证Redis
1)登录Redis
root@debian:~# redis-cli
127.0.0.1:6379> keys *
(empty array)
3、配置Redis
1)配置密码
root@debian:~# vim /etc/redis/redis.conf
2)开启远程链接
root@debian:~# vim /etc/redis/redis.conf
3)重启服务
root@debian:~# systemctl restart redis
root@debian:~# systemctl status redis
4)远程连接验证
# 使用Redis Desktop Manager进行连接测试
Redis Desktop Manager下载地址:https://github.com/uglide/RedisDesktopManager/releases/download/0.9.3/redis-desktop-manager-0.9.3.817.exe
5)服务管理
1、启动服务
root@debian:~# systemctl start redis
2、停止服务
root@debian:~# systemctl stop redis
3、重启服务
root@debian:~# systemctl restart redis
4、开机启动
root@debian:~# systemctl enable redis-server
5、禁止开机启动
root@debian:~# systemctl disable redis-server
二、方式二
1、安装Redis
1)安装依赖包
root@debian:~# apt -y install wget make gcc pkg-config
2)下载Redis安装包
root@debian:~# wget http://download.redis.io/releases/redis-6.2.16.tar.gz
3)解压软件包
root@debian:~# tar xf redis-6.2.16.tar.gz
4)编译
root@debian:~# cd redis-6.2.16
root@debian:~/redis-6.2.16# make install PREFIX=/usr/local/redis
2、配置Redis
1)配置Redis
root@debian:~/redis-6.2.16# cp redis.conf /usr/local/redis/
2)配置软连接
root@debian:~/redis-6.2.16# ln -sf /usr/local/redis/bin/redis-* /usr/bin/
3)配置访问密码
root@debian:~/redis-6.2.16# Passwd=$(openssl rand -base64 12)
root@debian:~/redis-6.2.16# sed -i "s/# requirepass foobared/requirepass ${Passwd}/" /usr/local/redis/redis.conf
4)开启远程连接
root@debian:~/redis-6.2.16# sed -i "s/127.0.0.1/0.0.0.0/g" /usr/local/redis/redis.conf
5)开启后台运行
root@debian:~/redis-6.2.16# sed -i "/daemonize/s/no/yes/" /usr/local/redis/redis.conf
6)配置系统服务
root@debian:~/redis-6.2.16# vim /lib/systemd/system/redis.service
# 基础信息 [Unit] # 描述 Description=Redis Server # 在哪个服务之后启动 After=syslog.target network.target remote-fs.target nss-lookup.target # 服务信息 [Service] Type=forking PIDFile=/var/run/redis_6379.pid # 启动命令 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true # 安装相关信息 [Install] WantedBy=multi-user.target
7)启动Redis
root@debian:~/redis-6.2.16# systemctl daemon-reload
root@debian:~/redis-6.2.16# systemctl start redis
root@debian:~/redis-6.2.16# systemctl status redis
8)远程连接验证
# 使用Redis Desktop Manager进行连接测试
Redis Desktop Manager下载地址:https://github.com/uglide/RedisDesktopManager/releases/download/0.9.3/redis-desktop-manager-0.9.3.817.exe
# 获取Redis密码
root@debian:~/redis-6.2.16# grep "^requirepass" /usr/local/redis/redis.conf
requirepass RGq+3q95iFjkA3pI
9)服务管理
1、启动服务
root@debian:~/redis-6.2.16# systemctl start redis
2、停止服务
root@debian:~/redis-6.2.16# systemctl stop redis
3、重启服务
root@debian:~/redis-6.2.16# systemctl restart redis
4、开机启动
root@debian:~/redis-6.2.16# systemctl enable redis
5、禁止开机启动
root@debian:~/redis-6.2.16# systemctl disable redis
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
评论