Centos 7 安装和配置Redis
一. 安装
操作系统:Centos 7. 最小化安装
redis版本: 4.0.6
服务器地址:***
第一步:下载redis安装包(如果有新的,下载最新的redis安装包)
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@iZwz991stxdwj560bfmadtZ local]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz--2017-12-13 12:35:12-- http://download.redis.io/releases/redis-4.0.6.tar.gzResolving download.redis.io (download.redis.io)... 109.74.203.151Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 1723533 (1.6M) [application/x-gzip]Saving to: ‘redis-4.0.6.tar.gz’100%[==========================================================================================================>] 1,723,533 608KB/s in 2.8s 2017-12-13 12:35:15 (608 KB/s) - ‘redis-4.0.6.tar.gz’ saved [1723533/1723533] |
第二步:解压压缩包
tar -zxvf redis-4.0.6.tar.gz
|
1
|
[root@iZwz991stxdwj560bfmadtZ local]# tar -zxvf redis-4.0.6.tar.gz |
第三步:yum安装gcc依赖
yum install gcc
|
1
|
[root@iZwz991stxdwj560bfmadtZ local]# yum install gcc |
|
1
|
遇到选择,输入y即可<br><br><br> |
如果安装遇到错误:
nother app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:PackageKit
内存:119 M RSS (1.5 GB VSZ)
已启动: Sat Aug 11 23:10:18 2018 - 01:46之前
状态 :睡眠中,进程ID:3465
yum在锁定状态中。
可以通过强制关掉yum进程:
#rm -f /var/run/yum.pid
然后就可以使用yum了。
第四步:跳转到redis解压目录下
cd redis-4.0.6
|
1
|
[root@iZwz991stxdwj560bfmadtZ local]# cd redis-4.0.6 |
第五步:编译安装
make MALLOC=libc
|
1
|
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# make MALLOC=libc |
将/usr/local/redis-4.0.6/src目录下的文件加到/usr/local/bin目录
cd src && make install
|
1
2
3
4
5
6
7
8
9
10
|
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src && make install CC Makefile.depHint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install |
第六步:测试是否安装成功
先切换到redis src目录下
|
1
|
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src |
1、直接启动redis
./redis-server
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 4.0.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 18685 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.18685:M 13 Dec 12:56:12.508 # Server initialized18685:M 13 Dec 12:56:12.508 # 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.18685:M 13 Dec 12:56:12.508 # 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.18685:M 13 Dec 12:56:12.508 * Ready to accept connections |
如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。
按 ctrl + c可以关闭窗口。
如果执行安装命令时出现“没有这个目录”的错误,可以尝试删除解压目录,然后再重新解压一次。
至此,安装完成。
二. 配置Redis随机启动
1.把redis配置为随机启动,类似于windows的服务,开机启动。
centos下配置随机启动需要在目录/etc/init.d中添加启动脚本,启动脚本的模板在redis源代码目录的utils文件夹中:redis_init_script
我们把这个文件复制到/etc/init.d文件夹中,并重命名为redis_6379, 我们这个服务名也就为redis_6379了
再来看下这个文件的内容:
#!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# chkconfig: 2345 90 10# description: Redis is a persistent key-value database# as it does use of the /proc filesystem.REDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/redis/${REDISPORT}.conf"case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;;esac |
$EXEC $CONF 代码中变量赋值,exec为redis-server命令路径,conf为配置文件,配置文件为/etc/redis/6379.conf,这个文件还没有,我们下面来配置它:
创建目录/etc/redis。 配置文件的模板还在在redis源码中找:redis-4.0.6/redis.conf

