Ubuntu20.04(linux)离线安装redis
官网redis下载地址
下载安装包redis-6.0.9.tar.gz。
1 下载安装
(1)解压
sudo tar -xzvf redis-6.0.9.tar.gz -C /usr/local/
cd /usr/local/redis-6.0.9/
(2)编译
sudo make
(3)测试
sudo dpkg -i libtcl8.6_8.6.10+dfsg-1_amd64.deb
sudo dpkg -i tcl8.6_8.6.10+dfsg-1_amd64.deb
sudo make test【依赖tcl模块】
出现如下内容表示测试通过
\o/ All tests passed without errors!
Cleanup: may take some time... OK
make[1]: Leaving directory '/usr/local/redis-6.0.9/src'
(4)安装
sudo make install
PREFIX未指定目录,默认安装到/usr/local/bin里面了
该目录下生成几个可执行文件
redis-benchmark 性能测试程序
redis-check-aof
redis-check-rdb
redis-cli 客户端可执行程序
redis-server 服务端可执行程序
2 修改配置文件
cd /usr/local/redis-6.0.9
sudo cp redis.conf redis.conf.backup
sudo mkdir /usr/local/redis-6.0.9/data
sudo touch /usr/local/redis-6.0.9/myredis.log
配置文件
#外网可访问
#bind 127.0.0.1
protected-mode no
#以后台进程方式启动
daemonize yes
#修改log存放路径
logfile /usr/local/redis-6.0.9/myredis.log
stop-writes-on-bgsave-error no
#修改AOF及RBD存放路径
dir /usr/local/redis-6.0.9/data
#设置密码
requirepass bigdata
3 开机自启动
(8)把redis服务添加至systemctl管理
#cd /usr/lib/systemd/system
#sudo vi redis.service
[Unit]
Description=redis.server
After=network.target
[Service]
Type=forking
PIDFILE=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/redis-6.0.9/redis.conf
ExecRepload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#sudo chmod a+x redis.service
#sudo systemctl daemon-reload
#sudo systemctl start redis.service
#sudo systemctl enable redis#设置开机自启动
4 测试使用
redis-cli
127.0.0.1:6379> set “name” “lucy”
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth bigdata
OK
127.0.0.1:6379> set “name” “lucy”
OK
127.0.0.1:6379> get “name”
“lucy”