Ⅰ.通过 SecureCRT 连接到 CentOS7 服务器;
Ⅱ.进入到目录 /usr/local/ 中:
cd /usr/local/
Ⅲ.创建目录 tools:
mkdir -p tools
Ⅳ.进入到目录 /usr/local/tools 中:
cd tools/
Ⅴ.网络下载
Ⅵ.解压缩文件:
tar -zxvf
redis-4.0.9.tar.gz
Ⅶ.返回到上一级并创建 /usr/local/redis 目录:
mkdir -p redis
Ⅷ.转移目录
mv /usr/local/tools/redis-4.0.9 /usr/local/redis/
Ⅸ.编译
cd /usr/local/redis/redis-4.0.9
make
make完后 redis-4.0.9/src/目录下会出现编译后的redis服务程序redis-server,还有用于测试的客户端程序redis-cli,两个程序位于安装目录 src 目录下
Ⅹ.启动redis程序
$ cd src$ ./redis-server
默认端口:6379
===============
如果启动前不对linux内核做任何更改,那么redis启动会报出警告,共三个:如下图所示
第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
意思是:TCP backlog设置值,511没有成功,因为 /proc/sys/net/core/somaxconn这个设置的是更小的128.
临时解决方法:(即下次启动还需要修改此值)
echo 511 > /proc/sys/net/core/somaxconn
永久解决方法:(即以后启动还需要修改此值)
将‘/proc/sys/net/core/somaxconn’写入/etc/rc.local文件中。
baklog参数实际控制的是已经3次握手成功的还在accept queue的大小。
第二个警告: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.
意思是:overcommit_memory参数设置为0!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。
临时解决方法:echo "vm.overcommit_memory=1" > /etc/sysctl.conf
永久解决方法:将其写入/etc/sysctl.conf文件中。
然后sysctl -p 使配置文件生效。
第三个警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.
意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。
临时解决方法:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
永久解决方法:
将‘/sys/kernel/mm/transparent_hugepage/enabled’写入/etc/rc.local文件中。
[root@centoszang src]# ./redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
[root@centoszang src]# ./redis-server /etc/redis.conf
[root@centoszang src]# ./redis-cli
127.0.0.1:6379>
找到redis.conf 并修改 daemonize no(第136行) 为
daemonize yes
,这样就可以默认启动就后台运行
开启客户端要确保服务端启动
redis-server /usr/local/redis/redis-4.0.9/src/redis.conf
==============================================================
设置开启服务器自启动:
在
/etc/rc.d/rc.local 文件中添加:
/usr/local/redis/redis-4.0.9/src/redis-server /usr/local/redis/redis-4.0.9/redis.conf
或者直接用命令执行:
echo "/usr/local/redis/redis-4.0.9/src/redis-server /usr/local/redis/redis-4.0.9/redis.conf
"
>
/etc/rc.d/rc.local
【完】