1、debian安装
查看是否安装了redis
apt list --installed |grep redis
# 或者
dpkg -l |grep redis查看系统自带包的版本
apt-cache madison redis
# 或者
apt list redis
apt-cache show redis
apt-cache policy redis安装redis(配置官方源仓库)
sudo apt-get update
sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis卸载redis
apt-get purge redisservice查看systemctl status redis.service
cat /lib/systemd/system/redis-server.service
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)
[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no
PIDFile=/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755
UMask=007
PrivateTmp=true
LimitNOFILE=65535
PrivateDevices=true
ProtectHome=true
ProtectSystem=strict
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redis
CapabilityBoundingSet=
LockPersonality=true
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateUsers=true
ProtectClock=true
ProtectControlGroups=true
ProtectHostname=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectProc=invisible
RemoveIPC=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~ @privileged @resources
# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you remove this line.
ReadWriteDirectories=-/etc/redis
# This restricts this service from executing binaries other than redis-server
# itself. This is really effective at e.g. making it impossible to an
# attacker to spawn a shell on the system, but might be more restrictive
# than desired. If you need to, you can permit the execution of extra
# binaries by adding an extra ExecPaths= directive with the command
# systemctl edit redis-server.service
NoExecPaths=/
ExecPaths=/usr/bin/redis-server /usr/lib /lib
[Install]
WantedBy=multi-user.target
Alias=redis.service
2、redhat安装
查看是否安装了redis
u查看系统自带包的版本
yum list available redis安装redis(配置官方源仓库)
vim /etc/yum.repos.d/redis.repo
[Redis]
name=Redis
baseurl=http://packages.redis.io/rpm/rockylinux8
enabled=1
gpgcheck=1
curl -fsSL https://packages.redis.io/gpg > /tmp/redis.key
sudo rpm --import /tmp/redis.key
sudo yum install redis卸载redis
yum remove redisservice查看systemctl status redis.service
cat /usr/lib/systemd/system/redis.service
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation
[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755
UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/run/redis
NoNewPrivileges=true
CapabilityBoundingSet=CAP_SYS_RESOURCE
ProtectSystem=true
ReadWriteDirectories=-/etc/redis
[Install]
WantedBy=multi-user.target
Alias=redis.service
3、安装包安装
官网下载最新压缩包并解压
wget https://download.redis.io/releases/redis-7.2.4.tar.gz
apt install build-essential
tar -xvf redis-7.2.4.tar.gz -C /usr/local
cd /usr/local/redis-7.2.4
#解压目录下再次执行 make 命令编译
make install // 检查
#Redis 安装目录: /usr/local/bin
#查看默认安装目录:
#redis-benchmark : 性能测试工具,可以在自己电脑运行,看看电脑性能如何
#redis-check-aof: 修复有问题的 AOF 文件, rdb 和 aof
#redis-chec-dump: 修复有问题的 dump.rdb 文件
#redis-sentinel: Redis集群使用
#redis-server : Redis 服务器启动命令
#redis-cli: 客户端,操作入口
修改配置文件, 将 daemonize no 改成 yes, 让服务在后台启动
将启动固定为启动命令。此方法最为常用,便于运维。
cat /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=notify
PIDFile=/run/redis_6379.pid
ExecStart=/usr/local/redis-7.2.4/src/redis-server /usr/local/redis-7.2.4/redis.conf
ExecReload=/bin/kill -HUP $MAINPID # systemctl reload redis.service
ExecStop=/bin/kill -s TERM $MAINPID # systemctl stop redis.service
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 配置开机自启动
sudo systemctl enable --now redis.service
# 查看版本
redis-server --version4、修改配置文件
# 修改bind的地址(redis监听地址)
bind 192.168.8.104
# 保护模式,设置为no则允许远程连接
protected-mode no
# 修改redis密码
requirepass qwert54321!!