Table of Contents
Preface
Redis installation
Compile and install
Make Redis a service reference: Redis Quick Start
test
Redis stop and start
yum installation
Three ways to install source code
Forced termination
Rvm 安装 更换源
Rvm Ruby 安装、使用、卸载
RubyGems 升级、更换源、安装redis
集群配置
开启 Redis cluster
创建配置文件
创建数据存储文件
启动Redis cluster 节点
创建集群
测试
问题汇总
Home Backend Development PHP Tutorial Summary of Redis cluster building tutorial

Summary of Redis cluster building tutorial

Jul 28, 2018 am 10:25 AM
php redis

The content of this article is a summary of the Redis cluster building tutorial. The content is very detailed. Friends in need can refer to it. I hope it can help everyone.

Preface

This article collects and organizes web articles, websites, and my own experience in building Redis clusters. The level is limited and only the environment construction is shared. This article is divided into the following parts:

  • Redis installation

  • Rvm installation and replacement source

  • Rvm Ruby installation, use, uninstall

  • RubyGems upgrade, change source, install redis

  • Cluster configuration

  • Achievements Test

Please follow the above steps to view this article

Instructions:

  • For learning purposes only , I do not assume any responsibility if used online.

  • If you have any questions, please leave a message below.

  • Some commands in the article do not include sudo because I use root permissions.

Redis installation

Compile and install

wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar xzf redis-4.0.10.tar.gz
cd redis-4.0.10
make PREFIX=/usr/local/redis install
Copy after login

Note: If you do not want to use Redis as a service, you have already installed it here

Make Redis a service reference: Redis Quick Start

  • Create a directory where to store your Redis config files and your data: (Youdao Dictionary: Create A directory to store Redis configuration files and data :)

    Summary of Redis cluster building tutorial

    # 这只是一个目录结构,大家不要着急为什么自己没有,往下看,一步一步来
    [root@amor ~]# cd /usr/local/redis
    [root@amor redis]# tree
    .
    ├── bin  # 编译安装指定目录后自动生成目录及文件
    │   ├── redis-benchmark
    │   ├── redis-check-aof
    │   ├── redis-check-rdb
    │   ├── redis-cli
    │   ├── redis-sentinel -> redis-server
    │   └── redis-server
    ├── conf # 自己建立的存储配置文件的目录及自己创建的单个Redis配置文件
    │   └── 6379.conf
    └── data # 自己建立的存储Redis数据的目录及单个Redis服务数据存储目录
        └── 6379
    
    4 directories, 7 files
    Copy after login

    Note: cp /usr /src/redis-4.0.10/src/redis-trib.rb /usr/local/redis/bin/ You will need to use

  • Copy later when creating a cluster the init script that you'll find in the Redis distribution under the utils directory into /etc/init.d. We suggest calling it with the name of the port where you are running this instance of Redis. For example: (Youdao Dictionary : Copy the init script found in the Redis distribution under the utils directory into /etc/init.d We recommend calling it with the name of the port on which this Redis instance is running. For example:)

    sudo cp utils/redis_init_script /etc/init.d/redis_6379
    Copy after login
  • Edit the init script.(Youdao Dictionary: Edit the init script.)

    #!/bin/sh
    # chkconfig 2345 90 25                         # linux 开机启动设置 2345 运行级别 90 启动优先级(参考 memcached head /etc/rc.d/rc3.d/S90memcached ) 25 关闭优先级 (参考memcached)
    # 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
    
    REDISPORT=6379
    EXEC=/usr/local/redis/bin/redis-server         # 修改为自己的可执行文件所在目录
    CLIEXEC=/usr/local/redis/bin/redis-cli         # 修改为自己的可执行文件所在目录
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid        # 默认就好
    CONF="/usr/local/redis/conf/${REDISPORT}.conf" # 修改为自己的配置文件存放目录
    ···省略···
    esac
    Copy after login

    Start modifying redis.conf

    Make sure to modify REDISPORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number. The file names all depend on the port number.)

    • Set daemonize to yes (by default it is set to no). (Needs to be changed to yes)

    • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed). (default is sufficient)

    • Change the port accordingly. In our example it is not needed as the default port is already 6379. (The default is enough, you need to copy the configuration file and reset the port when setting up the cluster)

    • Set your preferred loglevel. (default is enough)

    • Set the logfile to / var/log/redis_6379.log (the default seems to be empty and needs to be modified)

    • Set the dir to /var/redis/6379 (very important step!) (Redis data storage directory, you need to modify the location custom path)

    • sudo cp redis.conf /usr/local/redis/conf/6379.conf (Modify into a self-defined directory. Refer to the above directory structure redis.conf in the src directory in your redis decompression directory)

    • sudo mkdir /usr/local/redis/data/6379 (modify into your own defined directory. Refer to the above directory structure)

    • Edit the configuration file, making sure to perform the following changes: (Youdao Dictionary: Edit the configuration file, make sure to perform the following changes: )

      注:上面的意思是让你们修改 /usr/local/redis/conf/6379.conf,用vim 打开,搜索上述关键词即可,参考以下设置(如果所有的步骤都是粘贴复制的走下来的,直接修改成下面这样:0.0):
      Copy after login
      port 6379
      daemonize yes
      pidfile /var/run/redis_6379.pid
      loglevel notice
      logfile "/var/log/redis_6379.log"
      dir /usr/local/redis/data/6379
      Copy after login
  • Finally add the new Redis init script to all the default runlevels using the following command: (Youdao Dictionary: Finally, use the following command to add the new Redis init script to Added to all default runlevels :)

    # ubuntu
    sudo update-rc.d redis_6379 defaults
    Copy after login
    # centos
    chkconfig --add redis_6379
    Copy after login
  • You are done! Now you can try running your instance with:

    sudo /etc/init.d/redis_6379 start
    Copy after login

