CentOS7安装redis

一、安装gcc

CentOS7自带gcc版本了,所以不需要安装gcc了

[root@VM_103_117_centos bin]# yum install gcc-c++
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* webtatic: uk.repo.webtatic.com
Package gcc-c++-4.8.5-16.el7.x86_64 already installed and latest version
Nothing to do

二、下载redis的源文件

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

三、解压文件并进入redis的解压目录

tar zxvf redis-4.0.2.tar.gz

四、使用make命令编译

[root@VM_103_117_centos redis-4.0.2]# make

五、进入解压的src目录下

[root@VM_103_117_centos src]# make test

通过的话你就可以安装啦,但是我这里报了一个错:

Executing test client: NOREPLICAS Not enough good slaves to write..

百度后修改文件tests/integration/replication-2.tcl,将after 1000改为after 10000以延长等待时间。问题解决。再次make test提示成功了。

o/ All tests passed without errors!

六、安装redis

[root@VM_103_117_centos src]# make PREFIX=/usr/local/redis install  

这里可以选择将redis安装在其他目录,我这里是安装在了/usr/local/目录下

[root@VM_103_117_centos redis-4.0.2]# cp redis.conf /usr/local/redis

七、启动redis

[root@VM_103_117_centos redis-4.0.2]# cd /usr/local/redis/bin

[root@VM_103_117_centos bin]# ./redis-server

八、查看redis是否启动成功

[root@VM_103_117_centos bin]#ps -ef | grep -i redis

root 4432 6033 0 14:43 pts/0 00:00:00 grep --color=auto -i redis
root 11559 1 0 Sep20 ? 00:18:53 ./bin/redis-server *:6379

表示已经成功启动

九、简单的使用

//首先链接客户端 [root@VM_103_117_centos bin]# ./redis-cli

//检查网络是否可以 127.0.0.1:6379> ping PONG

//设置一个键值对 127.0.0.1:6379> set name cheny OK

//获取刚刚设置的键值对 127.0.0.1:6379> get name "cheny"

//查看所有的键 127.0.0.1:6379> keys * 1) "name"

//删除name这个键

127.0.0.1:6379> del name (integer) 1

127.0.0.1:6379> keys * (empty list or set)

127.0.0.1:6379>

附录:更多的关于 /usr/local/redis/etc/redis.conf 的配置信息

1、daemonize 如果需要在后台运行,把该项改为yes

2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid

3、bind 绑定ip,设置后只接受来自该ip的请求

4、port 监听端口,默认是6379

5、loglevel 分为4个等级:debug verbose notice warning

6、logfile 用于配置log文件地址

7、databases 设置数据库个数,默认使用的数据库为0

8、save 设置redis进行数据库镜像的频率。

9、rdbcompression 在进行镜像备份时,是否进行压缩

10、dbfilename 镜像备份文件的文件名

11、Dir 数据库镜像备份的文件放置路径

12、Slaveof 设置数据库为其他数据库的从数据库

13、Masterauth 主数据库连接需要的密码验证

14、Requriepass 设置 登陆时需要使用密码

15、Maxclients 限制同时使用的客户数量

16、Maxmemory 设置redis能够使用的最大内存

17、Appendonly 开启append only模式

18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)

19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)

20、vm-swap-file 设置虚拟内存的交换文件路径

21、vm-max-memory 设置redis使用的最大物理内存大小

22、vm-page-size 设置虚拟内存的页大小

23、vm-pages 设置交换文件的总的page数量

24、vm-max-threads 设置VM IO同时使用的线程数量

25、Glueoutputbuf 把小的输出缓存存放在一起

26、hash-max-zipmap-entries 设置hash的临界值

27、Activerehashing 重新hash

原文地址:https://www.cnblogs.com/liuboswu/p/7716693.html