Redis安装

Redis下载
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
shell> yum install tcl -y
shell> tar -xvf redis-6.2.7.tar.gz -C /usr/local/
shell> cd /usr/local/redis-6.2.7/
shell> make
shell> make install # 这一步操作安装的文件会安装到/usr/local/bin下,可以不执行
shell> ls /usr/local/bin/ # 查看安装文件
shell> ln -s /usr/local/redis-6.2.7/ /usr/local/redis
shell> cd /usr/local/redis
shell> cd src
shell> ./redis-server # 启动redis服务,测试是否可以启动 CTRL+C停止服务
shell> cd /usr/local/redis
shell> cp redis.conf redis.conf.bak_YYYYMMDDHHMM
shell> vi redis.conf
shell> /usr/local/bin/redis-server /usr/local/redis/redis.conf # 启动服务
shell> /usr/local/bin/redis-cli -a YOUR_PASS shutdown # 关闭redis服务
shell> vi /etc/systemd/system/redis.service
shell> systemctl daemon-reload
shell> systemctl enable redis
shell> systemctl start redis
redis.conf
1
2
3
4
5
6
7
8
9
10
11
#bind 127.0.0.1 -::1 # 注释
bind 0.0.0.0 # 新增 远程访问
#daemonize no # 注释
daemonize yes # 新增 守护进程运行
requirepass YOUR_PASS # 访问密码
port 6379
dir ./
databases 16
maxmemory 1G # 配置最大使用内存大小
#logfile "" # 注释
logfile "redis.log" # 新增 配置日志记录文件
redis.service
1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target