test

Summary of Redis cluster building tutorial

Redis stop and start

yum installation

  • /etc/init.d /redis-server stop

  • /etc/init.d/redis-server start

  • /etc/init.d/redis-server restart

Three ways to install source code

sudo /etc/init.d/redis_6379 start
/usr/local/redis/bin/redis-server redis.conf  # 注意此处缺省:配置文件路径
redis-cli -h 127.0.0.1 -p 6379 shutdown
Copy after login

Note: If you just stop local redis, please execute: redis-cli shutdown

Forced termination

  • kill -9 process number

  • pkill redis

Rvm 安装 更换源

curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -L get.rvm.io | bash -s stable 
rvm user gemsets # 建立用户配置目录,更换源的时候需要向 db 文件写入配置信息
echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db # 更换源
Copy after login

Rvm Ruby 安装、使用、卸载

rvm list known
rvm install 2.6
rvm use 2.6
yum -y remove ruby # 卸载centos yum 安装的 1.8 版本
ruby --version
rvm uninstall ruby # 此处带不带版本自己测试
Copy after login

RubyGems 升级、更换源、安装redis

gem install rubygems-update 
rubygems-update
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l 
gem install redis
Copy after login

集群配置

注:下面的内容是我自己参考这篇博文加上我熟悉Redis安装后自己的配置过程。大家可以参考NrwLm - Redis 集群搭建详细指南。

开启 Redis cluster

cd /usr/local/redis/conf
cp 6379.conf redis.conf.default  # 用作集群其他配置文件的蓝本
sudo vim redis.conf.default
Copy after login

修改内容如下

bind 192.168.2.123  # 绑定当前机器 IP
cluster-enabled yes # 取消注释,启动集群模式
cluster-config-file nodes-6379.conf # 取消注释,修改为 /usr/local/redis/data/6379/nodes-6379.conf  (如果遇到需要重新建立集群,不将此项修改为指定路径而和启动配置文件放在一起,会导致建立集群时,删除重建conf 文件)
cluster-node-timeout 15000 # 取消注释
appendonly yes # 将 no 修改为 yes
Copy after login

创建配置文件

cd /usr/local/redis/conf
echo 9001.conf 9002.conf 9003.conf 9004.conf 9005.conf 9006.conf | xargs -n 1 cp -v redis.conf.default
sed -i 's/6379/9001/g'  9001.conf 
sed -i 's/6379/9002/g'  9002.conf 
sed -i 's/6379/9003/g'  9003.conf 
sed -i 's/6379/9004/g'  9004.conf 
sed -i 's/6379/9005/g'  9005.conf 
sed -i 's/6379/9006/g'  9006.conf
Copy after login

Summary of Redis cluster building tutorial

Summary of Redis cluster building tutorial

创建数据存储文件

cd /usr/local/redis/data
mkdir -p 9001 9002 9003 9004 9005 9006
# 后期可能需要删除该文件件下的文件,用于重建集群,所以,删除命令也写一下
rm -rf 900*/*
Copy after login

启动Redis cluster 节点

/usr/local/redis/bin/redis-server /usr/local/redis/conf/9001.conf
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9002.conf
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9003.conf 
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9004.conf
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9005.conf
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9006.conf
Copy after login

Summary of Redis cluster building tutorial

创建集群

/usr/local/redis/bin/redis-trib.rb create --replicas 1 192.168.2.123:9001 192.168.2.123:9002 192.168.2.123:9003 192.168.2.123:9004 192.168.2.123:9005 192.168.2.123:9006

Summary of Redis cluster building tutorial

测试

执行命令: /usr/local/redis/bin/redis-cli -c -h 192.168.2.123 -p 9001

<img src="/static/imghw/default1.png" data-src="https://img.php.cn//upload/image/755/105/520/1532744572918545.png" class="lazy" title="1532744572918545.png" alt="Summary of Redis cluster building tutorial">

问题汇总

  • 如果遇到timeout 请查看自己的防火墙,安装宝塔的尤其注意,请先去安全里面放行 9001:9006 的端口

  • redis集群 Waiting for the cluster to join 一直等待,redis集群不仅需要开通redis客户端连接的端口,而且需要开通集群总线端口,集群总线端口为redis客户端连接的端口 + 1000Summary of Redis cluster building tutorial

  • redis /usr/bin/env: ruby: 没有那个文件或目录

    • 执行这个命令 rvm get stable --auto-dotfiles,或者执行 nvm list 有详细的错误说明(查了资料说,线上不要用rvm安装ruby)

    Summary of Redis cluster building tutorial

    • 这是我自己的解决方案

      # 把这个添加到 /etc/profile 文件中(放到最后就行)
      rvm use ruby-2.6.0-preview2
      Copy after login

相关推荐:

CentOS7系统安装和配置Memcached的方法

The above is the detailed content of Summary of Redis cluster building tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles