从零开始安装Redis 集群(Linux CenOS7)

使用ISO安装CentOS7虚拟机

安装jdk

  • 使用FileZilla上传jdk到Linux系统的/home/software
[root@localhost software]# mkdir /usr/java
...
[root@localhost software]# mkdir /home/software
...
[root@localhost software]# tar -zxvf jdk-8u231-linux-x64.tar.gz
...
[root@localhost software]# mv jdk1.8.0_231 /usr/java/
...
  • 配置java环境变量
  [root@localhost java]# vim /etc/profile
...
#最下方添加下面三条
export JAVA_HOME=/usr/java/jdk1.8.0_231
export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
...
[root@localhost java]# source /etc/profile
[root@localhost java]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

安装Redis

  • https://redis.io/download 下载稳定版本

  • 使用FileZilla上传redis到Linux系统的/home/software

  • 解压压缩包

    [root@localhost software]# tar -zxvf redis-5.0.7.tar.gz

    因为需要编译和生成redis,因此需要安装gcc

    [root@localhost software]# yum -y install gcc-c++
    ...
    已安装:
    gcc-c++.x86_64 0:4.8.5-39.el7 作为依赖被安装:
    cpp.x86_64 0:4.8.5-39.el7 gcc.x86_64 0:4.8.5-39.el7 glibc-devel.x86_64 0:2.17-292.el7 glibc-headers.x86_64 0:2.17-292.el7 kernel-headers.x86_64 0:3.10.0-1062.9.1.el7 libmpc.x86_64 0:1.0.1-3.el7
    libstdc++-devel.x86_64 0:4.8.5-39.el7 mpfr.x86_64 0:3.1.1-4.el7 完毕!

    进入redis-5.0.7解压目录,执行安装:

    [root@localhost redis-5.0.7]# make && make install
  • 配置Redis

    [root@localhost utils]# ll
    总用量 52
    -rw-rw-r--. 1 root root 593 11月 20 01:05 build-static-symbols.tcl
    -rw-rw-r--. 1 root root 1303 11月 20 01:05 cluster_fail_time.tcl
    -rw-rw-r--. 1 root root 1098 11月 20 01:05 corrupt_rdb.c
    drwxrwxr-x. 2 root root 60 11月 20 01:05 create-cluster
    -rwxrwxr-x. 1 root root 2149 11月 20 01:05 generate-command-help.rb
    drwxrwxr-x. 3 root root 31 11月 20 01:05 graphs
    drwxrwxr-x. 2 root root 39 11月 20 01:05 hashtable
    drwxrwxr-x. 2 root root 70 11月 20 01:05 hyperloglog
    -rwxrwxr-x. 1 root root 9567 11月 20 01:05 install_server.sh
    drwxrwxr-x. 2 root root 63 11月 20 01:05 lru
    -rw-rw-r--. 1 root root 1277 11月 20 01:05 redis-copy.rb
    -rwxrwxr-x. 1 root root 1352 11月 20 01:05 redis_init_script
    -rwxrwxr-x. 1 root root 1047 11月 20 01:05 redis_init_script.tpl
    -rw-rw-r--. 1 root root 1762 11月 20 01:05 redis-sha1.rb
    drwxrwxr-x. 2 root root 135 11月 20 01:05 releasetools
    -rwxrwxr-x. 1 root root 3787 11月 20 01:05 speed-regression.tcl
    -rwxrwxr-x. 1 root root 693 11月 20 01:05 whatisdoing.sh

    如上所示,在utils目录下,有一个redis_init_script文件,复制该文件到/etc/init.d/目录下,目的是为了配置redis为开机自启动。

    [root@localhost utils]# cp redis_init_script  /etc/init.d/
    [root@localhost utils]# mkdir /usr/local/redis -p
    [root@localhost redis-5.0.7]# cp redis.conf /usr/local/redis/

    创建/usr/local/redis目录,用于存放redis配置文件。

  • 修改redis配置文件

    ################################# GENERAL #####################################
    
    # 修改daemonize no为yes,目的是启动redis以后台进程运行
    daemonize yes
    # 修改redis工作路径(数据存储位置)
    dir /usr/local/redis/workingdb
    # 代表可以被远程访问,不受ip限制
    #bind 127.0.0.1
    bind 0.0.0.0
    # 修改密码
    requirepass 12345678
  • 修改redis_init_script文件中redis核心配置,修改文件权限


    REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/usr/local/redis/redis.conf"
    [root@localhost init.d]# chmod 777 redis_init_script
    #启动redis
    [root@localhost init.d]# ./redis_init_script start
  • 设置开机自启动

    1. /etc/init.d路径下的启动脚本文件中添加#chkconfig: 22345 10 90 &#description: Start and Stop redis
    [root@iZ2ze7s2v0b78922wia32rZ init.d]# vim redis_init_script
    #!/bin/sh
    #
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem. ### BEGIN INIT INFO
    # Provides: redis_6379
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Redis data structure server
    # Description: Redis data structure server. See https://redis.io
    ### END INIT INFO #chkconfig: 22345 10 90
    #description: Start and Stop redis REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/usr/local/redis/redis.conf"
    1. 执行chkconfig redis_init_script on,启动配置.

    2. 关闭redis

      [root@localhost redis]# /etc/init.d/redis_init_script stop
      Stopping ...
      (error) NOAUTH Authentication required.
      Waiting for Redis to shutdown ...
      Waiting for Redis to shutdown ...
      [root@localhost redis]# vim /etc/init.d/redis_init_script
      # 在脚本中也需要添加密码验证,才能关闭redis
      stop)
      if [ ! -f $PIDFILE ]
      then
      echo "$PIDFILE does not exist, process is not running"
      else
      PID=$(cat $PIDFILE)
      echo "Stopping ..."
      $CLIEXEC -a "12345678" -p $REDISPORT shutdown
      while [ -x /proc/${PID} ]
      do
      echo "Waiting for Redis to shutdown ..."
      sleep 1
      done
      echo "Redis stopped"
      fi
      ;;
      *)
    3. 安装之后,远程连接失败,因为在CentOS7 默认开启防火墙

      # 停止防火墙
      [root@localhost ~]# systemctl stop firewalld.service
      # 禁止防火墙开机启动
      [root@localhost ~]# systemctl disable firewalld.service
      Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
      Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

      或者执行下述命令来开放6379端口

      firewall-cmd --zone=public --add-port=6379/tcp --permanent

