linux安装Redis

 Redis下载地址:Index of /releases/

参考地址:linux 安装redis 完整步骤 - 掘金

1.下载

[root@localhost ~]# mkdir /opt/redis
[root@localhost ~]# cd /opt/redis/
[root@localhost redis]# wget http://download.redis.io/releases/redis-6.2.13.tar.gz

2.解压

[root@localhost redis]# tar -zxvf redis-6.2.13.tar.gz 

3.安装,默认安装到/usr/local/bin文件夹下,也可以用make install PREFIX=安装目录 来指定安装位置,不过不推荐。安装在默认位置可以在任何位置使用redis-server、redis-cli等命令。。

[root@localhost redis]# cd redis-6.2.13
[root@localhost redis-6.2.13]# make
[root@localhost redis-6.2.13]# cd src/
[root@localhost src]# make install

4.启动

[root@localhost redis]# redis-server
18985:C 02 Aug 2023 18:21:29.085 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18985:C 02 Aug 2023 18:21:29.085 # Redis version=6.2.13, bits=64, commit=00000000, modified=0, pid=18985, just started
18985:C 02 Aug 2023 18:21:29.085 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
18985:M 02 Aug 2023 18:21:29.086 * Increased maximum number of open files to 10032 (it was originally set to 1024).
18985:M 02 Aug 2023 18:21:29.086 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.13 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18985
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

18985:M 02 Aug 2023 18:21:29.086 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18985:M 02 Aug 2023 18:21:29.086 # Server initialized
18985:M 02 Aug 2023 18:21:29.086 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
18985:M 02 Aug 2023 18:21:29.086 * Ready to accept connections

ctrl+c可以停止正在运行的redis 

4.1带配置文件启动,配置文件在解压目录里,拷贝一份到/home/redis文件夹下

[root@localhost redis]# cp redis-6.2.13/redis.conf /home/redis
[root@localhost redis]# redis-server redis.conf 

4.2 redis.conf配置文件详解

# 下面是默认配置,只能本地访问
# bind 127.0.0.1 -::1
# 任何地址都可访问
bind 0.0.0.0

# 配置redis密码为foobared
requirepass foobared

# 允许后台启动,默认是daemonize no
daemonize yes

#保护模式,yes则需要配置密码才可远程访问,no则无需密码
protected-mode yes

5.访问redis,-p 指定redis端口,默认6379端口也可不写

[root@localhost redis]# redis-cli -p 6379

6.centos7想要除了本机之外其他电脑也能访问还需开放防火墙端口

[root@localhost redis]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
[root@localhost redis]# systemctl restart firewalld

7.查看redis是否后台运行

[root@localhost redis]# ps aux|grep redis
root      19007  0.0  0.5 162520  9900 ?        Ssl  18:32   0:00 redis-server 127.0.0.1:6379
root      19013  0.0  0.0 112824   980 pts/1    S+   18:32   0:00 grep --color=auto redis

8.停止后台运行的redis

[root@localhost redis]# redis-cli shutdown

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值