longxd

导航

 

安装Redis

 

1、首先上官网下载Redis 压缩包,地址:http://redis.io/download

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

 

 

2、执行解压操作

tar -zxvf redis-2.6.16.tar.gz

 

3、安装gccgcc-c++yum install gccyum install gcc-c++

执行make Redis解压后文件进行编译(make distclean清空上次编译失败残留文件)

 

4编译完成之后,可以看到解压文件redis-2.6.16 中会有对应的srcconf等文件夹

 

 

5进入src文件夹,执行make install进行Redis安装

 

安装完成:

 

 

6、为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中

使用mkdir etcmkdir bin创建文件夹。

 

 

 

复制文件到指定目录:

mv /usr/local/redis//redis-2.6.16/redis.conf /usr/local/redis/redis-2.6.16/etc

cd /usr/local/redis/redis-2.6.16/src

mv mkreleasdhdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/redis-2.6.16/bin

 

 

7、执行Redis-server 命令,启动Redis 服务。

 

 

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

 

8、配置后台启动redis服务,编辑conf文件,将daemonize属性改为yes(表明需要在后台运行)。

Cd /usr/local/redis/redis-2.6.16/etc

Vi redis.conf

 

再次启动redis服务,并指定启动服务配置文件.

[root@ip-192-168-1-111 etc]# vi redis.conf

[root@ip-192-168-1-111 etc]# redis-server /usr/local/redis/redis-2.6.16/etc/redis.conf

 

 

服务端启动成功后,执行redis-cli启动Redis 客户端,查看端口号以及验证redis

[root@ip-192-168-1-111 etc]# redis-cli

redis 127.0.0.1:6379>

redis 127.0.0.1:6379>

redis 127.0.0.1:6379> set a apple

OK

redis 127.0.0.1:6379> get a

"apple"

redis 127.0.0.1:6379> exit

 

 

需要永久配置密码的话就去redis.conf的配置文件中找到requirepass这个参数,如下配置:

修改redis.conf配置文件  

# requirepass foobared

requirepass 123   指定密码123

 

9,避免重启丢失数据。

编辑/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效

 

使用BGSAVE保存数据到磁盘

redis 127.0.0.1:6379> BGSAVE

Background saving started

posted on 2019-04-18 10:56  longxd  阅读(86)  评论(0编辑  收藏  举报