完整克隆虚拟机

  • 直接在VM ware fusion中需要克隆的机器上右键,选择 创建完整克隆

    • CentOS 7.直接修改Ip

      vim /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改IP配置
      service network restart 重置网络
    • CentOS 6或某些版本,需要更改MAC地址和IP

      vim /etc/udev/rule.d/70-persistent-ipoib.rules
      vim /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改IP配置
      service network restart 重置网络

Mac 下配置环境变量失效问题

自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bash_profile

发现zsh加载的是 ~/.zshrc文件,而 ‘.zshrc’ 文件中并没有定义任务环境变量。

解决办法

在~/.zshrc文件最后,增加一行:

source ~/.bash_profile

从零开始安装Redis 集群(Linux CenOS7)的更多相关文章

  1. centos7.0 安装redis集群

    生产环境下redis基本上都是用的集群,毕竟单机版随时都可能挂掉,风险太大.这里我就来搭建一个基本的redis集群,功能够用但是还需要完善,当然如果有钱可以去阿里云买云数据库Redis版的,那个还是很 ...

  2. liunx contos 7.4 安装redis集群

    前前后后安装了几次redis集群,基本上每次安装都会采坑,耗时伤神. 安装redis依赖gcc环境,安装前先检查liunx上面有没有安装GCC 命令:gcc -v 上传redis-4.0.1.tar. ...

  3. LINUX安装REDIS集群

    linux安装单机版redis已经在另一篇文章说过了,下边来搞集群,环境是新浪云服务器: redis3.0以后开始支持集群. 前言:redis用什么做集群? 用一个叫redis-trib.rb的rub ...

  4. Linux离线安装redis集群

    一.应用场景介绍 本文主要是介绍Redis集群在Linux环境下的安装讲解,联网环境安装较为简单,这里只说脱机的Linux环境下是如何安装的.因为大多数时候,公司的生产环境是在内网环境下,无外网,服务 ...

  5. Linux(ubuntu)安装redis集群,redis集群搭建

    今天学习一下redis集群的搭建.redis在现在是很常用的数据库,在nosql数据库中也是非常好用的,接下来我们搭建一下redis的集群. 一.准备 首先我们要安装c语言的编译环境,我们要安装red ...

  6. Linux 安装Redis<集群版>(使用Mac远程访问)

    阅读本文需要先阅读安装Redis<准备> 一 架构细节 所有的redis节点彼此互联(PING-PONG机制) 内部使用二进制协议优化传输速度和带宽 节点的fail是通过集群中超过半数的节 ...

  7. 离线安装redis集群

    Step0:redis集群组件需求 Step1:离线安装ruby Step2:离线安装rubygems Step3:安装rubygems的 redis api Step4:离线安装tcl 8.6 St ...

  8. 在虚拟机上安装redis集群,redis使用版本为4.0.5,本机通过命令客户端可以连接访问,外部主机一直访问不了

    在虚拟机上安装了redis 4 ,启动后本机客户端可以连接访问,但是外部主机一直访问不了,在使用java代码连接redis集群时报:no reachable node in cluster,原因:在r ...

  9. 阿里云服务器 CentOS 7.5 64位 docker安装redis集群

    网上有很多教程可以参考,但是遇到坑了...... 最后参考这个教程成功了.https://www.cnblogs.com/hbbbs/articles/10028771.html 安装docker 参 ...

