前言:

环境介绍:

CentOS 7.5
Redis 5.0.0
gcc

下载:

http://download.redis.io/releases/

安装redis:

[root@localhost ~]#yum -y install gcc[root@localhost ~]# mkdir redis[root@localhost redis]# wget http://download.redis.io/releases/redis-5.0.0.tar.gz[root@localhost ~]# cd redis/[root@localhost redis]# tar -xvf redis-5.0.0.tar.gz
redis-5.0.0/
redis-5.0.0/.gitignore
redis-5.0.0/00-RELEASENOTES
...
[root@localhost redis]# ls
redis-5.0.0  redis-5.0.0.tar.gz[root@localhost redis]# cd redis-5.0.0[root@localhost redis-5.0.0]# make && make install
...
make[1]: 离开目录“/root/redis/redis-5.0.0/src”
make[1]: 进入目录“/root/redis/redis-5.0.0/src”Hint: It's a good idea to run 'make test' ;)INSTALL installINSTALL installINSTALL installINSTALL installINSTALL install
make[1]: 离开目录“/root/redis/redis-5.0.0/src”

初始化配置:

[root@localhost redis-5.0.0]# ./utils/install_server.sh  //一路回车
Welcome to the redis service installer
This script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/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!
Starting Redis server...
Installation successful!

管理服务:

[root@localhost redis-5.0.0]# /etc/init.d/redis_6379 stop  //停止服务[root@localhost redis-5.0.0]# /etc/init.d/redis_6379 start  //启动服务[root@localhost redis-5.0.0]# /etc/init.d/redis_6379 enable //开机自启动[root@localhost redis-5.0.0]# ps -C redis-server   //查看进程PID TTY          TIME CMD14540 ?        00:00:00 redis-server[root@localhost redis-5.0.0]# ss -antulp | grep :6379   //查看端口
tcp    LISTEN     0      128    127.0.0.1:6379                  *:*                   users:(("redis-server",pid=14540,fd=6))

连接服务:

[root@localhost redis-5.0.0]# redis-cli
127.0.0.1:6379> set name bob    //存储数据,变量名为name,值为bob
OK
127.0.0.1:6379> get name    //查看变量name的值
"bob"
127.0.0.1:6379> keys *       //查询已有的变量
1) "name"
127.0.0.1:6379> exit

常用命令:

- set 变量名 变量值                 //存储1个变量值
- mset 变量名 变量值 变量名 变量值...      //存储多个变量值
- get 变量名                   //查询1个变量的值
- mget 变量名                 //查询多个变量的值
- select 数据库编号0-15(默认只有16个库)      //切换库
- keys *                  //显示所有的变量名
- keys ?                  //显示只有一个字符的变量名
- keys a?                //显示以a开头的2个字符的变量名
- exists 变量名            //测试某个变量是否存在
- ttl 变量名               //查看变量生存时间(-1为永久生存)
- type 变量名               //查看变量的类型
- move 变量名 数据库编号   //移动某变量到指定库中
- expire 变量名 时间       //设置变量的有效时间
- del 变量名              //删除指定的变量
- flushall                //删除内存里所有的变量
- flushdb               //删除所在的库中的所有变量
- save                 //保存所有变量到硬盘中
- shutdown            //停止redis服务

常用配置项:

[root@ku1-50 ~]# vim /etc/redis/6379.conf
93  port 6379                //端口
70  bind 127.0.0.1           //IP地址
137 daemonize yes            //守护进程方式运行
187 databases 16             //数据库个数
172 logfile /var/log/redis_6379.log     //日志文件
533 # maxclients 10000           //并发连接数量
264 dir /var/lib/redis/6379      //数据库目录

内存管理:

 默认使用noeviction清除策略。

优化设置:

[root@localhost redis-5.0.0]# vim /etc/redis/6379.conf
560 # maxmemory <bytes>           //最大内存
598 # maxmemory-policy noeviction    //默认使用的内存清除策略为noeviction
609 # maxmemory-samples 5    //默认选取变量(key)模板的个数(针对lru、ttl策略)为5个

连接配置:

[root@localhost redis-5.0.0]# vim /etc/redis/6379.conf
70 bind 192.168.2.159         //IP地址
93 port 6379                  //端口
508 requirepass 123456        //密码[root@localhost redis-5.0.0]# /etc/init.d/redis_6379 stop[root@localhost redis-5.0.0]# /etc/init.d/redis_6379 start[root@localhost redis-5.0.0]# redis-cli    //未携带修改的参数
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
注意:如果在配置文件中修改了密码、端口、IP地址,那么在连接redis服务的时候必须带上更改的参数才可以连接上服务。--明文密码连接
[root@localhost redis-5.0.0]# redis-cli -h 192.168.2.159 -a 123456       //密码明文连接
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.2.159:6379> keys *
1) "name"
192.168.2.159:6379> exit--交互式密码连接
[root@localhost redis-5.0.0]# redis-cli -h 192.168.2.159
192.168.2.159:6379> keys *         //不输入密码无法进行操作
(error) NOAUTH Authentication required.
192.168.2.159:6379> auth 123456
OK
192.168.2.159:6379> keys *
1) "name"
192.168.2.159:6379> exit

注意:

在修改了以上三种参数(密码、端口、IP地址)中的任意一种后,都无法再使用脚本来停止服务(启动服务不影响),需要对脚本进行修改。

[root@localhost ~]# /etc/init.d/redis_6379 stop
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...    //已经使用脚本无法停止服务了[root@localhost ~]# ss -antulp | grep :6379
tcp    LISTEN     0      128    192.168.2.159:6379                  *:*                   users:(("redis-server",pid=14558,fd=6))
[root@localhost ~]# redis-cli -h 192.168.2.159 -a 123456 shutdown      //只能这样停止redis服务[root@localhost ~]# ss -antulp | grep :6379

