zoukankan      html  css  js  c++  java
  • CentOS7安装配置Redis

    第一步:下载redis安装包
    [root@bogon ~]# wget http://download.redis.io/releases/redis-5.0.6.tar.gz
    第二步:解压安装包   将压缩包解压到指定目录

    [root@bogon ~]# tar xf redis-5.0.6.tar.gz -C /data/www/

    第三步:安装gcc依赖

    先通过gcc -v是否有安装gcc

    [root@bogon ~]# gcc -v

    如果没有安装,执行命令

    [root@bogon ~]# yum install -y gcc

    第四步:cd到redis的解压目录下,并执行

    此处目录根据下载的redis版本及解压路径调整

    [root@bogon ~]# cd /data/www/redis-5.0.6/

    第五步:编译安装

    [root@bogon redis-5.0.6]# make MALLOC=libc

    将/data/www/redis-5.0.6/src目录下的文件加到/data/app/redis/bin目录

    [root@bogon redis-5.0.6]# mkdir /data/app/redis/bin -p

    [root@bogon redis-5.0.6]# cp -r src/ /data/app/redis/bin/

    [root@bogon redis-5.0.6]# cd src && make install

    第六步:测试是否安装成功

    [root@bogon src]# cd /data/www/redis-5.0.6/src/

    [root@bogon src]# ./redis-server

     如果显示蕾西以上部分信息,就已经安装成功了,ctrl+c关闭窗口

    第七步:配置redis

    以后台进程方式启动:

    1.修改/data/www/redis-4.0.9/redis.conf:    daemonize no   将值改为yes 保存退出

    [root@bogon src]# vim /data/www/redis-5.0.6/redis.conf 

    =========================

    136 daemonize yes

    =========================

    2.指定redis.conf文件启动:

    [root@bogon src]# ./redis-server /data/www/redis-5.0.6/redis.conf
    9626:C 27 Sep 2019 03:19:32.587 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    9626:C 27 Sep 2019 03:19:32.587 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=9626, just started
    9626:C 27 Sep 2019 03:19:32.587 # Configuration loaded

    设置redis远程连接:

    1.因为redis默认设置允许本地连接,所以我们要将redis.conf中将bind 127.0.0.1 改为bind 0.0.0.0或者注释该行

    [root@bogon src]# vim /data/www/redis-5.0.6/redis.conf

    =====================

      69 bind 0.0.0.0

    =====================

    2.另外,阿里云ECS有一个安全组,找到并添加规则允许6379端口访问

    设置redis连接密码:

    在redis.conf中搜索requirepass这一行,然后在合适的位置添加配置

    [root@bogon src]# vim /data/www/redis-5.0.6/redis.conf

    ========================

     507 requirepass yourpassword

    ========================

    设置完成后执行更新配置

    [root@bogon src]# ./redis-server /data/www/redis-5.0.6/redis.conf
    9637:C 27 Sep 2019 03:26:46.259 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    9637:C 27 Sep 2019 03:26:46.259 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=9637, just started
    9637:C 27 Sep 2019 03:26:46.259 # Configuration loaded

    第八步:设置开机自启动

    由于上面我们执行了redis进程启动,查看redis进程,并用kill -9 进程id杀死

    [root@bogon src]# ps -aux | grep redis
    root 9627 0.1 0.2 144024 2028 ? Ssl 03:19 0:00 ./redis-server 127.0.0.1:6379
    root 9641 0.0 0.0 112712 964 pts/0 R+ 03:27 0:00 grep --color=auto redis
    [root@bogon src]# kill -9 9627

    1、在/etc目录下新建redis目录

    [root@bogon src]# mkdir /etc/redis

    2、将/data/www/redis-5.0.6/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf

    [root@bogon src]# cp /data/www/redis-5.0.6/redis.conf /etc/redis/6379.conf

    3、将redis的启动脚本复制一份放到/etc/init.d目录下

    [root@bogon src]# cp /data/www/redis-5.0.6/utils/redis_init_script /etc/init.d/redisd

    4、设置redis开机自启动

    先切换到/etc/init.d目录下  

    [root@bogon src]# chkconfig redisd on

    如果显示service redisd does not support chkconfig  解决方法:

    使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

    # chkconfig:   2345 90 10

    # description:  Redis is a persistent key-value database

    注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

    再次执行开机自启命令chkconfig redisd on,这个时候应该就能成功了

    直接已服务的形式启动和关闭redis

    [root@bogon src]# service redisd start

    [root@bogon src]# service redisd stop
    Stopping ...
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    Redis stopped

    拷贝到指定的目录下运行:

    [root@c9 src]# mkdir /data/redis/{etc,bin} -p

    [root@c9 src]# cp -r redis-benchmark redis-cli redis-check-aof redis-check-rdb redis-server /data/redis/bin/

    [root@c9 src]# cp ../redis.conf /data/redis/etc/

    [root@c9 src]# ll /data/redis
    total 0
    drwxr-xr-x 2 root root 112 Oct 7 23:44 bin
    drwxr-xr-x 2 root root 24 Oct 7 23:43 etc
    [root@c9 src]# ll /data/redis/bin/
    total 13024
    -rwxr-xr-x 1 root root 353800 Oct 7 23:39 redis-benchmark
    -rwxr-xr-x 1 root root 4055328 Oct 7 23:39 redis-check-aof
    -rwxr-xr-x 1 root root 4055328 Oct 7 23:39 redis-check-rdb
    -rwxr-xr-x 1 root root 799280 Oct 7 23:39 redis-cli
    -rwxr-xr-x 1 root root 4055328 Oct 7 23:39 redis-server
    [root@c9 src]# ll /data/redis/etc/
    total 64
    -rw-r--r-- 1 root root 61797 Oct 7 23:43 redis.conf

    [root@c9 src]# /data/redis/bin/redis-server /data/redis/etc/redis.conf
    15492:C 07 Oct 2019 23:47:43.075 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    15492:C 07 Oct 2019 23:47:43.077 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=15492, just started
    15492:C 07 Oct 2019 23:47:43.077 # Configuration loaded

    [root@c9 src]# ps -ef|grep redis
    root 15493 1 0 23:47 ? 00:00:00 /data/redis/bin/redis-server 0.0.0.0:6379
    root 15519 14117 0 23:48 pts/0 00:00:00 grep --color=auto redis
    [root@c9 src]# netstat -ntlp|grep 15493
    tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 15493/redis-server

  • 相关阅读:
    Tarjan算法
    10JS数组
    9JS循环
    8.JS流程控制
    7.JS运算符
    6.JS方法
    5.JS变量的各种问题
    java封装遇到的问题
    js报Uncaught SyntaxError: Unexpected token <错误 解决方法:
    使用layui出现Uncaught ReferenceError: layui is not defined问题解决:
  • 原文地址:https://www.cnblogs.com/xuanbao/p/11598506.html
Copyright © 2011-2022 走看看