IT评测·应用市场-qidao123.com技术社区

标题: Ubuntu上安装Redis的详细教程 [打印本页]

作者: 光之使者    时间: 2024-8-19 00:41
标题: Ubuntu上安装Redis的详细教程
1、安装redis

起首,访问Redis官网,点击首页的【Get Started】,然后点击Install Redis on Linux
安装
终端依次输入以下下令,假如过程中没有错误提示,则redis安装完成。
  1. sudo apt install lsb-release curl gpg
复制代码
  1. curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
复制代码
  1. 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
复制代码
  1. sudo apt-get update
复制代码
  1. sudo apt-get install redis
复制代码
  执行过程

  1. ubuntu@ip-172-0-0-00:~$
  2. ubuntu@ip-172-0-0-00:~$ sudo apt install lsb-release curl gpg
  3. Reading package lists... Done
  4. Building dependency tree... Done
  5. Reading state information... Done
  6. lsb-release is already the newest version (12.0-2).
  7. curl is already the newest version (8.5.0-2ubuntu10.2).
  8. gpg is already the newest version (2.4.4-2ubuntu17).
  9. gpg set to manually installed.
  10. 0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
  11. ubuntu@ip-172-0-0-00:~$
  12. ubuntu@ip-172-0-0-00:~$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
  13. ubuntu@ip-172-0-0-00:~$
  14. ubuntu@ip-172-0-0-00:~$ 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
  15. deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb noble main
  16. ubuntu@ip-172-0-0-00:~$
  17. ubuntu@ip-172-0-0-00:~$ sudo apt-get update
  18. Hit:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu noble InRelease
  19. Hit:2 http://cn-north-1.ec2.archive.ubuntu.com/ubuntu noble InRelease
  20. Get:3 http://cn-north-1.ec2.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
  21. Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
  22. Hit:5 http://cn-north-1.ec2.archive.ubuntu.com/ubuntu noble-backports InRelease
  23. Get:6 https://packages.redis.io/deb noble InRelease [3854 B]
  24. Get:7 https://packages.redis.io/deb noble/main amd64 Packages [1645 B]
  25. Get:8 https://packages.redis.io/deb noble/main all Packages [747 B]
  26. Ign:9 https://download.docker.com/linux/ubuntu focal InRelease
  27. Ign:9 https://download.docker.com/linux/ubuntu focal InRelease
  28. Ign:9 https://download.docker.com/linux/ubuntu focal InRelease
  29. Err:9 https://download.docker.com/linux/ubuntu focal InRelease
  30.   Cannot initiate the connection to download.docker.com:443 (2a03:2880:f131:83:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (67.228.235.93), connection timed out
  31. Fetched 132 kB in 37s (3549 B/s)
  32. Reading package lists... Done
  33. W: https://mirrors.aliyun.com/docker-ce/linux/ubuntu/dists/noble/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
  34. W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/focal/InRelease  Cannot initiate the connection to download.docker.com:443 (2a03:2880:f131:83:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (67.228.235.93), connection timed out
  35. W: Some index files failed to download. They have been ignored, or old ones used instead.
  36. ubuntu@ip-172-0-0-00:~$
  37. ubuntu@ip-172-0-0-00:~$ sudo apt-get install redis
  38. Reading package lists... Done
  39. Building dependency tree... Done
  40. Reading state information... Done
  41. The following additional packages will be installed:
  42.   redis-server redis-tools
  43. Suggested packages:
  44.   ruby-redis
  45. The following NEW packages will be installed:
  46.   redis redis-server redis-tools
  47. 0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded.
  48. Need to get 1633 kB of archives.
  49. After this operation, 9595 kB of additional disk space will be used.
  50. Do you want to continue? [Y/n] y
  51. Get:1 https://packages.redis.io/deb noble/main amd64 redis-tools amd64 6:7.4.0-1rl1~noble1 [1554 kB]
  52. Get:2 https://packages.redis.io/deb noble/main amd64 redis-server amd64 6:7.4.0-1rl1~noble1 [63.9 kB]
  53. Get:3 https://packages.redis.io/deb noble/main amd64 redis all 6:7.4.0-1rl1~noble1 [15.3 kB]
  54. Fetched 1633 kB in 3s (520 kB/s)
  55. Selecting previously unselected package redis-tools.
  56. (Reading database ... 98676 files and directories currently installed.)
  57. Preparing to unpack .../redis-tools_6%3a7.4.0-1rl1~noble1_amd64.deb ...
  58. Unpacking redis-tools (6:7.4.0-1rl1~noble1) ...
  59. Selecting previously unselected package redis-server.
  60. Preparing to unpack .../redis-server_6%3a7.4.0-1rl1~noble1_amd64.deb ...
  61. Unpacking redis-server (6:7.4.0-1rl1~noble1) ...
  62. Selecting previously unselected package redis.
  63. Preparing to unpack .../redis_6%3a7.4.0-1rl1~noble1_all.deb ...
  64. Unpacking redis (6:7.4.0-1rl1~noble1) ...
  65. Setting up redis-tools (6:7.4.0-1rl1~noble1) ...
  66. Setting up redis-server (6:7.4.0-1rl1~noble1) ...
  67. Setting up redis (6:7.4.0-1rl1~noble1) ...
  68. Processing triggers for man-db (2.12.0-4build2) ...
  69. Scanning processes...
  70. Scanning candidates...
  71. Scanning linux images...
  72. Pending kernel upgrade!
  73. Running kernel version:
  74.   6.8.0-1010-aws
  75. Diagnostics:
  76.   The currently running kernel version is not the expected kernel version 6.8.0-1013-aws.
  77. Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting.
  78. Restarting services...
  79. Service restarts being deferred:
  80. /etc/needrestart/restart.d/dbus.service
  81. systemctl restart networkd-dispatcher.service
  82. systemctl restart systemd-logind.service
  83. systemctl restart unattended-upgrades.service
  84. No containers need to be restarted.
  85. No user sessions are running outdated binaries.
  86. No VM guests are running outdated hypervisor (qemu) binaries on this host.
  87. ubuntu@ip-172-0-0-00:~$
复制代码
2、修改设置

答应外网端访问

redis的设置文件在/etc/redis/redis.conf,打开这个文件
  1. sudo vim /etc/redis/redis.conf
复制代码
  1. #注释下面内容
  2. bind 127.0.0.1 -::1
  3. #添加
  4. bind 0.0.0.0
  5. 修改为no
  6. protected-mode no
复制代码

增加暗码

 3、相关下令


  1. 启动方式一
  2. /etc/init.d/redis-server start
  3. 启动方式二
  4. systemctl start redis-server
  5. 启动方式三
  6. service redis-server start
  7. 重启
  8. service redis-server restart
  9. 关闭
  10. service redis-server stop
  11. 查看状态
  12. service redis-server status
复制代码
  操作记录
  1. ubuntu@ip-172-0-0-00:/etc$ sudo /etc/init.d/redis-server start
  2. Starting redis-server (via systemctl): redis-server.service.
  3. ubuntu@ip-172-0-0-00:/etc$
  4. ubuntu@ip-172-0-0-00:/etc$ service redis-server status
  5. ● redis-server.service - Advanced key-value store
  6.      Loaded: loaded (/usr/lib/systemd/system/redis-server.service; disabled; preset: enabled)
  7.      Active: active (running) since Tue 2024-08-13 11:46:55 UTC; 15min ago
  8.        Docs: http://redis.io/documentation,
  9.              man:redis-server(1)
  10.    Main PID: 503818 (redis-server)
  11.      Status: "Ready to accept connections"
  12.       Tasks: 6 (limit: 18951)
  13.      Memory: 3.5M (peak: 4.1M)
  14.         CPU: 2.882s
  15.      CGroup: /system.slice/redis-server.service
  16.              └─503818 "/usr/bin/redis-server 127.0.0.1:6379"
  17. Aug 13 11:46:55 ip-172-0-0-00 systemd[1]: Starting redis-server.service - Advanced key-value store...
  18. Aug 13 11:46:55 ip-172-0-0-00 systemd[1]: Started redis-server.service - Advanced key-value store.
  19. ubuntu@ip-172-0-0-00:/etc$
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4