修改停止服务脚本

[root@localhost ~]# vim /etc/init.d/redis_6379
43  $CLIEXEC -p $REDISPORT shutdown↓↓↓↓根据更改的参数将以上配置修改为↓↓↓↓
43 $CLIEXEC -h 192.168.2.159 -p 6379 -a 123456 shutdown[root@localhost ~]# /etc/init.d/redis_6379 stop  //使用脚本停止服务
Stopping ...
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Redis stopped[root@localhost ~]# ss -antulp | grep :6379   //停止服务成功[root@localhost ~]# /etc/init.d/redis_6379 start
Starting Redis server...[root@localhost ~]# ss -antulp | grep :6379
tcp    LISTEN     0      128    192.168.2.159:6379                  *:*                   users:(("redis-server",pid=14649,fd=6))

参考链接 :

企业实战(3) Redis服务部署和配置详解 :https://mp.weixin.qq.com/s/EFWwX4PQ_DlGAlQTSyQqSA

redis最全命令手册(强推) :https://mp.weixin.qq.com/s/ug0ZSjLjNKXKr4S7XKzClQ

1 企业实战(3) Redis服务部署和配置详解 (资源)相关推荐

  1. redis服务部署及配置详解

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集合和有序集合.支持在服务器端计算集合的并,交和补集(diffe ...

  2. Rsync 服务部署与参数详解

    Rsync 简介 rsync 是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.Rsync软件适用于unix/linux/windows等多种操作系统平台. 传统的 ...

  3. asp.net 获取计算机配置_PBI Report Server 部署与配置详解

    12月18日追加:欢迎加入知乎-微软BI技术圈,一起讨论.分享包括PowerBI在内的一切BI话题! [前述]关于Power BI 报表服务器的安装与配置,国内外的教程有很多,但较为全面的介绍却少之又 ...

  4. smb服务介绍及配置详解

    理论部分 samba服务简介 smb服务是微软的网络通讯协议,后来应用到了linux系统上.这款文件共享协议可以使得Linux与windows系统之间进行文件共享与打印功能,由于NFS可以完成linu ...

  5. Kafka 环境部署与配置详解

    2019独角兽企业重金招聘Python工程师标准>>> 什么是Kafka Kafka是一种高吞吐量 的分布式发布订阅消息系统,有如下特性:1>.通过O(1)的磁盘数据结构提供消 ...

  6. haproxy安装部署以及配置详解

    haproxy安装部署 一. Haproxy简介 haproxy提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. ha ...

  7. Twemproxy的部署和配置详解

    Twemproxy 概述 Twemproxy(又称为nutcracker)是一个轻量级的Redis和Memcached代理,主要用来减少对后端缓存服务器的连接数.Twemproxy是由Twitter开 ...

  8. linux下nginx部署以及配置详解

    1.下载源码包解压编译 启动多个,请看:在linux系统下安装两个nginx以及启动 查看nginx包路径:http://nginx.org/download/,两种下载方式: 1.在官网下载使用Xf ...

  9. linux nginx权限配置文件,linux下nginx部署以及配置详解

    1.下载源码包解压编译 1.在官网下载使用Xftp上传到linux上(不推荐使用) 2.(推荐)在版本上选好,直接命令下载,如下:(下载nginx-1.16.1.tar.gz版本)建议到home目录执 ...

最新文章

  1. java服务端监听_Java客户端正在监听WebSphere MQ服务器?
  2. DotNet中几种常用的加密算法
  3. leetcode算法题--字符串的排列
  4. mysql索引的方法_mysql查看索引方法
  5. 攻防世界base除4_CCTV5周末看点:周六!女足世界杯1/4决赛连战三场;周日!中超15轮国安碰鲁能...
  6. 趣说游戏AI开发:曼哈顿街角的A*算法 1
  7. 日语学习-多邻国-时间
  8. Kinect for Windows Samples
  9. 无线通信设备安装工程概预算编制_祁东设备安装工程施工承包-设计安装_天霖工程...
  10. 公众号获取openid
  11. win7 64位 纯净版旗舰版202104
  12. 试分析培正强智教务系统选课卡顿的原因
  13. 浅谈精准提取日志中的URL
  14. 【程序人生】程序员薪酬对比研究以及晋升详情2022(持续更新)
  15. 广告投放ROI如何计算?实现广告效果最大化
  16. dubbo注册服务IP解析异常及IP解析源码分析
  17. curl: (52) Empty reply from server错误
  18. Redis 实战篇:通过 Geo 类型实现附近的人邂逅女神
  19. 766.托普利茨矩阵
  20. influxdb学习记录

热门文章

  1. 基于块分割及CNN的文档矫正与光照消除方法 (有源码和数据)
  2. VGG16 、VGG19 、ResNet50 、Inception V3 、Xception介绍
  3. 对GCN,Transformer, XLNet, ALBERT, CRF等技术仍然一知半解?再不学习就OUT了!
  4. linux内核nasm,在x86汇编代码,NASM,Linux中操作字符串
  5. java基础类与对象_Java基础---类与对象
  6. 输出高电平程序c语言,51用c语言怎么编程检测US-100超声波测距模块echo/rx引脚输出高电平时间长度,,谁能给我个模板...
  7. python列表快速排序_python 实现快速排序
  8. markdown 提示文本_【文本编辑01】MarkdownPad安装及基本配置
  9. 使用cronolog-1.6.2按日期截取Tomcat日志
  10. docker命令易错点整理