CentOS 7 安装Redis4.0

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

环境 : CnetOS7   192.168.94.11

关闭SElinux和防火墙

安装Redis

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

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

[[email protected] redis]# grep -Ev ‘^#|^$‘ conf/redis.conf.bak > conf/redis.conf
[[email protected] redis]# mkdir /data/redis -p

修改redis配置文件

修改以下参数
[[email protected] redis]# vim conf/redis.conf

bind 0.0.0.0            #监听地址
port 6379               #监听端口
tcp-backlog 1024        #tcp连接数
daemonize yes           #是否后台启动
pidfile /data/redis/redis.pid   #pid存放目录
logfile "/data/redis/redis.log" #日志存放目录
dir /data/redis/                #工作目录

redis服务启动和关闭

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

redis系统参数优化

启动redis之后产看redis日志
[[email protected] redis]# cat /data/redis/redis.log
54108:C 08 Oct 15:45:46.095 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
54108:C 08 Oct 15:45:46.095 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=54108, just started
54108:C 08 Oct 15:45:46.095 # Configuration loaded
54109:M 08 Oct 15:45:46.097 * Increased maximum number of open files to 10032 (it was originally set to 1024).  # 系统文件描述符设置为1024,太小,最好设置为10032
                _._
           _.-``__ ‘‘-._
      _.-``    `.  `_.  ‘‘-._           Redis 4.0.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 54109
  `-._    `-._  `-./  _.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io
  `-._    `-._`-.__.-‘_.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |
  `-._    `-._`-.__.-‘_.-‘    _.-‘
      `-._    `-.__.-‘    _.-‘
          `-._        _.-‘
              `-.__.-‘                                               

54109:M 08 Oct 15:45:46.099 # WARNING: The TCP backlog setting of 1024 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.  # TCP的值为128太小了
54109:M 08 Oct 15:45:46.100 # Server initialized
54109:M 08 Oct 15:45:46.100 # 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.
# overcommit_memory=0为不允许超额抢占内存,但是,rdb保存可能会失败。建议将vm.overcommit_memory = 1进行修改

54109:M 08 Oct 15:45: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的延迟内存使用冲突

54109:M 08 Oct 15:45:46.100 * Ready to accept connections

下面来逐个调整

调整系统文件描述符
[[email protected] redis]# echo "* - nofile 10240" >> /etc/security/limits.conf
[[email protected] redis]# ulimit -n
1024
[[email protected] redis]# su -l    # 重新登录 , 使配置生效
上一次登录:一 10月  8 15:15:35 CST 2018从 192.168.94.1pts/1 上
[[email protected] ~]# ulimit -n
10240
调整TCP连接数
[[email protected] ~]# sysctl -a | grep soma
net.core.somaxconn = 128
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"
[[email protected] ~]# echo "net.core.somaxconn = 10240" >> /etc/sysctl.conf
[[email protected] ~]# sysctl -p
net.core.somaxconn = 10240
调整系统内存分配策略
[[email protected] ~]# echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
[[email protected] ~]# sysctl -p
net.core.somaxconn = 10240
vm.overcommit_memory = 1
[[email protected] ~]# 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 = 0
vm.overcommit_kbytes = 0
vm.overcommit_memory = 1    # 修改成功
vm.overcommit_ratio = 50
关闭系统内核的巨大内存页支持
[[email protected] ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[[email protected] ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[[email protected] ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[[email protected] ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
# 添加到rc.local
[[email protected] ~]# echo -e ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled\necho never > /sys/kernel/mm/transparent_hugepage/defrag‘>> /etc/rc.local
[[email protected] ~]# tail -2 /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

重启redis-server

[[email protected] ~]# redis-cli -h 127.0.0.1 shutdown    # 关闭redis服务
[[email protected] ~]# > /data/redis/redis.log     # 清空日志
[[email protected] ~]# redis-server /usr/local/redis/conf/redis.conf  # 启动redis服务
[[email protected] ~]# cat /data/redis/redis.log   # 查看日志
54720:C 08 Oct 16:08:17.474 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
54720:C 08 Oct 16:08:17.474 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=54720, just started
54720:C 08 Oct 16:08:17.474 # Configuration loaded
                _._
           _.-``__ ‘‘-._
      _.-``    `.  `_.  ‘‘-._           Redis 4.0.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 54721
  `-._    `-._  `-./  _.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io
  `-._    `-._`-.__.-‘_.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |
  `-._    `-._`-.__.-‘_.-‘    _.-‘
      `-._    `-.__.-‘    _.-‘
          `-._        _.-‘
              `-.__.-‘                                               

