Installation and deployment of Redis under Linux

1. Introduction to Redis

Redis is one of the more popular NOSQL systems, it is a key-value storage system. Similar to Memcache, but largely compensates for the shortcomings of Memcache. It supports relatively more value types to be stored, including string, list, set, zset, and hash. These data types all support push/pop, add/remove, intersection union and difference, and richer operations. On this basis, Redis supports sorting in various ways.
Like Memcache, Redis data is cached in computer memory. The difference is that Memcache can only cache data in memory and cannot automatically write to the hard disk regularly. . Therefore, the application scenario of Memcache is suitable for caching data that does not need to be persisted. The difference between Redis is that it periodically writes updated data to disk or writes modification operations to additional record files to achieve data persistence.

Second, the installation of Redis

The following describes the installation and deployment of Redis in the Linux environment

1. First, go to the official website to download the Redis compressed package, address: http://redis.io/download and download the stable version 3.0.7.

2. Use the remote management tool to copy the compressed package to the Linux server and perform the decompression operation

3. Execute make to compile the Redis decompressed file

 

 

When compiling the redis source code on the linux system, the prompt "make cc Command not found, make: *** [adlist.o] Error 127" is displayed. This is because the system does not have the gcc environment installed, so the above prompt will appear when compiling. When gcc is installed and then compiled, the above error prompt will disappear.

 

 

 

  1. This is because the newly installed Linux system does not have the gcc environment installed, and needs to install gcc. For convenience, I choose to install it with yum.

    # yum  install  gcc

    If prompted You need to be root to perform this command, log in with the root account.

    When compiling redis, it prompts make cc Command not found
  2.  
    When compiling redis, it prompts make cc Command not found
  3.  

    Verify that gcc is installed successfully

    # rpm -qa |grep gcc

    When compiling redis, it prompts make cc Command not found
  4.  

    重新对redis进行编译安装

    # make  && make install 

    通过下图可以看到编译通过,并成功安装redis。

    When compiling redis, it prompts make cc Command not found
    When compiling redis, it prompts make cc Command not found
  5. 6

    总结:在进行linux系统安装时,尤其是进行linux服务器安装时,系统工程师往往会最小化安装相应的在linux系统。那么,在这样的linux系统上进行源码文件编译安装时,通常都会出现cc: Command not found,这说明系统上没有安装C语言环境,需要安装,在linux系统上的C环境是gcc,因此需要安装gcc。

     

     

    第四步:编译成功后进入redis-2.6.14/src 目录

    # cd /usr/local/soft/redis-2.6.14/src

    # ll

    会看到有几个可执行文件:

    这里我们只需要用到两个文件就可以了:redis-server和redis-cli

     

    第五步:创建一个工作目录,然后将上述的两个文件copy到工作目录下

    我是在/usr/local/目录下创建了一个redis 目录

    # cd /usr/local/

    # mkdir redis

    然后将src目录下的redis-server和server-cli 复制到redis目录下

    [root@localhost src]# cp redis-cli redis-server /usr/local/redis/

     

    然后再回到redis-2.6.14 源码目录 将redis.conf 文件复制到 redis 目录下

    [root@localhost redis-2.6.14]# cp redis.conf /usr/local/redis/

     

    最终结果是,redis目录下有了三个文件 如下图:

    到这里,就算完成了 ,

     

    接下来运行redis服务:

    [root@localhost redis]# ./redis-server

    出现下面的界面,就说明你的redis可以正常使用了

     

    现在还有个问题:redis在前台运行,我不能做其他事情怎么办?如何将redis放在后台运行?

    方法:修改redis.conf 文件,将daemonize no 改为daemonize yes

    [root@localhost redis]# vi redis.conf

    将no修改为yes ; 保存退出

     

    杀掉rdis进程,然后再次打开redis服务

    [root@localhost redis]# killall redis-server

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

    出现如下界面说明成功让redis在后台运行

     

    如果想查看进程里面有没有redis服务,可以用pstree命令查看进程:

    [root@localhost redis]# pstree

     

     后台运行成功以后,用redis-cli客户端连接redis:

    [root@localhost redis]# ./redis-cli 192.168.0.101 6379

    上面代码中IP地址和端口号可以不写,不写的话,默认连接本机redis

     

    查看redis里面有没有数据

    命令:keys *

     

    暂时还没有数据

    来添加一条数据吧!

    命令 : set mykey “tom”

     或者 :set mykey "tom" EX 100 NX

    SET KEY VALUE [EX seconds] [PX milliseconds] [NX|XX]
    
    • EX seconds − 设置指定的到期时间(以秒为单位)。
    • PX milliseconds - 设置指定的到期时间(以毫秒为单位)。
    • NX - 仅在键不存在时设置键。
    • XX - 只有在键已存在时才设置。

     

     

     

    读取一条数据:

    命令: get mykey

     

    到这里,redis就算是安装成了

     

     

     

    注意:这里直接执行Redis-server 启动的Redis服务,是在前台直接运行的(效果如上图),也就是说,执行完该命令后,如果Lunix关闭当前会话,则Redis服务也随即关闭。正常情况下,启动Redis服务需要从后台启动,并且指定启动配置文件。 

    3、后台启动redis服务

    a)首先编辑conf文件,将daemonize属性改为yes(表明需要在后台运行)

    cd bin/
    Vi redis.conf

    b) Start the redis service again and specify the startup service configuration file

    ./redis-server redis.conf (indicates that the configuration file is loaded at startup)

    4. After the server starts successfully, execute redis-cli to start the Redis client and check the port number.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326356520&siteId=291194637