############  准备  ###############

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

下载链接:https://redis.io/download

############  开始  ###############

################################## 1.安装redis ######################################
希望将redis安装到此目录

1
/usr/local/redis

希望将安装包下载到此目录

1
/usr/local/src

那么安装过程指令如下:

1
2
3
4
5
6
7
$ mkdir /usr/local/redis  
$ cd /usr/local/src  
$ tar xzf redis-3.2.6.tar.gz   
$ ln -s redis-3.2.6 redis #建立一个链接  
$ cd redis  
$ make PREFIX=/usr/local/redis install #安装到指定目录中

注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装:

1
yum install gcc

安装完成后,继续执行make.

这里也可以执行更新yum

1
sudo yum update

在安装redis成功后,你将可以在/usr/local/redis看到一个bin的目录,里面包括了以下文件:

1
redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-server

################################# 2.将redis做成一个服务并注册 ################################

1.复制脚本到/etc/rc.d/init.d目录 
ps: /etc/rc.d/init.d/目录下的脚本就类似与windows中的注册表,在系统启动的时候某些指定脚本将被执行 
按以上步骤安装Redis时,其服务脚本位于:

1
/usr/local/src/redis/utils/redis_init_script 

必须将其复制到/etc/rc.d/init.d的目录下:

1
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis

将redis_init_script复制到/etc/rc.d/init.d/,同时易名为redis。

如果这时添加注册服务:

1
chkconfig --add redis

将报以下错误:

1
redis服务不支持chkconfig

为此,我们需要更改redis脚本。

2.更改redis脚本 
打开使用vi打开脚本,查看脚本信息:

1
vim /etc/rc.d/init.d/redis

看到的内容如下(下内容是更改好的信息):

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh 
#chkconfig: 2345 80 90 
# Simple Redis init.d script conceived to work on Linux systems 
# as it does use of the /proc filesystem. 
   
REDISPORT=6379 
EXEC=/usr/local/redis/bin/redis-server 
CLIEXEC=/usr/local/redis/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 