54721:M 08 Oct 16:08:17.478 # Server initialized
54721:M 08 Oct 16:08:17.479 * DB loaded from disk: 0.000 seconds
54721:M 08 Oct 16:08:17.479 * Ready to accept connections

原文地址:https://www.cnblogs.com/bigdevilking/p/9756107.html

时间: 2024-08-06 11:06:52

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

CentOS 7安装Redis4.0.10

cd /usr/local/src && wget http://download.redis.io/releases/redis-4.0.10.tar.gz && tar -xzvf redis-4.0.10.tar.gzcd /usr/local/src/redis-4.0.10 && make mkdir -p /usr/local/rediscp /usr/local/src/redis-4.0.2/src/redis-server /usr/loc

CentOS 7安装zabbix3.0

  CentOS 7安装zabbix3.0 一.环境介绍 # systemctl stop firewalld # setenforce 0 # yum -y install unzip vim net-tools lrzsz Zabbix 需要依赖LAMP/LNMP环境 # yum -y install httpd mariadb mariadb-server php   二.Zabbix 安装 1.安装服务器端包 1 2 3 #rpm -ivh http://repo.zabbix.com/

centos7.3 安装redis-4.0.7

centos7安装redis-4.0.7 解压 tar xvf redis-4.0.7.tar.gz -C /usr/local/src 编译 cd /usr/local/src/redis-4.0.7/ make PREFIX=/usr/local/redis install 准备 mkdir /usr/local/redis/{log,data,conf} cat /usr/local/redis/conf/redis.conf daemonize yes bind 0.0.0.0 #log

CentOS6.9安装Redis4.0.0

防伪码:没有相当程度的孤独是不可能有内心的平和. 1.环境准备 主机名 IP 系统 redis-01 192.168.10.24 CentOS release 6.9 (Final) Redis安装比较简单,官网下载界面就有参考: https://redis.io/download 2.安装 # 创建安装目录 mkdir /app # 下载redis4.0.0 cd /opt wget http://download.redis.io/releases/redis-4.0.0.tar.gz # 

CentOS7安装Redis4.0

1. 安装CentOS7,关闭防火墙 systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动 2 安装Redis需要用GCC编译.先安装GCC yum install gcc make 3. 通过wget下载redis wget http://download.redis.io/releases/redis-4.0.1.tar.gz  这里的下载地址可以去red

(十)Linux安装Redis-4.0.8

Redis的安装 1.上传 redis-4.0.8.tar.gz 到/usr/local/src文件夹 2.解压 tar xzf redis-4.0.8.tar.gz 3.cd redis-4.0.8 4.编译 make(因为下载的源码,需要编译) 编译完成之后,可以看到解压文件redis-4.0.8 中会有对应的src文件夹.conf文件. 5.编译成功后,进入src文件夹,执行make install进行Redis安装 Redis的部署 安装成功后,下面对Redis 进行部署, 1.首先为了

linux上安装redis4.0.9

redis安装从3.0的版本到现在4.0的版本,现在装一个4.0的版本供大家学习使用. 先yum安装gcc  yum -y install gcc 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile  * base: mirrors.aliyun.com  * extras: mirror.bit.edu.cn  * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正

阿里云 CentOS7安装redis4.0.9并开启远程访问

1 安装redis编译的c环境 yum install gcc-c++ redis是c语言开发的,安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境. 如果没有gcc环境,需要安装gcc环境 输入y开始安装: 2 redis安装 1 上传文件 2 解压文件到/usr/local下 进入到/soft目录后执行下面的命令. tar -xvf redis-4.0.9.tar.gz -C /usr/local 3 编译redis(将.c文件编译成.o文件)  1) 进入redis-4.0.

CENTOS7下安装REDIS4.0.11

拷贝收藏私用,别无他意,原博客地址:https://www.cnblogs.com/zuidongfeng/p/8032505.html 1.安装redis 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.11.tar.gz 1 2 3 4 5 6 7 8 9 10 11 [[email protected] local]# wget http://download.redis.io/releases/redis-4