目录
1. Redis安装约定
安装包存放目录:/home/tools
安装目录:/usr/local/redis
2. 下载Redis安装包
Redis官网:http://redis.io
[root@node1 tools]# pwd
/home/tools
[root@node1 tools]# ll
total 213384
-rw-r--r-- 1 root root 1737022 May 29 15:30 redis-4.0.9.tar.gz
3. 解压并进入安装包中查看重要的文件及目录
[root@node1 tools]# cd redis-4.0.9
[root@node1 redis-4.0.9]# ll
total 304
-rw-rw-r-- 1 root root 157632 Mar 27 00:04 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 Mar 27 00:04 BUGS
-rw-rw-r-- 1 root root 1815 Mar 27 00:04 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Mar 27 00:04 COPYING
drwxrwxr-x 6 root root 4096 Mar 27 00:04 deps
-rw-rw-r-- 1 root root 11 Mar 27 00:04 INSTALL
-rw-rw-r-- 1 root root 151 Mar 27 00:04 Makefile
-rw-rw-r-- 1 root root 4223 Mar 27 00:04 MANIFESTO
-rw-rw-r-- 1 root root 20543 Mar 27 00:04 README.md #安装说明
-rw-rw-r-- 1 root root 58766 Mar 27 00:04 redis.conf #redis软件主配置文件
-rwxrwxr-x 1 root root 271 Mar 27 00:04 runtest
-rwxrwxr-x 1 root root 280 Mar 27 00:04 runtest-cluster
-rwxrwxr-x 1 root root 281 Mar 27 00:04 runtest-sentinel
-rw-rw-r-- 1 root root 7606 Mar 27 00:04 sentinel.conf
drwxrwxr-x 3 root root 4096 Mar 27 00:04 src #安装包内存放启动脚本的目录
drwxrwxr-x 10 root root 4096 Mar 27 00:04 tests
drwxrwxr-x 8 root root 4096 Mar 27 00:04 utils
[root@node1 redis-4.0.9]#cat README.md
4. 正式安装redis
[root@node1 redis-4.0.9]# make MALLOC=jemalloc
[root@node1 redis-4.0.9]# make PREFIX=/usr/local/redis install
#redis比较特殊,在这一步才指定安装路径
5. 安装完成后查看安装目录
[root@node1 redis]# cd /usr/local/redis
[root@node1 redis]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 1 12:04 bin
[root@node1 redis]# tree /usr/local/redis/bin/
./bin/
├── redis-benchmark #redis性能测试工具启动,测试redis在你的系统及你的配置下的读写性能
├── redis-check-aof #更新日志检查
├── redis-check-rdb #本地数据库检查
├── redis-cli redis #命令行操作工具(即客户端)
├── redis-sentinel -> redis-server
└── redis-server #redis服务器的daemon启动程序
6. 配置环境变量
[root@node1 ~]#echo 'export PATH=$PATH:/usr/local/redis/bin' >> /etc/profile
[root@node1 ~]# source /etc/profile
[root@node1 ~]# echo $PATH
[root@node1 ~]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
Examples: ###redis服务器的daemon程序如何启动
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf –sentinel
7. 拷贝安装包目录下的配置文件到安装目录的conf目录下
[root@node1 redis-4.0.9]# mkdir -p /usr/local/redis/conf
[root@node1 redis-4.0.9]# pwd
/home/tools/redis-4.0.9
[root@node1 redis-4.0.9]# ll
total 304
-rw-rw-r-- 1 root root 157632 Mar 27 00:04 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 Mar 27 00:04 BUGS
-rw-rw-r-- 1 root root 1815 Mar 27 00:04 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Mar 27 00:04 COPYING
drwxrwxr-x 6 root root 4096 Jun 1 12:03 deps
-rw-rw-r-- 1 root root 11 Mar 27 00:04 INSTALL
-rw-rw-r-- 1 root root 151 Mar 27 00:04 Makefile
-rw-rw-r-- 1 root root 4223 Mar 27 00:04 MANIFESTO
-rw-rw-r-- 1 root root 20543 Mar 27 00:04 README.md
-rw-rw-r-- 1 root root 58766 Mar 27 00:04 redis.conf #redis软件主配置文件
-rwxrwxr-x 1 root root 271 Mar 27 00:04 runtest
-rwxrwxr-x 1 root root 280 Mar 27 00:04 runtest-cluster
-rwxrwxr-x 1 root root 281 Mar 27 00:04 runtest-sentinel
-rw-rw-r-- 1 root root 7606 Mar 27 00:04 sentinel.conf
drwxrwxr-x 3 root root 4096 Jun 1 12:04 src
drwxrwxr-x 10 root root 4096 Mar 27 00:04 tests
drwxrwxr-x 8 root root 4096 Mar 27 00:04 utils
[root@node1 redis-4.0.9]# cp /home/tools/redis-4.0.9/redis.conf /usr/local/redis/conf
7. 启动redis服务
[root@node1 redis]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
[root@node1 redis]# echo 'vm.overcommit_memory=1' >>/etc/sysctl.conf
[root@node1 redis]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.overcommit_memory = 1
8. 再次启动redis服务
[root@node1 redis]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
9543:C 01 Jun 12:31:07.484 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9543:C 01 Jun 12:31:07.484 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=9543, just started
9543:C 01 Jun 12:31:07.484 # Configuration loaded
9543:M 01 Jun 12:31:07.485 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 9543
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
#警告:
#您的内核中启用了透明的大页面(THP)支持,
#这将创建与ReDIS的延迟和内存使用问题,
#若要修复此问题,请运行命令“EngEng/mS/mL/mM/ExpListNo.HugPoIP/启用”为root,
#并将其添加到您的/etc/rc.local,以便在重新启动后保留设置。在禁用THP之后,必须重新启动redis。
[root@node1 ~]# echo 511 > /proc/sys/net/core/somaxconn
[root@node1 ~]#echo never > /sys/kernel/mm/transparent_hugepage/enabled
9. 检查redis服务是否启动成功
# 默认的情况下,redis服务的端口号是6379
# redis 服务的端口号在主配置文件/usr/local/redis/conf/redis.conf 中修改
# netstat -lntup|grep redis
# ps -ef |grep redis
# lsof -i:6379
10. 关闭redis的正确方法
[root@node1 ~]# /usr/local/redis/bin/redis-cli shutdown