随机推荐

  1. mysql format时间格式化说明

    原文地址为:mysql format时间格式化说明 date_format(datetime,formatting)可以格式日期和时间(例如 YYYY-MM-DD HH:MM:SS)和(HH:MM:S ...

  2. 用laravel搭一个微信公众号后台

    我使用的是laravel5.2, 早期版本可能不适合下面的方法. 在routes.php写下接收微信服务器post请求的路径: Route::post('wechatmp', 'WechatContr ...

  3. Angular项目目录结构

    前言:不支持MakeDown的博客园调格式的话,真的写到快o(╥﹏╥)o了,所以老夫还是转战到CSDN吧,这边就不更新啦啦啦~ CSDN地址:https://blog.csdn.net/Night20 ...

  4. LRJ-Example-06-17-Uva10562

    main() 函数中的这两行 fgets(buf[0], maxn, stdin); sscanf(buf[0], "%d", &T); 不能简单替换为 scanf(&qu ...

  5. Java一行代码可声明多个同类变量

    Java支持一句语句声明多个同类变量. Example: String a = "Hello", c = "hello"; int x = 5, y = 5;

  6. [Atom 编辑器 ] Packages

    Atom包      https://atom.io/packages 常用包整理: atom-chinese-menu   中文插件 atom-ternjs   对 es5,es6的语法支持 ato ...

  7. redis cluster和hash slot

    redis cluster介绍 从redis3.0.0开始,官方支持了redis cluster的集群模式,结束了redis没有集群的时代. redis cluster 支撑 N 个 redis ma ...

  8. H3C TFTP文件传输过程

  9. ASP.NET Core 开启后台任务

    本文告诉大家如何通过 Microsoft.Extensions.Hosting.BackgroundService 开启后台任务 实现 BackManagerService 类继承 Backgroun ...

  10. CentOS yum有时出现“Could not retrieve mirrorlist ”的解决办法——resolv.conf的配置

    国内服务器在运行命令yum -y install wget的时候,出现: Could not retrieve mirrorlist http://mirrorlist.centos.org/?rel ...