redis是一种内存型的NoSQL数据库,优点是快,常用来做缓存用 
redis存储数据的方法是以key-value的形式 
value类型支持字符串,列表,哈希等多种类型

环境 : CnetOS7   192.168.94.11

关闭SElinux和防火墙

安装Redis

[root@redis01 ~]# yum -y install wget gcc gcc-c++ make tar openssl openssl-devel cmake
[root@redis01 ~]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz
[root@redis01 ~]# tar xf redis-4.0..tar.gz -C /usr/local/src/
[root@redis01 ~]# cd /usr/local/src/redis-4.0./
[root@redis01 redis-4.0.]# make & make test
[root@redis01 redis-4.0.]# make PREFIX=/usr/local/redis install
[root@redis01 redis]# cd /usr/local/redis/
[root@redis01 redis]# ls
bin
[root@redis01 redis]# mkdir /usr/local/redis/conf
[root@redis01 redis]# cp /usr/local/src/redis-4.0./redis.conf /usr/local/redis/conf/
[root@redis01 redis]# cp /usr/local/src/redis-4.0./sentinel.conf /usr/local/redis/conf/
[root@redis01 redis]# ln -s /usr/local/redis/bin/* /usr/local/bin/
[root@redis01 redis]# redis-server --version
Redis server v=4.0.1 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=d789e4152c8567db

简化redis配置文件,创建redis数据目录

[root@redis01 redis]# grep -Ev '^#|^$' conf/redis.conf.bak > conf/redis.conf
[root@redis01 redis]# mkdir /data/redis -p

修改redis配置文件

修改以下参数
[root@redis01 redis]# vim conf/redis.conf bind 0.0.0.0 #监听地址
port #监听端口
tcp-backlog #tcp连接数
daemonize yes #是否后台启动
pidfile /data/redis/redis.pid #pid存放目录
logfile "/data/redis/redis.log" #日志存放目录
dir /data/redis/ #工作目录

redis服务启动和关闭

启动redis服务
[root@redis01 redis]# redis-server /usr/local/redis/conf/redis.conf
[root@redis01 redis]# netstat -antup|grep redis
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server
连接redis服务
[root@redis01 redis]# redis-cli -h 127.0.0.1
127.0.0.1:> quit
关闭redis服务
[root@redis01 redis]# redis-cli -h 127.0.0.1 shutdown
[root@redis01 redis]# netstat -antup|grep redis

redis系统参数优化

启动redis之后产看redis日志
[root@redis01 redis]# cat /data/redis/redis.log
:C Oct ::46.095 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Oct ::46.095 # Redis version=4.0., bits=, commit=, modified=, pid=, just started
:C Oct ::46.095 # Configuration loaded
:M Oct ::46.097 * Increased maximum number of open files to (it was originally set to ).  # 系统文件描述符设置为1024,太小,最好设置为10032
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 54109
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Oct ::46.099 # WARNING: The TCP backlog setting of cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of .  
# TCP的值为128太小了
:M Oct ::46.100 # Server initialized
:M Oct ::46.100 # WARNING overcommit_memory is set to ! 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.
# overcommit_memory=0为不允许超额抢占内存,但是,rdb保存可能会失败。建议将vm.overcommit_memory = 1进行修改 :M Oct ::46.100 # 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.
# 你的内核中启用了巨大内存页的支持,这将与redis的延迟内存使用冲突 :M Oct ::46.100 * Ready to accept connections

下面来逐个调整

