Blog > How to implement rapid deployment of SequoiaDB cluster with Docker

How to implement rapid deployment of SequoiaDB cluster with Docker

 2019-03-15  SequoiaDB,Docker
How to implement rapid deployment of SequoiaDB cluster with Docker

Container technology, represented by Docker and Rocket, is becoming more and more popular. It changes the way companies and users create, publish, and use distributed applications, and it will bring its value to the cloud computing industry in the next five years. The reasons for its attractiveness are as follows:

1)Resource Independence and Isolation

Resource isolation is the most basic requirement of cloud computing platforms. Docker limits the hardware resources and software running environment through the Linux namespace, cgroup, and is isolated from other applications on the host machine, so it does not affect each other.

Different applications and service are “ship” and “unship” with the unit of container. Thousands of “containers” are arranged on the “container” ship. Different companies, different types of “goods” (programs, components, operating environments, dependencies required to run applications) remain independent.

2) Environmental Consistency

The development engineer builds a docker image after finishing the application development. Based on this image, the container is packaged with various “parts of goods” (programs, components, operating environment, dependencies required to run the application). No matter where the container is: development environment, test environment or production environment, you can ensure that the number of “goods” in the container is exactly the same, the software package will not be missing in the test environment, and the environmental variables will not be forgotten in the production environment. The development and production environment will not cause the application to run abnormally due to the dependency of installing different versions. This consistency is benefited by the fact that the “build docker image” is already sealed into the “container” when delivery, and each link is transporting this complete “container” that does not need to be split and merged.

3) Lightweight

Compared to traditional virtualization technology (VM), the performance loss of using docker on cpu, memory, disk IO, network IO has the same level or even better performance. The rapid creation, start-up, and destruction of containers have received a lot of praise.

4)Build Once, Run Everywhere

This feature has attracted many people. When the “goods” (application) is exchanged between “cars”, “trains”, “ships” (private clouds, public clouds, etc.), it only need to migrate the “docker container” which conform to the standard specifications and handling mode, which has reduced the time-consuming and labor-intensive manual “loading and unloading” (online and off-line applications), resulting in huge time labor cost savings. This feature makes it possible for only a few operators in the future to operate the container clusters for ultra-large-scale loading online applications, just as a few machine operators in the 1960s can unload a 10,000-class container ship in a few hours.

Container technology nowadays is also widely used in the database field. Its “Build Once, Run Everywhere” feature greatly reduces the time spent on installing the configuration database environment. Because even for DBAs who have been working with databases for many years, installing the configuration database environment is still a seemingly simple but often a complex work. Of course, other advantages of container technology are also well used in the application of databases.

As an excellent domestic distributed NewSQL database, SequoiaDB has been recognized by more and more users. This article takes Docker as an example, focusing on how to quickly build a SequoiaDB image with Dockerfile, and how to use the container to quickly build and start the SequoiaDB cluster to application system.

Build SequoiaDB image

How to install docker and configure repositories is not the focus of this article. There are many related technical articles on the Internet. It should be pointed out that this article uses Aliyun Repository, because the speed of uploading images to Docker official repository is unflattering. How to register and use the Aliyun Repository can refer to the article (http://www.jb51.net/article/123101.htm).

STEP 1: Create Dockerfile using following simple statements:

# Sequoiadb DOCKERFILES PROJECT
# --------------------------
# This is the Dockerfile for Sequoiadb 2.8.4
#
# REQUIRED FILES TO BUILD THIS IMAGE
# ----------------------------------
# (1) sequoiadb-2.8.4-linux_x86_64-enterprise-installer.run
# (2) installSDB.sh
#
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile
# Run:
#      $ sudo docker build -t sequoiadb:2.8.4 .
#
# Pull base image
   FROM ubuntu
# Environment variables required for this build
   ENV INSTALL_BIN_FILE="sequoiadb-2.8.4-linux_x86_64-enterprise-installer.run" \
    INSTALL_SDB_SCRIPT="installSDB.sh" \
    INSTALL_DIR="/opt/sequoiadb"
# Copy binaries
ADD $INSTALL_BIN_FILE $INSTALL_SDB_SCRIPT $INSTALL_DIR/
# Install SDB software binaries
    RUN chmod 755 $INSTALL_DIR/$INSTALL_SDB_SCRIPT \
    && $INSTALL_DIR/$INSTALL_SDB_SCRIPT \
          && rm $INSTALL_DIR/$INSTALL_SDB_SCRIPT

The content of the installSDB.sh script are as follows:

chmod 755 $INSTALL_DIR/$INSTALL_BIN_FILE
$INSTALL_DIR/$INSTALL_BIN_FILE --mode unattended
rm $INSTALL_DIR/$INSTALL_BIN_FILE
echo 'service sdbcm start' >> /root/.bashrc

It should to be noted that this example uses SequoiaDB Enterprise Edition 2.8.4. You can also download the community version from the official website of SequoiaDB (select tar package, download and extract), and replace the media name in this example.

SequoiaDB website download address: http://download.sequoiadb.com/cn/

STEP 2: Create an image

The root user executes:

docker build -t sequoiadb:2.8.4 .

If you are a normal user, use sudo:

sudo docker build -t sequoiadb:2.8.4 .

STEP3: Login to Aliyun Repository

docker login --username=xxx registry.cn-hangzhou.aliyuncs.com
Where xxx is the account you registered with Alibaba Cloud.

STEP4: View local SequoiaDB image id

docker images

STEP5: Mark local image and put it into Aliyun Repository

docker tag 04dc528f2a6f registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb:latest
04dc528f2a6f is the author’s local sequoiadb image id, registry.cn-hangzhou.aliyuncs.com is the Aliyun Repository address, 508mars is the author’s name in Aliyun, SequoiaDB is the image name, and latest is the tag.

STEP6:Submit Sequoiadb image to image library

docker push registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb:latest

Start SequoiaDB cluster with container

Docker’s network defaults to bridge mode, and containers in bridge mode have the following characteristics:

1) Containers in the same host can ping each other

