记录一下Ubuntu20.04 64位系统下使用apt-get安装Redis
首先检查一下系统是否安装过redis
whereis redis
myw@myw-K84HR:~$ whereis redis
redis:
myw@myw-K84HR:~$
更新软件包
sudo apt-get update -y
安装redis
sudo apt-get install redis-server -y
myw@myw-K84HR:~$ sudo apt-get update -y
命中:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
命中:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
命中:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
正在读取软件包列表... 完成
myw@myw-K84HR:~$ sudo apt-get install redis-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
将会同时安装下列软件:
libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-tools
建议安装:
ruby-redis
下列【新】软件包将被安装:
libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-server redis-tools
升级了 0 个软件包,新安装了 7 个软件包,要卸载 0 个软件包,有 49 个软件包未被升级。
需要下载 1,273 kB 的归档。
解压缩后会消耗 5,725 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 libjemalloc2 amd64 5.2.1-4ubuntu1 [240 kB]
获取:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build4 [99.9 kB]
获取:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 liblzf1 amd64 3.6-3 [7,444 B]
获取:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 lua-bitop amd64 1.0.2-5 [6,680 B]
获取:5 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 lua-cjson amd64 2.1.0+dfsg-2.1 [17.4 kB]
获取:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 redis-tools amd64 5:6.0.16-1ubuntu1 [856 kB]
获取:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 redis-server amd64 5:6.0.16-1ubuntu1 [45.9 kB]
已下载 1,273 kB,耗时 3秒 (433 kB/s)
正在选中未选择的软件包 libjemalloc2:amd64。
(正在读取数据库 ... 系统当前共安装有 212231 个文件和目录。)
准备解压 .../0-libjemalloc2_5.2.1-4ubuntu1_amd64.deb ...
正在解压 libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
正在选中未选择的软件包 liblua5.1-0:amd64。
准备解压 .../1-liblua5.1-0_5.1.5-8.1build4_amd64.deb ...
正在解压 liblua5.1-0:amd64 (5.1.5-8.1build4) ...
正在选中未选择的软件包 liblzf1:amd64。
准备解压 .../2-liblzf1_3.6-3_amd64.deb ...
正在解压 liblzf1:amd64 (3.6-3) ...
正在选中未选择的软件包 lua-bitop:amd64。
准备解压 .../3-lua-bitop_1.0.2-5_amd64.deb ...
正在解压 lua-bitop:amd64 (1.0.2-5) ...
正在选中未选择的软件包 lua-cjson:amd64。
准备解压 .../4-lua-cjson_2.1.0+dfsg-2.1_amd64.deb ...
正在解压 lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
正在选中未选择的软件包 redis-tools。
准备解压 .../5-redis-tools_5%3a6.0.16-1ubuntu1_amd64.deb ...
正在解压 redis-tools (5:6.0.16-1ubuntu1) ...
正在选中未选择的软件包 redis-server。
准备解压 .../6-redis-server_5%3a6.0.16-1ubuntu1_amd64.deb ...
正在解压 redis-server (5:6.0.16-1ubuntu1) ...
正在设置 libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
正在设置 lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
正在设置 liblzf1:amd64 (3.6-3) ...
正在设置 lua-bitop:amd64 (1.0.2-5) ...
正在设置 liblua5.1-0:amd64 (5.1.5-8.1build4) ...
正在设置 redis-tools (5:6.0.16-1ubuntu1) ...
正在设置 redis-server (5:6.0.16-1ubuntu1) ...
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.service.
正在处理用于 man-db (2.10.2-1) 的触发器 ...
正在处理用于 libc-bin (2.35-0ubuntu3.4) 的触发器 ...
myw@myw-K84HR:~$
查看redis是否运行了,默认安装是自动运行的
sudo netstat -lnp|grep redis
sudo ps -ef|grep redis
sudo ps -ef|grep redis
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 735727/redis-server
tcp6 0 0 ::1:6379 :::* LISTEN 735727/redis-server
myw@myw-K84HR:~$ sudo ps -ef|grep redis
redis 735727 1 0 14:57 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
myw 738330 724691 0 15:01 pts/0 00:00:00 grep --color=auto redis
myw@myw-K84HR:~$ sudo service redis status
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-12-02 14:57:33 CST; 4min 25s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 735727 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 4567)
Memory: 2.6M
CPU: 936ms
CGroup: /system.slice/redis-server.service
└─735727 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
12月 02 14:57:33 myw-K84HR systemd[1]: Starting Advanced key-value store...
12月 02 14:57:33 myw-K84HR systemd[1]: Started Advanced key-value store.
myw@myw-K84HR:~$
myw@myw-K84HR:~$ whereis redis
redis: /etc/redis
myw@myw-K84HR:~$
查看安装的版本
myw@myw-K84HR:~$ redis-server --version
Redis server v=6.0.16 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=a3fdef44459b3ad6
myw@myw-K84HR:~$
修改一些配置信息以及账号密码信息
myw@myw-K84HR:~$ sudo chmod 777 /etc/redis
[sudo] myw 的密码:
myw@myw-K84HR:~$
一般为了支持本地(自己电脑访问服务器端redis的使用)除了放开端口这些操作外,还需要对redis进行配置,还要加上密码
在redis.conf文件里
注释 # bind 127.0.0.1 -::1
修改protected-mode no (默认yes,开启保护模式,限制为本地访问,改为no)
daemonize no(默认no,改为yes意为以守护进程方式启动,可后台运行,我后面会配置服务方式开机启动,因此不改动)
requirepass 12345678 (密码,我修改成常见的12345678)
常见指令
停止
sudo service redis stop
启动
sudo service redis start
重启
sudo service redis restart
查看状态
sudo service redis status
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 753854/redis-server
tcp6 0 0 :::6379 :::* LISTEN 753854/redis-server
myw@myw-K84HR:~$ sudo service redis stop
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
myw@myw-K84HR:~$ sudo service redis start
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 754147/redis-server
tcp6 0 0 :::6379 :::* LISTEN 754147/redis-server
myw@myw-K84HR:~$ sudo service redis restart
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 754285/redis-server
tcp6 0 0 :::6379 :::* LISTEN 754285/redis-server
myw@myw-K84HR:~$
停止
sudo systemctl stop redis
启用
sudo systemctl start redis
重启
sudo systemctl restart redis
查询状态
sudo systemctl status redis
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 754285/redis-server
tcp6 0 0 :::6379 :::* LISTEN 754285/redis-server
myw@myw-K84HR:~$ sudo systemctl stop redis
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
myw@myw-K84HR:~$ sudo systemctl start redis
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 756269/redis-server
tcp6 0 0 :::6379 :::* LISTEN 756269/redis-server
myw@myw-K84HR:~$ sudo systemctl restart redis
myw@myw-K84HR:~$ sudo netstat -lnp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 756755/redis-server
tcp6 0 0 :::6379 :::* LISTEN 756755/redis-server
myw@myw-K84HR:~$ sudo systemctl status redis
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-12-02 15:28:09 CST; 1min 2s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 756755 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 4567)
Memory: 2.6M
CPU: 309ms
CGroup: /system.slice/redis-server.service
└─756755 "/usr/bin/redis-server *:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
12月 02 15:28:09 myw-K84HR systemd[1]: Starting Advanced key-value store...
12月 02 15:28:09 myw-K84HR systemd[1]: Started Advanced key-value store.
myw@myw-K84HR:~$
卸载redis
sudo apt-get remove redis-server
sudo apt-get autoremove redis-server --purge
myw@myw-K84HR:~$ whereis redis
redis:
myw@myw-K84HR:~$ sudo find / -name "redis*"
/snap/gnome-42-2204/120/usr/lib/python3/dist-packages/pip/_vendor/cachecontrol/caches/redis_cache.py
/snap/gnome-42-2204/141/usr/lib/python3/dist-packages/pip/_vendor/cachecontrol/caches/redis_cache.py
find: ‘/run/user/1000/doc’: 权限不够
find: ‘/run/user/1000/gvfs’: 权限不够
find: ‘/run/user/128/doc’: 权限不够
find: ‘/run/user/128/gvfs’: 权限不够
/run/systemd/propagate/redis-server.service
/var/cache/apt/archives/redis-tools_5%3a6.0.16-1ubuntu1_amd64.deb
/var/cache/apt/archives/redis-server_5%3a6.0.16-1ubuntu1_amd64.deb
myw@myw-K84HR:~$
也没有什么需要特别注意删除的文件或文件夹
文章评论