Linux 安装部署Redis

在Linux上安装Redis,注意前提需要gcc环境

首先去官网下载压缩包再传到服务器上,或者也可直接使用wget在线下载

wget http://download.redis.io/releases/redis-4.0.2.tar.gz

下载完后解压

tar -zxvf redis-4.0.2.tar.gz

之后进入解压后的文件夹进行编译

make

编译完成以后进行安装

[root@VM_75_51_centos redis-4.0.2]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: Entering directory `/tmp/redis-4.0.2/src'
    CC Makefile.dep
make[1]: Leaving directory `/tmp/redis-4.0.2/src'
make[1]: Entering directory `/tmp/redis-4.0.2/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/tmp/redis-4.0.2/src'

之后我们进入/usr/local/redis/bin 目录查看是否安装成功

[root@VM_75_51_centos bin]# cd /usr/local/redis/bin/
[root@VM_75_51_centos bin]# ls -l
total 21820
-rwxr-xr-x 1 root root 2450686 Sep 28 09:29 redis-benchmark
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-check-aof
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-check-rdb
-rwxr-xr-x 1 root root 2604968 Sep 28 09:29 redis-cli
lrwxrwxrwx 1 root root      12 Sep 28 09:29 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-server
[root@VM_75_51_centos bin]# 

可以看到目录下有一系列的可执行文件

  • redis-benchmark 性能测试工具
  • redis-check-aof AOF文件修复工具
  • redis-check-rdb RDB文件检查工具
  • redis-cli 客户端
  • redis-server 服务端

之后需要把我们之前解压的目录下的redis.conf配置文件复制到我们redis的安装目录下

[root@VM_75_51_centos redis]# cp /tmp/redis-4.0.2/redis.conf ./redis.conf
[root@VM_75_51_centos redis]# ls
bin  redis.conf

此时我们Redis安装完成可以启动。首先进入bin目录下运行redis-server

[root@VM_75_51_centos bin]# ./redis-server 
21203:C 28 Sep 09:37:08.713 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21203:C 28 Sep 09:37:08.713 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21203, just started
21203:C 28 Sep 09:37:08.713 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 21203
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

21203:M 28 Sep 09:37:08.714 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
21203:M 28 Sep 09:37:08.714 # Server initialized
21203:M 28 Sep 09:37:08.714 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
21203:M 28 Sep 09:37:08.714 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
21203:M 28 Sep 09:37:08.714 * DB loaded from disk: 0.000 seconds
21203:M 28 Sep 09:37:08.714 * Ready to accept connections

但是这种启动是前台启动,启动完成后当前界面就无法再进行操作了,因此需要换一种启动的方式,后台运行redis服务

首先打开之前复制过来的redis.conf文件

daemonize no 改成daemonize yes

后台启动redis服务

[root@VM_75_51_centos redis]# ./bin/redis-server ./redis.conf 
21535:C 28 Sep 09:41:40.394 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21535:C 28 Sep 09:41:40.394 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21535, just started
21535:C 28 Sep 09:41:40.394 # Configuration loaded

查看一下是否启动了

[root@VM_75_51_centos redis]# ps -ef | grep redis
root     21536     1  0 09:41 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root     21601 17018  0 09:42 pts/2    00:00:00 grep --color=auto redis

接下来可以使用redis了

[root@VM_75_51_centos redis]# ./bin/redis-cli 
127.0.0.1:6379> ping
PONG

停止redis服务

[root@VM_75_51_centos redis]# ./bin/redis-cli shutdown
[root@VM_75_51_centos redis]# ps -ef | grep redis
root     21691 17018  0 09:43 pts/2    00:00:00 grep --color=auto redis
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值