1.上传并解压
redis-4.0.2.tar.gz
2.安装C语言编译环境
[建议先拍快照]
yum install -y gcc-c++
如果不能联网,可以使用下面步骤安装:
1.上传gcc-c++.rpm.packages目录到Linux系统
2.拍摄快照
3.进入rpm包所在目录
4.执行安装 rpm -Uvh *.rpm --nodeps --force
5.验证安装效果 gcc -v
3.修改安装位置
vim redis解压目录/src/Makefile
PREFIX?=/usr/local/redis
就Redis自身而言是不需要修改的,这里修改的目的是让Redis的运行程序不要和其他文件混杂在一起。
4.编译安装
编译:进入Redis解压目录执行make命令
[建议先拍快照]
安装:make install
5.启动Redis服务器
①默认启动
[root@rich ~]# /usr/local/redis/bin/redis-server
7239:C 07 Oct 18:59:12.144 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7239:C 07 Oct 18:59:12.144 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=7239, just started
7239:C 07 Oct 18:59:12.144 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/redis/bin/redis-server /path/to/redis.conf
7239:M 07 Oct 18:59:12.145 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7239
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7239:M 07 Oct 18:59:12.148 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7239:M 07 Oct 18:59:12.148 # Server initialized
7239:M 07 Oct 18:59:12.148 # 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.
7239:M 07 Oct 18:59:12.148 # 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.
7239:M 07 Oct 18:59:12.148 * Ready to accept connections
停止Redis服务器可以在另外一个命令行窗口执行下面命令:
/usr/local/redis/bin/redis-cli shutdown
7239:M 07 Oct 19:00:53.208 # User requested shutdown...
7239:M 07 Oct 19:00:53.208 * Saving the final RDB snapshot before exiting.
7239:M 07 Oct 19:00:53.214 * DB saved on disk
7239:M 07 Oct 19:00:53.214 # Redis is now ready to exit, bye bye...
②定制配置项启动
[1]准备配置文件
cp redis解压目录/redis.conf /usr/local/redis/
[2]修改配置项
配置项名称 | 作用 | 取值 |
---|---|---|
daemonize | 控制是否以守护进程形式运行Redis服务器 | yes |
logfile | 指定日志文件位置 | "/var/logs/redis.log" |
dir | Redis工作目录 | /usr/local/redis |
注意:/var/logs目录需要我们提前创建好
[3]让Redis根据指定的配置文件启动
格式
redis-server文件路径 redis.conf文件路径
举例
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
6.客户端登录
/usr/local/redis/bin/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit