ubuntu安装redis记录

第一步,命令安装redis:apt-get install redis-server

root@luoyh6:~# apt-get install redis-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-tools
Suggested packages:
  ruby-redis
The following NEW packages will be installed:
  libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-server redis-tools
0 upgraded, 7 newly installed, 0 to remove and 90 not upgraded.
Need to get 1,273 kB of archives.
After this operation, 5,725 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 libjemalloc2 amd64 5.2.1-4ubuntu1 [240 kB]
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build4 [99.9 kB]
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 liblzf1 amd64 3.6-3 [7,444 B]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 lua-bitop amd64 1.0.2-5 [6,680 B]
Get:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 lua-cjson amd64 2.1.0+dfsg-2.1 [17.4 kB]
Get:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 redis-tools amd64 5:6.0.16-1ubuntu1 [856 kB]
Get:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 redis-server amd64 5:6.0.16-1ubuntu1 [45.9 kB]
Fetched 1,273 kB in 4s (293 kB/s)  
Selecting previously unselected package libjemalloc2:amd64.
(Reading database ... 136952 files and directories currently installed.)
Preparing to unpack .../0-libjemalloc2_5.2.1-4ubuntu1_amd64.deb ...
Unpacking libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
Selecting previously unselected package liblua5.1-0:amd64.
Preparing to unpack .../1-liblua5.1-0_5.1.5-8.1build4_amd64.deb ...
Unpacking liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Selecting previously unselected package liblzf1:amd64.
Preparing to unpack .../2-liblzf1_3.6-3_amd64.deb ...
Unpacking liblzf1:amd64 (3.6-3) ...
Selecting previously unselected package lua-bitop:amd64.
Preparing to unpack .../3-lua-bitop_1.0.2-5_amd64.deb ...
Unpacking lua-bitop:amd64 (1.0.2-5) ...
Selecting previously unselected package lua-cjson:amd64.
Preparing to unpack .../4-lua-cjson_2.1.0+dfsg-2.1_amd64.deb ...
Unpacking lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Selecting previously unselected package redis-tools.
Preparing to unpack .../5-redis-tools_5%3a6.0.16-1ubuntu1_amd64.deb ...
Unpacking redis-tools (5:6.0.16-1ubuntu1) ...
Selecting previously unselected package redis-server.
Preparing to unpack .../6-redis-server_5%3a6.0.16-1ubuntu1_amd64.deb ...
Unpacking redis-server (5:6.0.16-1ubuntu1) ...
Setting up libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
Setting up lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Setting up liblzf1:amd64 (3.6-3) ...
Setting up lua-bitop:amd64 (1.0.2-5) ...
Setting up liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Setting up redis-tools (5:6.0.16-1ubuntu1) ...
Setting up 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.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.6) ...
Scanning processes...                                                                                         
Scanning candidates...                                                                                        
Scanning linux images...                                                                                      

Restarting services...
 systemctl restart packagekit.service systemd-resolved.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@luoyh6:~# 
root@luoyh6:~# 

第二步:修改密码:在/etc/redis/redis.conf文件里面增添或修改port、requirepass (默认端口是6379,根据自己项目需求进行修改)

# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 31778
requirepass 123456
# TCP listen() backlog.
#
# In high requests-per-second environments you need a high backlog in order
# to avoid slow clients connection issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# Unix socket.

第三步:重启redis

service redis restart

第四步:连接redis,输入密码

root@luoyh6:~# 
root@luoyh6:~# 
root@luoyh6:~# redis-cli -p 31778
127.0.0.1:31778> 
127.0.0.1:31778> 
127.0.0.1:31778> AUTH 123456
OK
127.0.0.1:31778> 
127.0.0.1:31778> 
127.0.0.1:31778> 

Ubuntu安装 Redis 并配置一些常用的选项可以帮助你快速搭建一个稳定、高效的缓存或消息队列服务。以下是详细的步骤指南: ### 第一步:更新软件索引并安装 Redis 首先确保你的系统软件是最新的,然后安装 Redis Server: ```bash # 更新本地的软件索引 sudo apt update # 安装最新的Redis版本 sudo apt install redis-server -y ``` 如果你需要安装特定版本的 Redis,请参考之前关于[apt安装指定版本的redis](https://)的回答。 ### 第二步:检查 Redis 是否已成功启动 安装完成后,默认情况下 Redis 服务器会被设为开机自启并且已经运行。我们可以通过以下命令验证其状态: ```bash sudo systemctl status redis.service ``` 如果一切正常的话,你会看到类似于 `active (running)` 的信息。 ### 第三步:修改基本配置文件 `/etc/redis/redis.conf` 为了满足不同的需求,你可以编辑主配置文件来调整各种参数: 1. **绑定IP地址** 默认情况下,Redis 只监听 localhost (`127.0.0.1`) 接口。若你要让远程客户端能够连接上这台机器上的 Redis 实例,则需取消注释 bind 行并将 IP 改成相应值(如公网 IP)。不过请注意开放外部访问的安全风险。 ```conf # 修改后的bind行示例: bind 0.0.0.0 ``` 2. **端口号** 如果不想使用默认的 6379 端口作为通信端口,可以在 port 配置项下更改数字部分为自己所需的数值。 ```conf port 6380 ``` 3. **持久化策略** - RDB 快照模式开启与否由 save 参数控制 ```conf # 每秒内有超过一千次写入就触发一次快照保存 save 900 1 ``` - 开启 AOF 日志记录机制以提供更高的数据安全性 ```conf appendonly yes ``` 4. **内存管理** 设置最大使用的 RAM 数量。当达到限制时,可以根据 LRU(Least Recently Used)等算法淘汰一部分键空间内的内容。 ```conf maxmemory 2gb ``` 5. **密码保护** 对于生产环境下的实例建议启用认证功能。 ```conf requirepass your_password_here ``` 完成上述修改后记得重启 Redis 让它们生效: ```bash sudo systemctl restart redis.service ``` 最后别忘了防火墙规则允许相应的 TCP 连接通过,比如 UFW 用户应添加如下规则放通对外提供的服务端口: ```bash sudo ufw allow 6379/tcp ``` 以上就是Ubuntu环境下安装及初步优化Redis的一些关键点,希望能帮助到您! --- 更多高级配置和其他特性可以查阅官方文档或者社区资料库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

映秀小子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值