编程知识 cdmana.com

Rapid deployment of casandra3 cluster in ansible

Welcome to visit mine GitHub

https://github.com/zq2599/blog_demos

Content : All original articles classified summary and supporting source code , involve Java、Docker、Kubernetes、DevOPS etc. ;

About cassandra3 Cluster deployment

Usually cassandra3 The cluster deployment operations are as follows :

  1. install JDK;
  2. Set up JDK environment variable ;
  3. Create run cassandra Service groups and accounts ;
  4. install cassandra;
  5. Set up cassandra environment variable ;
  6. Set up cassandra Parameters ;
  7. Set up cassandra Log directory and file directory ;

The above operations shall be performed on each machine , Manual operation is more time-consuming , So with ansible To complete all of the above steps , Except that it 's easy , It also reduces the overview of operational errors ;

About ansible Deploy

  1. ansible It's a common operation and maintenance tool , Can greatly simplify the entire deployment process ;
  2. Next use ansible Complete the deployment , If you want to know ansible, Please refer to 《ansible2.4 Installation and experience 》;
  3. The deployment operation is shown in the figure below , Installed in one ansible Running scripts on your computer , from ansible Remote connection to three CentOS7.7 On , Complete the deployment :

 Insert picture description here

Software version

The software version information of this actual combat is as follows :

  1. ansible Computer operating system :CentOS Linux release 7.7.1908
  2. cassandra Server operating system :CentOS Linux release 7.7.1908
  3. cassandra edition :3.11.6
  4. jdk:1.8.0_191

Material preparation

ansible The most important thing about remote operation is to prepare materials in advance , This actual battle needs to be as follows 7 file ( Download address later ):

  1. ansible.cfg:ansible The configuration file ;
  2. hosts: Saved three cassansra server information ;
  3. cluster-3-nodes.yml:ansible Script , namely playbook file , It is the logic of the whole installation and deployment ;
  4. vars-cluster-3-nodes.yml:ansible The variable configuration information used in the script , for example JDK file name ,cassandra File name, etc. ;
  5. cassandra.yaml:cassandra The configuration file , I took it out of the package and made some changes ( Several directory related configurations , Changed from comment state to effective state by me )
  6. apache-cassandra-3.11.6-bin.tar.gz:cassandra Official installation package ;
  7. jdk-8u191-linux-x64.tar.gz:jdk8 The official installation package for ;

Download address of all materials

  1. from 1 To 5 The content can be found in my GitHub download , Warehouse address :https://github.com/zq2599/blog_demos , In the warehouse <font color="blue">playbooks/cassandra3</font> Under the table of contents , A name is <font color="blue">cluster-3-nodes</font> Folder , As shown in the red box below , There are five documents in it :  Insert picture description here
  2. apache-cassandra-3.11.6-bin.tar.gz: Download it from the official website :http://ftp.kddilabs.jp/infosystems/apache/cassandra/3.11.6/apache-cassandra-3.11.6-bin.tar.gz
  3. jdk-8u191-linux-x64.tar.gz:Oracle The official website is available , It can also be in csdn download ( No points ), Address :https://download.csdn.net/download/boling_cavalry/12098987

Location of documents

  1. Sign in ansible The computer , Create a home directory called palybooks The catalog of , The order is :mkdir ~/playbooks
  2. Of the seven documents above ,1 To 4 Put in playbooks Catalog ;
  3. playbooks The new name in the directory is files The catalog of , take 5 To 7 Put it in ;
  4. The location of the final seven documents is shown in the figure below :

 Insert picture description here

Modify the configuration

  1. cassandra Server's IP Address 、 account number 、 The password needs to be changed to your own information , Please amend hosts Relevant contents in the document , Here's the picture :  Insert picture description here
  2. cassandra Clustered seed The configuration is for two of the machines IP Address , The message is vars-cluster-3-nodes.yml, Please change it to your own machine IP Address , As shown in the yellow box below :  Insert picture description here
  3. If your cluster name 、jdk edition 、cassandra The version is different from mine , Can be in <font color="red">vars-cluster-3-nodes.yml</font> Revision in China ;
  4. for the first time ssh Connect to cassandra There will be a prompt for input when the machine "Yes", In order to avoid this situation ansible Connect cassandra Machine time , It is recommended to connect it manually first , So there's no more hint , Here's the picture :  Insert picture description here

Ready , It's time to deploy ;

Deploy

  1. stay playbooks Execute under directory ansible-playbook cluster-3-nodes.yml
  2. Wait for about 5 About minutes , If the console does not report an error , The entire installation process is complete ;
  3. If there is an error , Please follow the error prompt to do a good job of processing and then repeat ansible-playbook cluster-3-nodes.yml, This command can be executed many times ;

start-up

  1. When deployed, it creates a file named <font color="blue">cassandra</font> Group of , And called <font color="blue">cassandra</font> Account number ;
  2. With cassandra Account number SSH Log in to three cassandra machine , The password is <font color="red">888888</font>
  3. Sign in cassandra Behind the machine , To execute a command anywhere <font color="blue">cassandra</font>, You can start cassandra service ;
  4. Wait about a few minutes , Service initialization 、 Build a cluster successfully :  Insert picture description here
  5. Execute commands in any directory of three machines <font color="blue">nodetool status</font>, View the cluster : ansible Rapid deployment cassandra3 colony

verification

  1. On any one cassandra On the machine ,cqlsh After entering interactive mode , Do the following :  Insert picture description here
  2. Create a springboot application , Visit the new student surface , As shown in the red box below , Connect when app starts cassandra success :  Insert picture description here
  3. springboot There is a... In the application that searches for records by name web Interface , Here's the picture , You can find the records in the database :  Insert picture description here
  4. above springboot The application source code has been uploaded to GitHub, Warehouse address :https://github.com/zq2599/blog_demos , In the warehouse <font color="blue">cassandrahelloworld</font> Under the table of contents , As shown in the red box below :  Insert picture description here thus ,cassandra The cluster operation has been completed from deployment to verification , I hope I can give you some reference ;

Welcome to the official account : Xinchen, programmer

WeChat search 「 Xinchen, programmer 」, I'm Xinchen , Looking forward to traveling with you Java The world ... https://github.com/zq2599/blog_demos

版权声明
本文为[Programmer Xinchen]所创,转载请带上原文链接,感谢

Scroll to Top