将这个配置文件复制到/etc/redis目录 ,并重命名为6379.conf。
打开这个文件并修改:
这里贴出关键修改代码:
# 注释掉它,以便让外网访问# bind 127.0.0.1# 关闭保护模式protected-mode no# Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程# 启用守护进程后,Redis会把pid写到一个pidfile中,在/var/run/redis.piddaemonize yes# 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定pidfile /var/run/redis_6379.pid# 指定Redis监听端口,默认端口为6379# 如果指定0端口,表示Redis不监听TCP连接port 6379# 工作目录.# 指定本地数据库存放目录,文件名由上一个dbfilename配置项指定## Also the Append Only File will be created inside this directory.## 注意,这里只能指定一个目录,不能指定文件名dir /var/redis/6379 |
最后一行 /var/redis/6379 这个目录还没有,需要我们创建,用于存放redis的持久化文件。
然后执行命令:
#设置开机执行redis脚本chkconfig redis_6379 on |
通过上面的操作后,我们就可以通过 如下命令启动,停止redis了
service redis_6379 startservice redis_6379 stopCentos 7 安装和配置Redis的更多相关文章
- Ubuntu 安装和配置redis数据库
Ubuntu 14.04下安装和配置redis数据库 小编现在在写一个分布式爬虫,要用到这个数据库,所以分享一下小编是如何安装和配置的,希望对大家有帮助. 工具/原料 Ubuntu 系统电脑一台 ...
- 在 CentOS 上安装和配置 OpenNebula
转自:http://www.aikaiyuan.com/4889.html 我们提到的云计算一般有三种类型:软件即服务(Software as a Service, SaaS),平台即服务(Platf ...
- windows下安装和配置redis
1.windows下安装和配置redis 1.1 下载: 官网(linux下载地址):https://redis.io/ Windows系统下载地址:https://github.com/MSOpen ...
- Redis安装与配置Redis安装与配置
今天在使用Redis的时候遇到了一些问题,这个问题的解决,发现很多人使用Redis的时候没有一点安全意识.所以又重温了一下Redis,觉得应该写一下Redis的安全和配置. Redis安装与配置Red ...
- CentOS 7 安装 Nginx 配置反向代理
Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Ngi ...
- 阿里云CentOs服务器 安装与配置mysql数据库
阿里云CentOs服务器 安装与配置mysql数据库 以上为Linux安装mysql数据库 Linux 安装mysql 数据库 一下为mysql 安装教程 Using username "r ...
- Centos7 安装并配置redis
一. 安装 操作系统:Centos 7. 最小化安装 redis版本: 4.0.2 服务器地址:*** 安装过程: 安装wget, yum -y install wget 2. 下载redis wg ...
- CentOS下安装JDK,Tomcat,Redis,Mysql,及项目发布
上传文件到服务器,安装lrzsz , 可以将本地的文件上传到linux系统上. 如果是CentOS则可以用yum install lrzsz 命令安装,更方便. 或:yum -y install lr ...
- 本地电脑安装和配置Redis操作客户端
下载需要的文件:http://pan.baidu.com/s/1gdfQePl 把这个下载下来解压就可以了,如图所示 第一步(配置本地服务) 点击run这个DOS执行命令 因为是自己的电脑测试 ...
随机推荐
- Codeforces 158B:Taxi
B. Taxi time limit per test 3 seconds memory limit per test 256 megabytes input standard input outpu ...
- Rotor envoy control plane 简单试用
rotor 基于golang 的envoy xds 服务,支持多种集成方式: k8s consul aws dc/os demo试用docker 以及consul 进行环境运行 下载demo 可以试用 ...
- 访问https请求出现警告,去掉警告的方法
在顶部引多一个包即可 from requests.packages.urllib3.exceptions import InsecureRequestWarning,InsecurePlatformW ...
- CentOS下长时间ping网络加时间戳并记录到文本
Linux下长时间ping网络加时间戳并记录到文本 由于一些原因,比如需要检查网络之间是否存在掉包等问题,会长时间去ping一个地址,由于会输出大量的信息而且最好要有时间戳,因此我们可以使用简单的 ...
- 第2章 Linux操作系统简介
1. Linux操作系统的构成 (1)内核(kernel) ①操作系统的核心,负责管理系统的进程.内存.设备驱动程序.文件和网络系统. ②控制系统和硬件之间的相互通信. ③决定着系统的性能和稳定性. ...
- [nginx]lua操作redis
local redis = require "resty.redis" local red = redis:new() red:set_timeout() -- sec -- or ...
- 方便好使的java.util.Properties类
今天偶然碰到这个类,发现jdk中这些平时不大用到的类还挺好玩儿的,用起来也特别实在方便,随便写点记录下. java.util.Properties是对properties这类配置文件的映射.支持key ...
- libtrace 安装 使用 修改
下载 https://github.com/LibtraceTeam/libtrace/releases 解压 进入目录 依赖 sudo apt install libpcap0.8-dev -y a ...
- vue组件化开发实践
前言 公司目前制作一个H5活动,特别是有一定统一结构的活动,都要码一个重复的轮子.后来接到一个基于模板的活动设计系统的需求,便有了一下的内容.首先会对使用Vue进行开发的一些前期需要的技术储备进行简单 ...
- Mysql 查询列名
#列名 select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yunpiaobox_db' and table_ ...