源码编译装redis
1、下载包
[root@ZZQVM1 ~]# cd /usr/src
[root@ZZQVM1src]#wget http://download.redis.io/releases/redis-5.0.9.tar.gz?_ga=2.234283038.1022079843.1602419660-2097223004.1602165290
[root@ZZQVM1 src]# mv redis-5.0.9.tar.gz\?_ga\=2.234283038.1022079843.1602419660-2097223004.1602165290 redis-5.0.9.tar.gz
2、解压
[root@ZZQVM1 src]# tar xf redis-stable.tar.gz
3、安装(无需编译-已经有Makefile文件)
[root@ZZQVM1 src]# cd redis-5.0.9
[root@ZZQVM1 redis-5.0.9]# ls
00-RELEASENOTES deps README.md runtest-moduleapi tests
BUGS INSTALL redis.conf runtest-sentinel utils
CONTRIBUTING Makefile runtest sentinel.conf
COPYING MANIFESTO runtest-cluster src
(1) 更改文件安装目录
[root@ZZQVM1 redis-5.0.9]# vim src/Makefile
(2)修改以下加粗内容:
PREFIX?=/usr/local/redis
(3)安装
[root@ZZQVM1 redis-5.0.9]# make && make install
[root@ZZQVM1 redis-5.0.9]# cp redis.conf /usr/local/redis/redi.conf
4、完成安装启动:
[root@ZZQVM1 redis-5.0.9]# /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 14681
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
14681:M 10 Oct 2020 13:37:49.221 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14681:M 10 Oct 2020 13:37:49.221 # Server initialized
14681:M 10 Oct 2020 13:37:49.221 # 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.
14681:M 10 Oct 2020 13:37:49.221 # 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.
# 默认前台运行 Ctrl+D退出修改配置文件
[root@ZZQVM1 redis-5.0.9]# vim /usr/local/redis/redis.conf
# 修改下面内容,进入后台运行
daemonize yes
# 先杀掉进程再启动:
[root@ZZQVM1 redis-5.0.9]# pkill redis-server
[root@ZZQVM1 redis-5.0.9]# /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
(1)让redis自己管理内存
[root@ZZQVM1 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
(2)启动麻烦:进去源码安装目录,初始化启动脚本
[root@ZZQVM1 redis-5.0.9]# ls utils/
build-static-symbols.tcl hashtable redis_init_script.tpl
cluster_fail_time.tcl hyperloglog redis-sha1.rb
corrupt_rdb.c install_server.sh releasetools
create-cluster lru speed-regression.tcl
generate-command-help.rb redis-copy.rb whatisdoing.sh
graphs redis_init_script
[root@ZZQVM1 redis-5.0.9]# ./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
#用6379.conf为以后做多实例做准备(以后可能配多个redis),按错Ctrl+Backspace
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis/6379.conf
# 选择redis的日志文件(自己指定名字自己定)
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/6379.log
# 指定redis的数据目录(内存的数据库-可以做持久化)
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/6379
# 选择可执行文件的目录
Please select the redis executable path [] /usr/local/redis/bin/redis-server
Selected config:
Port : 6379
Config file : /usr/local/redis/6379.conf
Log file : /usr/local/redis/6379.log
Data dir : /usr/local/redis/6379
Executable : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
/var/run/redis_6379.pid exists, process is already running or crashed
Installation successful
# 先杀掉进程再启动:
[root@ZZQVM1 redis-5.0.9]# pkill redis-server
[root@ZZQVM1 redis-5.0.9]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
# 用脚本启动
[root@ZZQVM1 redis-5.0.9]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@ZZQVM1 redis-5.0.9]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1449/mysqld
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 14894/redis-server
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 858/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1139/sshd
tcp6 0 0 :::111 :::* LISTEN 858/rpcbind
tcp6 0 0 :::22 :::* LISTEN 1139/sshd