和原配置文件相比(以下几处都要更改,特别是第一个#chkconfig,否则会导致无法添加配置):

1.原文件是没有以下第2行的内容的,

1
#chkconfig: 2345 80 90 

2.原文件EXEC、CLIEXEC参数,也是有所更改。

1
2
EXEC=/usr/local/redis/bin/redis-server   
CLIEXEC=/usr/local/redis/bin/redis-cli 

3.redis开启的命令,以后台运行的方式执行。

1
$EXEC $CONF & 

ps:注意后面的那个“&”,即是将服务转到后面运行的意思,否则启动服务时,Redis服务将

占据在前台,占用了主用户界面,造成其它的命令执行不了。 
4.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf

1
2
mkdir /etc/redis    
cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf

这样,redis服务脚本指定的CONF就存在了。默认情况下,Redis未启用认证,可以通过开启6379.conf的requirepass 指定一个验证密码。

以上操作完成后,即可注册yedis服务:

1
chkconfig --add redis

3.启动redis服务

1
service redis start 

########################  3.将Redis的命令所在目录添加到环境变量PATH中 ##############################

修改profile文件:

1
vi /etc/profile

在最后行追加:

1
export PATH="$PATH:/usr/local/redis/bin"

应用这个文件:

1
. /etc/profile  

####################################  4.设置redis密码 #########################################

打开配置文件:# vi /etc/redis/6379.conf

1
vi /etc/redis/6379.conf 

进入命令模式查找"requirepass"字符串,找到这一段,去掉前面的#号,后面密码就自定义了(此处修改为-Tq8UA7zredis)

1
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass -Tq8UA7zredis

# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients. 

要使配置生效可以重启一下

#####################################  5.安装完成,进入redis ####################################

这样就可以直接调用redis-cli的命令了,如下所示:

1
2
3
4
$ redis-cli   
redis 127.0.0.1:6379> auth -Tq8UA7zredis   
OK  
redis 127.0.0.1:6379>

 

redis-cli shutdown :关闭命令
service redis start:启动命令

java整合redisTest

/**
*
* @ClassName: JedisTest
* @Description: jedis配置链接测试类(这里用一句话描述这个类的作用)
* @author youqc
* @date 2018年3月17日
*
*/
public class JedisTest {
@Test
public void testSetting(){
JedisPoolConfig config = new JedisPoolConfig();
//最大连接数
config.setMaxTotal(30);
//最大连接空闲数
config.setMaxIdle(2);
JedisPool pool = new JedisPool(config, "119.23.70.207", 6379, 3000, "root.201803##@@!!");
Jedis jedis = null;
try {
jedis = pool.getResource();
jedis.set("name", "lisi");
String name = jedis.get("name");
System.out.println(name);
}catch(Exception ex){
ex.printStackTrace();
}finally{
if(jedis != null){
//关闭连接
jedis.close();
}
}
}

}

1.本地无法访问redis服务器:将redis。conf文件的bind 127.0.0.1前新增# 注释;

 

阿里云CentOS 7.3安装Redis详细步骤的更多相关文章

  1. 阿里云Centos 7.6安装Redis以及开启远程连接

    下载地址:http://redis.io/download,下载最新稳定版本. 本教程使用的最新文档版本为 5.0.5,下载并安装: $ wget http://download.redis.io/r ...

  2. 阿里云centos 7上面安装mysql5.7的详细步骤!!!

    前言: 网上太多的linux 的安装mysql教程,很多教程不全或者因为环境不一致导致无法成功安装,以下是亲测的可行性的方法,请参考. 步骤: Centos7操作系统YUM库列表里默认不再提供MySQ ...

  3. 阿里云Centos 7上面安装mysql教程

    1 软件的基本安装过程 1 卸载已有的mysql 1.查看系统是否安装了mysql软件 rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用 ...

  4. [Linux] - 阿里云CentOS 6.5 安装Docker

    因为阿里云的CentOS 6.5版本默认内核kernel版本是2.6的,比较低.安装docker的后,运行不了. 步骤: 1.使用命令更新: yum update 2.安装Docker.这里忽略500 ...

  5. 阿里云主机(aliyun-Linux) x64安装Redis详解

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/97.html?1455870336 如何在Linux​上安装Redis呢, ...

  6. 阿里云centos系统上安装ftp

    最近需要在一台阿里云的云服务器上搭建FTP服务器,在这篇博文中分享一下我们根据实际需求进行的一些配置. ftp软件用的是vsftpd. vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...

  7. 阿里云,CentOS下yum安装mysql,jdk,tomcat

    首先说明,服务器是阿里云的,centos6.3_64位安全加固版.首先需要登陆进来,使用的是putty,因为最初的时候,Xshell登陆会被拒绝. 0. 创建个人文件夹 # 使用 yum 安装tomc ...

  8. linux安装redis详细步骤(系统centos 6.4 )

    1.安装redis 进入安装目录下载: cd  /usr/local/redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 解 ...

  9. mac下安装redis详细步骤

    Linux下安装redis也可以参照下面的步骤哦!!!! 1.到官网上下载redis,我下载的版本是redis-3.2.5.tar 官网地址:http://redis.io/ 2.将下载下来的tar. ...

随机推荐

  1. [19/10/16-星期三] Python中的模块和包、异常、操作文件

    一.模块 # 模块(module) # 模块化,模块化指将一个完整的程序分解为一个一个小的模块 # 通过将模块组合,来搭建出一个完整的程序 # 不采用模块化,统一将所有的代码编写到一个文件中 # 采用 ...

  2. Python 入门之Python基础数据类型及其方法

    Python 入门之Python基础数据类型 1. 整型:int 用于计算,用于比较 (在赋值的时候先执行等号右边的内容) 1.1 整数的加 a = 10 b = 20 print(a + b) 结果 ...

  3. css实现斑马线效果

    文本实现斑马线效果 <style> p { font-size: 17px; line-height: 25px; background-color: antiquewhite; back ...

  4. 行内元素(例如)设置float之后才能用width调整宽度

    因为只有块元素才会有物理属性,在css世界里边,有三种形态的东西, 1. 块元素. 特性:有物理属性,width,height写值起作用,而且要占据一行.2. 内联元素. 特性:没有物理属性.但是ma ...

  5. git(github)配置密钥/私钥/SSH公钥)

    1.桌面右键 Git Bash Here 打开git命令行 2.ssh-keygen -t rsa -C "xxxxx@qq.com"(你的注册邮箱)enter 3.cd ~/.s ...

  6. django基础篇04-自定义simple_tag和fitler

    自定义simple_tag app目录下创建templatetags目录 templatetags目录下创建xxpp.py 创建template对象register,注意变量名必须为register ...

  7. Spring基础15——通过工厂方法来配置bean

    1.什么是工厂方法 这里的工厂方法指的是创建指定bean的方法.工厂方法又分为静态工厂方法和实例工厂方法. 2.静态工厂方法配置bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中 ...

  8. Web基础之http协议

    第6章 Web基础之http协议 第6章 Web基础之http协议一.http协议介绍 1.1)什么是超文本 1.2)什么是URL 1.3)什么是超文本传输协议二.访问网站分析三.页面请求信息解析(仅 ...

  9. CSS的优先级理解

    样式的优先级 多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 一般情况下,优先级如下: (外部样式)External styl ...

  10. python--线程锁,队列

    #线程数据安全处理--同步锁 import time def sub(): global num print("ok") lock.acquire()#获取这把锁--->只有 ...