调整系统文件描述符
[root@redis01 redis]# echo "* - nofile 10240" >> /etc/security/limits.conf
[root@redis01 redis]# ulimit -n [root@redis01 redis]# su -l # 重新登录 , 使配置生效
上一次登录:一 10月 :: CST 2018从 192.168..1pts/ 上
[root@redis01 ~]# ulimit -n 调整TCP连接数
[root@redis01 ~]# sysctl -a | grep soma
net.core.somaxconn =
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.ens33.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
[root@redis01 ~]# echo "net.core.somaxconn = 10240" >> /etc/sysctl.conf
[root@redis01 ~]# sysctl -p
net.core.somaxconn =
调整系统内存分配策略
[root@redis01 ~]# echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
[root@redis01 ~]# sysctl -p
net.core.somaxconn =
vm.overcommit_memory =
[root@redis01 ~]# sysctl -a | grep commit
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.ens33.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.nr_overcommit_hugepages =
vm.overcommit_kbytes =
vm.overcommit_memory = # 修改成功
vm.overcommit_ratio =
关闭系统内核的巨大内存页支持
[root@redis01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@redis01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@redis01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@redis01 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
# 添加到rc.local
[root@redis01 ~]# echo -e 'echo never > /sys/kernel/mm/transparent_hugepage/enabled\necho never > /sys/kernel/mm/transparent_hugepage/defrag'>> /etc/rc.local
[root@redis01 ~]# tail - /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

重启redis-server

[root@redis01 ~]# redis-cli -h 127.0.0.1 shutdown    # 关闭redis服务
[root@redis01 ~]# > /data/redis/redis.log # 清空日志
[root@redis01 ~]# redis-server /usr/local/redis/conf/redis.conf  # 启动redis服务
[root@redis01 ~]# cat /data/redis/redis.log   # 查看日志
:C Oct ::17.474 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Oct ::17.474 # Redis version=4.0., bits=, commit=, modified=, pid=, just started
:C Oct ::17.474 # Configuration loaded
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 54721
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Oct ::17.478 # Server initialized
:M Oct ::17.479 * DB loaded from disk: 0.000 seconds
:M Oct ::17.479 * Ready to accept connections

CentOS 7 安装Redis4.0的更多相关文章

  1. CentOS 7安装Redis4.0.10

    cd /usr/local/src && wget http://download.redis.io/releases/redis-4.0.10.tar.gz && t ...

  2. CentOS 7安装zabbix3.0

      CentOS 7安装zabbix3.0 一.环境介绍 # systemctl stop firewalld # setenforce 0 # yum -y install unzip vim ne ...

  3. centos7 安装 redis4.0.8

    1.安装lrzsz yum install lrzsz -y 2.利用rz命令将window中从redis官网下载好的“redis-4.0.8.tar.gz” 拷贝到centos中 redis官网 : ...

  4. centos7安装redis-4.0.1集群

    试验机操作系统:CentOS Linux release 7.2.1511 (Core) 本文的目的是教会大家快速搭建redis集群,完了再深入学习. 试问如果不上手试验,看的资料再多有个毛用? 下载 ...

  5. Linux下安装Redis4.0版本(简便方法)

    Redis介绍: Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的持久 ...

  6. linux 安装redis4.0.6

    1.进入/usr/local/src目录,下载redis # cd /usr/local/src# wget http://download.redis.io/releases/redis-4.0.6 ...

  7. centos6 安装redis-4.0.9

    从redis官网下载Linux redis4.0.9版本,我下载的redis-4.0.9.tar.gz(目前最新稳定版),下载到/usr/local/src目录,如果没有就mkdir创建一个. 下载链 ...

  8. centos7 安装 redis-4.0.9

    下载地址:https://redis.io/download 下载 安装: $ wget http://download.redis.io/releases/redis-4.0.9.tar.gz $ ...

  9. centos7/rhel7下安装redis4.0集群

    相关介绍:Redis从3.0版本开始支持集群! 集群一般由多个节点组成,节点数量至少6个才能保证组成完整高可用的集群. 每个节点需要开启配置文件中的cluster-enabled yes,让Redis ...

随机推荐

  1. elk安装&集群配置

    ---恢复内容开始--- 这里我用以elasticsearch-5.3.2.kibana-5.3.0.logstash-5.3.0的版本为例: 1.创建elastic用户,这里elasticsearc ...

  2. (二)文档请求不同源之window.name跨域

    一.基本原理 window.name不是一个普通的全局变量,而是当前窗口的名字.这里要注意的是每个iframe都有包裹它的window,而这个window 是top window的子窗口,而它自然也有 ...

  3. webpack 打包测试和生产多个版本

    cross-env修改生产环境变量 npm i --save-dev cross-env 在package.json里这么配置 npm run build就是打包到生产环境 npm run build ...

  4. MyBatis(三)MyBatis的增删改查

    (1)接口中编写方法 public Emp getEmp(Integer id); public void addEmp(Emp emp); public void deleteEmp(Integer ...

  5. SVN服务器搭建及使用

    .SVN(全称Subversion)是优秀的版本控制工具,与微软的TFS相比,有如下优势:开源(免费),支持多种操作系统. 本次我搭建的服务器采用:VisualSVN-Server-3.6.1-x64 ...

  6. Vue(二十六)父子组件通信

    今天写了一个分页公共组件,就出现了父子组件通信的问题,今天来总结下我遇到的父子组件通信问题 一.子组件调取父组件的数据或方法 (1)props 想要把父组件的值,传到子组件中,使用props 比如你在 ...

  7. webpack3_脚手架

    webpack    记得 --save-dev 装入开发依赖 更新迭代快,需要有根据报错解决问题的能力,来融会贯通这个工具 这里的是 webpack3,其实已经到了 webpack4 了 采用了 w ...

  8. [Codeforces Round #438][Codeforces 868D. Huge Strings]

    题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...

  9. Mac 比较实用的软件

    解压缩 BetterZip 系统 CleanMyMac Quicksilver Alfred3 视频 Movist

  10. HTTP 错误 405.0 - Method Not Allowed 无法显示您正在查找的页面,因为使用了无效方法(HTTP 谓词)。

    x 前言:报错信息 HTTP 错误 405.0 - Method Not Allowed 无法显示您正在查找的页面,因为使用了无效方法(HTTP 谓词). 发送至 Web 服务器的请求使用了为处理该请 ...