zoukankan      html  css  js  c++  java
  • Centos7安装Redis 3.2.8

    关闭防火墙和SELinx

    关闭防火墙

    [root@node1 ~]# systemctl stop firewalld

    开启防火墙

    [root@node1 ~]# systemctl enable firewalld

    关闭SElinux

    [root@node1 ~]# vim /etc/selinux/config 
    SELINUX=disabled
    [root@node1 ~]# getenforce 
    Disabled

    系统环境和版本说明

    [root@node2 ~]#  cat /etc/redhat-release
    CentOS Linux release 7.1.1503 (Core) 
    [root@node2 ~]# uname -r 
    3.10.0-229.el7.x86_64

    安装Redis

    安装gcc

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

    下载Redis安装包

    [root@node2 ~]# curl -O  http://download.redis.io/releases/redis-3.2.8.tar.gz

    解压

    [root@node2 ~]# tar -zxvf redis-3.2.8.tar.gz 

    切换目录

    [root@node2 ~]# cd redis-3.2.8/deps/

    编译依赖

    [root@node2 deps]# make geohash-int hiredis jemalloc linenoise lua

    切换目录

    [root@node2 deps]# cd ..

    编译Redis

    [root@node2 redis-3.2.8]# make && make install

    切换目录

    [root@node2 redis-3.2.8]# cd utils/

    使用脚本安装服务,配置后Redis弄随系统启动,执行期间会让你选择端口、文件名称等,我都选默认。一路回车

    [root@node2 utils]# ./install_server.sh

    启动服务

    [root@node2 utils]# systemctl start redis_6379

    关闭服务

    [root@node2 utils]# systemctl stop redis_6379

    查看服务状态

    [root@node2 utils]# systemctl status redis_6379

    查看进程

    [root@node2 utils]# ps -ef | grep redis
    root      18036      1  0 07:24 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
    root      18040   2254  0 07:24 pts/1    00:00:00 grep --color=auto redis

    测试(127.0.0.1 是计算机的IP地址  6379 是运行 Redis 服务器的端口)

    [root@node2 utils]# redis-cli
    127.0.0.1:6379> 

    执行ping命令(以下结果表明Redis 已成功安装)

    [root@node2 ~]# redis-cli
    127.0.0.1:6379> ping 
    PONG
    127.0.0.1:6379> 

    设置Redis登录密码

    修改redis.conf文件,把bind 注释掉或改为将IP改为 0.0.0.0

     61行 #bind 127.0.0.1 或  bind 0.0.0.0

    修改redis.conf文件,添加密码

     480行 requirepass 123456

    重启Redis服务,重启完成后进行测试

    [root@node2 ~]# redis-cli  -p 6379  不输入密码登录只能访问,无操作权限
    127.0.0.1:6379> keys *
    (error) NOAUTH Authentication required.     
    127.0.0.1:6379> 
    [root@node2 ~]# redis-cli  -p 6379 -a 123456  输入密码登录,获取操作权限
    127.0.0.1:6379> keys *
    (empty list or set)   
    127.0.0.1:6379> 

    如果不想设置密码,修改配置文件Redis.conf文件: protected-mode no

    可视化工具

    下载地址,直接在Windows上面安装

    链接:http://pan.baidu.com/s/1eSEORTK 密码:xsmv

    修改redis.conf文件,把bind改为虚拟机的本机IP

     61 bind 127.0.0.1  #修改为虚拟机的本机IP  如果不限制登录IP,可将127.0.0.1改为 0.0.0.0

     点击 Connect to Redis Server

     

    进行配置

     可以点击 Test Connection 进行测试,测试成功后点击 OK 进行连接

     

    常见问题

    无法停止Redis

    [root@node2 ~]# systemctl stop redis_6379
    无输出、无响应

    查看进程

    [root@node2 ~]# ps -ef | grep redis
    root      18764      1  0 10:26 ?        00:00:00 redis-server 127.0.0.1:6379
    root      18774      1  0 10:28 ?        00:00:00 /bin/sh /etc/rc.d/init.d/redis_6379 stop
    root      18876   2254  0 10:30 pts/1    00:00:00 grep --color=auto redis

    杀掉前两个进程

    [root@node2 ~]# kill -9 18764 18774
    [root@node2 ~]# 

    查看Redis运行状态,已经停止

    [root@node2 ~]# systemctl status redis_6379
    redis_6379.service - LSB: start and stop redis_6379
       Loaded: loaded (/etc/rc.d/init.d/redis_6379)
       Active: failed (Result: signal) since Fri 2017-09-01 10:31:15 EDT; 37s ago
      Process: 18774 ExecStop=/etc/rc.d/init.d/redis_6379 stop (code=killed, signal=KILL)
      Process: 18760 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)

    启动成功但无服务器进程

    将redis.conf 文件中的daemonize no 修改为 daemonize yes 

    [root@node2 ~]# vim /root/redis-3.2.8/redis.conf
    在128行 daemonize yes

    启动Redis服务器时无服务器进程

    [root@node2 ~]# systemctl start redis_6379

    服务启动成功,但是进程里无Redis服务器进程

    [root@node2 ~]# ps -ef | grep redis
    root      18982   2254  0 10:36 pts/1    00:00:00 grep --color=auto redis

    启动服务端

    [root@node2 ~]# redis-server /root/redis-3.2.8/redis.conf 

    启动成功

    [root@node2 ~]# ps -ef | grep redis
    root      18986      1  0 10:38 ?        00:00:00 redis-server 127.0.0.1:6379
    root      18990   2254  0 10:38 pts/1    00:00:00 grep --color=auto redis

    连接报错

    [root@node2 ~]## redis-cli
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    not connected> exit

    解决办法

    [root@node2 ~]# redis-server /root/redis-3.2.8/redis.conf
    [root@node2 ~]# redis-cli
    127.0.0.1:6379> 
  • 相关阅读:
    02数组基本操作
    01数组创建
    java流程控制
    assignment1
    Lecture 1: Introduction
    Lecture 14:Radial Basis Function Network
    Lecture 13:Deep Learning
    机器学习基石笔记16——机器可以怎样学得更好(4)
    机器学习基石笔记15——机器可以怎样学得更好(3)
    机器学习基石笔记14——机器可以怎样学得更好(2)
  • 原文地址:https://www.cnblogs.com/wanglan/p/7649841.html
Copyright © 2011-2022 走看看