Part 1 . redis在Linux上的安装
安装包下载地址:点击这里
1)安装redis编译的c环境,yum install gcc-c++
2)将redis-4.0.9.tar.gz上传到Linux系统中
3)解压到/usr/local下 tar -xvf redis-4.0.9.tar.gz -C /usr/local
4)进入redis-4.0.9目录 使用make命令编译redis
5)在redis-4.0.9目录中 使用make PREFIX=/usr/local/redis install命令安装 redis到/usr/local/redis中
6)拷贝redis-4.0.9中的redis.conf到安装目录redis中
上述步骤完成后,redis-4.0.9目录基本无其他作用了,可以无视.
reids/bin目录情况如下:
这里我们只会用到redis-server 服务端 /redis-cli 客户端
Part 2 . redis的运行
下面所有命令执行路径都在redis/bin目录下
1.前端模式启动(不推荐)
1)在bin目录下执行 ./redis-server,然后当前控制台无法进行任何操作,关闭ctrl+c
2)再开一个控制台,在bin目录下执行 ./redis-cli ,即可以使用redis
2.后提模式启动
1)修改redis.conf配置文件
2)启动服务端,执行命令:./redis-server redis.conf
3)启动客户端,执行命令:./redis-cli
4)redis关闭
a.强制关闭(不推荐)
找到redis相关进程: ps -ef | grep redis
关闭进程:kill -9 [pid码,根据上面命令查询出来的结果]
b.正常关闭
退出客户端,然后执行 : ./redis-cli shutdown
Part 3 . redis运行时出现的警告
警告:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解决方法:
echo “net.core.somaxconn = 551” > /etc/sysctl.conf
警告:
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.
解决方法:
echo “vm.overcommit_memory=1” >> /etc/sysctl.conf
警告:
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.
解决方法:
[root@centos224]# vi /etc/rc.local
插入以下指令
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
警告:
Warning: no config file specified, using the default config.
In order to specify a config file use ‘redis-server /path/to/redis.conf’
解决方法:
运行时需指定相应配置文件,即步骤6中copy下来的文件redis.conf
./redis-server [redis.conf 文件路径]