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

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. android开发错误经验总结

    TextView: 1.textView.setText();参数如果直接传int类型,ide不会显示错误.但是运行会报错. 布局渲染: 1. <View android:background= ...

  2. 记:第一次更新服务器CUDA和GPU驱动

    因有需求需要改动centos7中的CUDA(更新到10)和GUP 的driver(更新到410)的版本. 事先需要查看原版本的信息,使用nvidia-smi可以查看driver的版本信息(最新的也显示 ...

  3. keystone验证安装

     以管理员的身份来请求鉴权的标识 keystone --os-tenant-name admin --os-username admin --os-password 123456 --os-auth- ...

  4. net 架构师-数据库-sql server-002-工具

    本章讲述的工具包括: SQL Server 联机丛书 SQL Server配置管理器 SQL Server Management Studio SQL Server Business Intellig ...

  5. JDBC插入中文数据出现?号地解决问题

    1. 查看jdbc配置是否指定编码 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/te ...

  6. TMS320F28335——SPI使用笔记

    一.SPI硬件接口 GPIO54    -------    SPISIMOA GPIO55    -------    SPISOMIA GPIO56    -------    SPCLK GPI ...

  7. 2019-10-31-VisualStudio-2019-新特性

    title author date CreateTime categories VisualStudio 2019 新特性 lindexi 2019-10-31 08:48:27 +0800 2019 ...

  8. JavaEE高级-Spring学习笔记

    *Spring是什么? - Spring是一个开源框架 - Spring为简化企业级应用开发而生.使用Spring可以使简单的JavaBean实现以前只有EJB才能实现的功能 - Spring是一个I ...

  9. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  10. qt03 QString和QByteArray相互转换

    QString str("hello");   QByteArray bytes = str.toUtf8(); // QString转QByteArray方法1       QS ...