Linux 安装部署Redis

来源:互联网 发布:go并发编程实战 编辑:程序博客网 时间:2024/06/08 05:27

在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 installcd src && make installmake[1]: Entering directory `/tmp/redis-4.0.2/src'    CC Makefile.depmake[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 installmake[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 -ltotal 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-clilrwxrwxrwx 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]# lsbin  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 oO0OoO0OoO0Oo21203:C 28 Sep 09:37:08.713 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21203, just started21203: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 initialized21203: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 seconds21203: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 oO0OoO0OoO0Oo21535:C 28 Sep 09:41:40.394 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21535, just started21535:C 28 Sep 09:41:40.394 # Configuration loaded

查看一下是否启动了

[root@VM_75_51_centos redis]# ps -ef | grep redisroot     21536     1  0 09:41 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379root     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> pingPONG

停止redis服务

[root@VM_75_51_centos redis]# ./bin/redis-cli shutdown[root@VM_75_51_centos redis]# ps -ef | grep redisroot     21691 17018  0 09:43 pts/2    00:00:00 grep --color=auto redis
原创粉丝点击