Redis的安装部署及成功启动

#目录

文章目录

      • 1. Redis安装约定
      • 2. 下载Redis安装包
      • 3. 解压并进入安装包中查看重要的文件及目录
      • 4. 正式安装redis
      • 5. 安装完成后查看安装目录
      • 6. 配置环境变量
      • 7. 拷贝安装包目录下的配置文件到安装目录的conf目录下
      • 8. 启动redis服务
      • 9. 再次启动redis服务
      • 10. 检查redis服务是否启动成功
      • 11. 关闭redis的正确方法
      • 12. redis配置

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 root1737022 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 root53 Mar 27 00:04 BUGS -rw-rw-r--1 root root1815 Mar 27 00:04 CONTRIBUTING -rw-rw-r--1 root root1487 Mar 27 00:04 COPYING drwxrwxr-x6 root root4096 Mar 27 00:04 deps -rw-rw-r--1 root root11 Mar 27 00:04 INSTALL -rw-rw-r--1 root root151 Mar 27 00:04 Makefile -rw-rw-r--1 root root4223 Mar 27 00:04 MANIFESTO -rw-rw-r--1 root root20543 Mar 27 00:04 README.md #安装说明 -rw-rw-r--1 root root58766 Mar 27 00:04 redis.conf #redis软件主配置文件 -rwxrwxr-x1 root root271 Mar 27 00:04 runtest -rwxrwxr-x1 root root280 Mar 27 00:04 runtest-cluster -rwxrwxr-x1 root root281 Mar 27 00:04 runtest-sentinel -rw-rw-r--1 root root7606 Mar 27 00:04 sentinel.conf drwxrwxr-x3 root root4096 Mar 27 00:04 src#安装包内存放启动脚本的目录 drwxrwxr-x 10 root root4096 Mar 27 00:04 tests drwxrwxr-x8 root root4096 Mar 27 00:04 utils[root@node1 redis-4.0.9]#cat README.md

Redis的安装部署及成功启动
文章图片

Redis的安装部署及成功启动
文章图片

【Redis的安装部署及成功启动】Redis的安装部署及成功启动
文章图片

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 Jun1 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 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 verboseSentinel 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 root53 Mar 27 00:04 BUGS -rw-rw-r--1 root root1815 Mar 27 00:04 CONTRIBUTING -rw-rw-r--1 root root1487 Mar 27 00:04 COPYING drwxrwxr-x6 root root4096 Jun1 12:03 deps -rw-rw-r--1 root root11 Mar 27 00:04 INSTALL -rw-rw-r--1 root root151 Mar 27 00:04 Makefile -rw-rw-r--1 root root4223 Mar 27 00:04 MANIFESTO -rw-rw-r--1 root root20543 Mar 27 00:04 README.md -rw-rw-r--1 root root58766 Mar 27 00:04 redis.conf#redis软件主配置文件 -rwxrwxr-x1 root root271 Mar 27 00:04 runtest -rwxrwxr-x1 root root280 Mar 27 00:04 runtest-cluster -rwxrwxr-x1 root root281 Mar 27 00:04 runtest-sentinel -rw-rw-r--1 root root7606 Mar 27 00:04 sentinel.conf drwxrwxr-x3 root root4096 Jun1 12:04 src drwxrwxr-x 10 root root4096 Mar 27 00:04 tests drwxrwxr-x8 root root4096 Mar 27 00:04 utils [root@node1 redis-4.0.9]# cp /home/tools/redis-4.0.9/redis.conf/usr/local/redis/conf

8. 启动redis服务
[root@node1 redis]# /usr/local/redis/bin/redis-server/usr/local/redis/conf/redis.conf

Redis的安装部署及成功启动
文章图片

[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

9. 再次启动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 `-._`-._`-.__.-'_.-'_.-' |`-._`-._`-.__.-'_.-'_.-'| |`-._`-.__.-'_.-'| `-._`-._`-.__.-'_.-'_.-' `-._`-.__.-'_.-' `-.__.-'

Redis的安装部署及成功启动
文章图片

#警告: #您的内核中启用了透明的大页面(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 #再次重启redis [root@node1 ~]#/usr/local/redis/bin/redis-server/usr/local/redis/conf/redis.conf

10. 检查redis服务是否启动成功
# 默认的情况下,redis服务的端口号是6379 # redis 服务的端口号在主配置文件/usr/local/redis/conf/redis.conf 中修改 # netstat -lntup|grep redis # ps -ef |grep redis # lsof -i:6379

11. 关闭redis的正确方法
[root@node1 ~]# /usr/local/redis/bin/redis-clishutdown

12. redis配置
除去本机以外,授权其他主机也可以连接此redis服务
先注释掉:bind 127.0.0.1 再将NETWORK下的protected-mode yes修改为protected-mode no

配置redis登录密码
requirepass 密码

配置redis以守护进程方式启动
daemonize no 修改为 daemonize yes

配置问看修改后重启redis服务生效
/usr/local/redis/bin/redis-clishutdown /usr/local/redis/bin/redis-server/usr/local/redis/conf/redis.conf

    推荐阅读