Redis之在Linux上安装

一、安装gcc 
1、Redis在linux上的安装首先必须先安装gcc,这个是用来编译redis的源文件的。首先需要先切换的到root用户:

[cheny@localhost ~]$ su
Password: 
[root@localhost cheny]# 

  • 1
  • 2
  • 3
  • 4
  • 5

2、然后开始安装gcc:

[root@localhost /]# yum install gcc-c++
//这个命令是在线安装的,所以在这之前你的VM必须能够上网,需要在   VM中把网卡设置成NAT模式 ,因为我使用的是centos,在网络设置中需要把网卡开启,反正我在装完系统之后它是默认关闭的
  • 1
  • 2

3、之后便会出现下载文件界面: 
gcc下载界面 
4、会出现2次确认界面,输入y即可 
这里写图片描述 
5、之后会进行更新检查,进行更新验证等等操作,等他自动完成即可。 
6、出现如下代码即是安装成功:

Installed:
  gcc-c++.x86_64 0:4.8.5-11.el7                               

Dependency Installed:
  cpp.x86_64 0:4.8.5-11.el7                                   
  gcc.x86_64 0:4.8.5-11.el7                                   
  glibc-devel.x86_64 0:2.17-157.el7_3.5                       
  glibc-headers.x86_64 0:2.17-157.el7_3.5                     
  kernel-headers.x86_64 0:3.10.0-514.26.2.el7                 
  libmpc.x86_64 0:1.0.1-3.el7                                 
  libstdc++-devel.x86_64 0:4.8.5-11.el7                       

Dependency Updated:
  glibc.x86_64 0:2.17-157.el7_3.5                             
  glibc-common.x86_64 0:2.17-157.el7_3.5                      

Complete!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

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

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

下载完后解压

tar -zxvf redis-4.0.2.tar.gz
  • 1

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

make
  • 1

编译完成以后进行安装

[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'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

之后我们进入/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]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

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

  • 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
  • 1
  • 2
  • 3

此时我们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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

但是这种启动是前台启动,启动完成后当前界面就无法再进行操作了,因此需要换一种启动的方式,后台运行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
  • 1
  • 2
  • 3
  • 4

查看一下是否启动了

[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
  • 1
  • 2
  • 3

接下来可以使用redis了

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

停止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

猜你喜欢

转载自blog.csdn.net/dajienet/article/details/79960386
今日推荐