2) Containers in different hosts can not ping each other

However, the SequoiaDB cluster requires interoperability between all nodes, so if the container with SequoiaDB is running on different hosts, the default network mode of docker is obviously inappropriate. There are many ways to solve the connectivity problem between different host containers. This article only introduces the weave virtual network solution, because weave also provides a DNS server function. When deploying SequoiaDB clusters with containers using this function, it is no longer necessary to modify /etc/hosts inside each container, which greatly simplifies the steps of automated deployment.

STEP1: Install the weave network

curl -s -L git.io/weave -o /usr/local/bin/weave
chmod a+x /usr/local/bin/weave

It needs to install on all hosts, the author uses three virtual machines as hosts: sdb1, sdb2 and sdb3.

STEP2: Start the weave network

weave launch

The weave image will be downloaded the first time it is started.

STEP3: Download the SequoiaDB image from Aliyun Repository

docker pull registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb

STEP4: Create a docker mounted volume on all hosts

cd /home/sdbadmin
mkdir -p data/disk1 data/disk2 data/disk3
mkdir -p conf/local
chmod -R 777 data
chmod -R 777 conf

The location of the mounted volume can be customized, but in general, it needs to create two types of mounted volumes, one for storing aggregate data, such as data/disk1, data/disk2, data/disk3, and so on. The other is used to store node configuration information, such as conf/local in this example. Thus, even if the container is deleted by mistake, you can still start a new container to play the role of the container that was accidentally deleted.

STEP5: Start the container

sdb1:

weave stop
weave launch
eval $(weave env)
docker run -dit --name sdbserver1 -p 11810:11810 -v /home/sdbadmin/data:/data -v /home/sdbadmin/conf/local:/opt/sequoiadb/conf/local registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb

sdb2:

weave stop
weave launch 192.168.17.132
eval $(weave env)
docker run -dit --name sdbserver2 -p 11810:11810 -v /home/sdbadmin/data:/data -v /home/sdbadmin/conf/local:/opt/sequoiadb/conf/local registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb

sdb3:

weave stop
weave launch 192.168.17.132
eval $(weave env)
docker run -dit --name sdbserver3 -p 11810:11810 -v /home/sdbadmin/data:/data -v /home/sdbadmin/conf/local:/opt/sequoiadb/conf/local registry.cn-hangzhou.aliyuncs.com/508mars/sequoiadb

192.168.17.132 is the IP address of sdb1 and 11810 is the externally exposed cluster access port. The volume on the host that stores the node configuration information must be hung in the /opt/sequoiadb/conf/local directory of the container. The volume that holds the table data can be mounted to the user-defined directory. However, once the cluster is created, it cannot be changed. The machine name must be specified when starting the container, because after the cluster is built, the machine name will be saved in the system table of SequoiaDB. If the machine name of the node is inconsistent with the system table, it will not be added to the cluster. In the scenario of using weave, it is recommended to use the--name option. Do not use--hostname to set the machine name. The latter will prevent weave from adding the machine name to the DNS server. Weave will automatically set the machine name according to the value of --name, and add the weave.local domain name after the machine name. Also, it will add it to the DNS server.

STEP6: Copy the script that created the SequoiaDB cluster to the container

docker cp create_cluster.js sdbserver1:/data

The content of create_cluster.js is as follows:

var array_hosts = ["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"];
var array_dbroot = ["/data/disk1/sequoiadb/database","/data/disk2/sequoiadb/database","/data/disk3/sequoiadb/database"];
var port_sdbcm = "11790";
var port_temp_coord = "18888";
var cataloggroup = {gname:"SYSCatalogGroup", gport:"11820", ghosts:["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"]};
var array_coordgroups = [
        {gname:"SYSCoord", gport:"11810", ghosts:["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"]}
];
var array_datagroups = [
        {gname:"dg1", gport:"11830", ghosts:["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"], goptions:{transactionon:true}}
       ,{gname:"dg2", gport:"11840", ghosts:["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"], goptions:{transactionon:true}}
       ,{gname:"dg3", gport:"11850", ghosts:["sdbserver1.weave.local", "sdbserver2.weave.local", "sdbserver3.weave.local"], goptions:{transactionon:true}}
];
var array_domains = [
        {dname:"allgroups", dgroups:["dg1", "dg2", "dg3"], doptions:{AutoSplit:true}}
];
println("启动临时协调节点");
var oma = new Oma(array_coordgroups[0].ghosts[0], port_sdbcm);
oma.createCoord(port_temp_coord, array_dbroot[0]+"/coord/"+port_temp_coord);
oma.startNode(port_temp_coord);
println("创建编目节点组:"+cataloggroup.ghosts[0]+"   "+cataloggroup.gport+"    "+array_dbroot[0]+"/cata/"+cataloggroup.gport);
var db = new Sdb(array_coordgroups[0].ghosts[0], port_temp_coord);
db.createCataRG(cataloggroup.ghosts[0], cataloggroup.gport, array_dbroot[0]+"/cata/"+cataloggroup.gport);
var cataRG = db.getRG("SYSCatalogGroup");
for (var i in cataloggroup.ghosts) {
        if (i==0) {continue;}
    println("创建编目节点: "+cataloggroup.ghosts[i]+"  "+cataloggroup.gport+"    "+array_dbroot[0]+"/cata/"+cataloggroup.gport);
        var catanode = cataRG.createNode(cataloggroup.ghosts[i], cataloggroup.gport, array_dbroot[0]+"/cata/"+cataloggroup.gport);
        catanode.start();
}
println("创建协调节点组");
var db = new Sdb(array_coordgroups[0].ghosts[0], port_temp_coord);
var coordRG = db.createCoordRG();
for (var i in array_coordgroups) {
        for (var j in array_coordgroups[i].ghosts) {
                println("创建协调节点组:"+array_coordgroups[i].ghosts[j]+"    "+array_coordgroups[i].gport+"    "+array_dbroot[0]+"/coord/"+array_coordgroups[i].gport);
                coordRG.createNode(array_coordgroups[i].ghosts[j], array_coordgroups[i].gport, array_dbroot[0]+"/coord/"+array_coordgroups[i].gport);
        }
}
coordRG.start();
println("删除临时协调节点")
var oma = new Oma(array_coordgroups[0].ghosts[0], port_sdbcm);
oma.removeCoord(port_temp_coord);
println("创建数据节点组")
var db = new Sdb(array_coordgroups[0].ghosts[0], array_coordgroups[0].gport);
var k=0;
for (var i in array_datagroups) {
        var dataRG = db.createRG(array_datagroups[i].gname);
        for (var j in array_datagroups[i].ghosts) {
                println("创建数据节点:"+array_datagroups[i].gname+"    "+array_datagroups[i].ghosts[j]+"   "+array_datagroups[i].gport+"    "+array_dbroot[k]+"/data/"+array_datagroups[i].gport+"    "+array_datagroups[i].goptions)
                dataRG.createNode(array_datagroups[i].ghosts[j], array_datagroups[i].gport, array_dbroot[k]+"/data/"+array_datagroups[i].gport, array_datagroups[i].goptions);
        }
        dataRG.start();
        k++;
}
println("创建域");
var db = new Sdb(array_coordgroups[0].ghosts[0], array_coordgroups[0].gport);
for (var i in array_domains) {
        println("创建域:"+array_domains[i].dname+"   "+array_domains[i].dgroups+"    "+array_domains[i].doptions)
        db.createDomain(array_domains[i].dname, array_domains[i].dgroups, array_domains[i].doptions );
}

STEP7: Create a SequoiaDB cluster

docker exec sdbserver1 su - sdbadmin -c "sdb -f /data/create_cluster.js

Now, SequoiaDB cluster is created and started, and the cluster will start automatically when you start the container.

Conclusion

SequoiaDB uses container technology to achieve rapid cluster deployment, which greatly simplifies the installation and deployment of beginners. Later, the author will also do some optimization on SequoiaDB image production, because the image currently made is a bit large. The main reason is that using the ADD or COPY command to copy the CD-ROM toward the Docker container will generate a new image1, although the finally generated image2 has been deleted CD-ROM, it is above image1, and the size of image2 still contains the CD-ROM. Thus, it is best to use ADD command to copy tar package(ADD automatically decompress ) or use a method as follows:

RUN mkdir -p /usr/src/things \
&& curl -SL http://example.com/big.tar.xz \
| tar -xJC /usr/src/things \
&& make -C /usr/src/things all
Ready to get started with SequoiaDB?