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.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 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.dep Hint: 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-server 18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started 18685: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 initialized 18685: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 = 6379 EXEC = / usr / local / bin / redis - server CLIEXEC = / usr / local / bin / redis - cli PIDFILE = / var / run / redis_${REDISPORT}.pid CONF = "/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.pid daemonize 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 start
service redis_6379 stop
Centos 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执行命令 因为是自己的电脑测试 ...
随机推荐
- .NET移动开发环境搭建
开发工具:Xamarin Studio 社区版 下载地址 http://www.monodevelop.com/download/ 操作系统要求:Windows7及以上..NET Framework4 ...
- java实现MsOffice文档向pdf文档转化
本篇文档实现功能,将word和ppt文档的文件转化成pdf格式的文档 应用到jacob 第一步:下载压缩包 (1)jacob官网下载jacob压缩包 (2)网址:http://sourceforge. ...
- pandas dataframe 读取 xlsx 文件
refer to: https://medium.com/@kasiarachuta/reading-and-writingexcel-files-in-python-pandas-8f0da449c ...
- jQuery中使用data()方法读取HTML5自定义属性data-*实例
如果你使用jQuery类库,那么你可以非常愉悦的使用jquery的data()方法存取data-* 自定义属性,方法允许我们在DOM元素上绑定任意类型的数据,避免了循环引用的内存泄漏风险 主要的方法如 ...
- [CLPR] 用于加速训练神经网络的二阶方法
本文翻译自: http://www.codeproject.com/Articles/16650/Neural-Network-for-Recognition-of-Handwritten-Digi ...
- 插入排序算法-python实现
#-*- coding: UTF-8 -*- import numpy as np def InsertSort(a): for i in xrange(1,a.size): for j in xra ...
- python文本挖掘输出权重,词频等信息,画出3d权重图
# -*- coding: utf-8 -*- from pandas import read_csv import numpy as np from sklearn.datasets.base im ...
- 现象级AR营销助力“口碑双十二”,蚂蚁特工在全国数万商户掀起“AR捉四宝”
领取阅读奖励金 今年双十二,全国人民吃喝玩乐放飞自我,嗨出了新纪元.除了见证你国人民的财力,这个“双十二”还诞生了教科书级的“AR营销”.无论是在口碑商户门口,还是在各大购物广场,都能看到举着手机,正 ...
- Nginx rewrite使用
转自: https://www.cnblogs.com/czlun/articles/7010604.html
- 5月23日Google就宣布了Chrome 36 beta
对于开发人员来说,本次更新的重点还有element.animate().HTML Imports.Object.observe()的引入,以及一个改进后的throttled async touchmo ...