Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Giant Sequoia Tech | use SequoiaDB + Docker + Nodejs to build Web server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The emergence of containerization technology greatly simplifies the work of application developers in building the underlying infrastructure. SequoiaDB Giant Sequoia Database officially launched the Docker containerization deployment scheme in version 3.2.1. This paper will build a simple Web server based on SequoiaDB Giant Sequoia database and Nodejs Docker image.

1. Planning and deployment

We will build a high-availability SequoiaDB sequoia database with three partitions and three copies. At the same time, we will create a MySQL instance of the SequoiaDB giant sequoia database to provide Nodejs as the data source.

Container role

Container name / IP: Port

Partition group

Mirror version

Database coordination node

Coord_catalog/172.17.0.2:11810

SYSCoord

Sequoiadb/sequoiadb:v3.2.1

Database cataloging node

Coord_catalog/172.17.0.2:11800

SYSCatalog

Sequoiadb/sequoiadb:v3.2.1

Data Partition 1 copy 1

Sdb_data1/172.17.0.3:11820

Group1

Sequoiadb/sequoiadb:v3.2.1

Data Partition 1 copy 2

Sdb_data2/172.17.0.4:11820

Group1

Sequoiadb/sequoiadb:v3.2.1

Data Partition 1 copy 3

Sdb_data3/172.17.0.5:11820

Group1

Sequoiadb/sequoiadb:v3.2.1

Data Partition 2 copy 1

Sdb_data2/172.17.0.4:11830

Group2

Sequoiadb/sequoiadb:v3.2.1

Data Partition 2 copy 2

Sdb_data3/172.17.0.5:11830

Group2

Sequoiadb/sequoiadb:v3.2.1

Data Partition 2 copy 3

Sdb_data1/172.17.0.3:11830

Group2

Sequoiadb/sequoiadb:v3.2.1

Data Partition 3 copy 1

Sdb_data3/172.17.0.5:11840

Group3

Sequoiadb/sequoiadb:v3.2.1

Data Partition 3 copy 2

Sdb_data1/172.17.0.3:11840

Group3

Sequoiadb/sequoiadb:v3.2.1

Data Partition 3 copy 3

Sdb_data2/172.17.0.4:11840

Group3

Sequoiadb/sequoiadb:v3.2.1

Database MySQL instance

Mysql/172.17.0.6:3306

-

Sequoiadb/sequoiasql-mysql:v3.2.1

Nodejs Web server

Nodetest/172.17.0.7:3000

-

Node:latest

2. Install the Docker environment

Readers who have installed the Docker environment can skip this chapter. For readers who have not used Docker before, you can install the local Docker environment through this chapter.

Docker can run on most major operating systems, including commonly used Windows, Mac, and multiple versions of Linux.

For Mac users, you can install Docker Desktop for Mac at:

Https://hub.docker.com/editions/community/docker-ce-desktop-mac

For Windows users, you can install Docker Deskop for Windows at:

Https://docs.docker.com/docker-for-windows/install/

For Linux users, you can install it directly using yum or apt-get:

Https://docs.docker.com/install/linux/docker-ce/centos/

Https://docs.docker.com/install/linux/docker-ce/ubuntu/

3. Set up SequoiaDB giant sequoia database cluster.

Download SequoiaDB engine and SequoiaSQL-MySQL database instance locally

Docker pull sequoiadb/sequoiadb: v3.2.1

Docker pull sequoiadb/sequoiasql-mysql:v3.2.1

3.2. Start the database engine container

Docker run-it-d-name coord_catalog sequoiadb/sequoiadb: v3.2.1

Docker run-it-d-- name sdb_data1 sequoiadb/sequoiadb:v3.2.1

Docker run-it-d-- name sdb_data2 sequoiadb/sequoiadb:v3.2.1

Docker run-it-d-- name sdb_data3 sequoiadb/sequoiadb:v3.2.1

Verify the IP address of each container

Docker inspect-- format'{{.NetworkSettings.IPAddress}} 'coord_catalog

Docker inspect-- format'{{.NetworkSettings.IPAddress}} 'sdb_data1

Docker inspect-- format'{{.NetworkSettings.IPAddress}} 'sdb_data2

Docker inspect-- format'{{.NetworkSettings.IPAddress}} 'sdb_data3

The expected output is:

172.17.0.2

172.17.0.3

172.17.0.4

172.17.0.5

Deploy SequoiaDB Giant Sequoia database engine cluster

Docker exec coord_catalog "/ init.sh"\

-- coord='172.17.0.2:11810'\

-- catalog='172.17.0.2:11800'\

-- data='group1=172.17.0.3:11820172.17.0.4:11820172.17.0.5:11820;group2=172.17.0.4:11830172.17.0.5:11830172.17.0.3:11830;group3=172.17.0.5:11840172.17.0.3:11840172.17.0.4:11840'

The expected output is:

Begin generating SequoiaDB conf file

Finish generating SequoiaDB conf file

Restarting sdbcm process, it will take 10 seconds

Deploy...

Execute command: / opt/sequoiadb/tools/deploy/../../bin/sdb-f / opt/sequoiadb/tools/deploy/quickDeploy.js-e''

* Deploy SequoiaDB *

Create catalog: 172.17.0.2:11800

Create coord: 172.17.0.2:11810

Create data: 172.17.0.3:11820

Create data: 172.17.0.4:11820

Create data: 172.17.0.5:11820

Create data: 172.17.0.4:11830

Create data: 172.17.0.5:11830

Create data: 172.17.0.3:11830

Create data: 172.17.0.5:11840

Create data: 172.17.0.3:11840

Create data: 172.17.0.4:11840

Start the MySQL instance container

Docker run-it-d-p 3306 name mysql sequoiadb/sequoiasql-mysql:v3.2.1

3.6. verify the IP address

Docker inspect-- format'{{.NetworkSettings.IPAddress}} 'mysql

The expected output is:

172.17.0. six

Create a MySQL instance

Docker exec mysql "/ init.sh"-port=3306-coord='172.17.0.2:11810'

Enter the IP address and listening port where the coordinator node is located in the coord parameter.

The expected output is:

Creating SequoiaSQL instance: MySQLInstance

Modify configuration file and restart the instance: MySQLInstance

Restarting instance: MySQLInstance

Opening remote access to user root

Restarting instance: MySQLInstance

Instance MySQLInstance is created on port 3306, default user is root

4. Log in to MySQL and create a test table

4.1. get the container ID of the MySQL instance

Docker ps-filter name=mysql-format {{.ID}}

The expected result is the Container ID where the MySQL instance container resides:

Cc17df22a908

4.2.Log in to the MySQL instance command line

Docker exec-it cc17df22a908 "/ opt/sequoiasql/mysql/bin/mysql"-h 127.0.0.1-u root

The-it parameter is the container ID of the MySQL instance, and the expected result is:

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 4

Server version: 5.7.25 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

No entry for terminal type "xterm"

Using dumb terminal settings.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql >

4.3. Create a database and table, and create a test data

Create database sample

Use sample

Create table T1 (C1 varchar)

Insert into T1 values ("SequoiaDB")

Select * from T1

The expected output is:

+-+

| | C1 |

+-+

| | SequoiaDB |

+-+

1 row in set (0.02 sec)

5. Create a Nodejs service

5.1.Create app.js file

Var express = require ('express'); / / introduce express module

Var mysql = require ('mysql'); / / introduce mysql module

Var app = express (); / / create an instance of express

Var connection = mysql.createConnection ({/ / create mysql instance

Host:'172.17.0.6'

Port:'3306'

User:'root'

Password:''

Database:'sample'

});

Var sql = 'SELECT * FROM T1'

Connection.connect ()

App.get ('/', function (req,res) {

Connection.query (sql, function (err,result) {

If (err) {

Console.log ('[SELECT ERROR]:', err.message)

}

Res.send ('Hello:' + result [0] .c1)

});

});

App.listen (3000) function () {/ listen on port 3000

Console.log ('Server running at 3000 port')

});

The host in the code uses the IP address of the MySQL instance.

5.2.Create package.json file

{

"name": "nodetest"

"version": "1.0.0"

"description":

"main": "index.js"

"scripts": {

"test": "echo\" Error: no test specified\ "& exit 1"

}

"author":

"license": "ISC"

"dependencies": {

"express": "^ 4.17.1"

"mysql": "^ 2.17.1"

}

}

5.3.Create Dockerfile file

FROM node:latest

RUN mkdir-p / usr/src/

COPY package.json / usr/src/

COPY app.js / usr/src/

WORKDIR / usr/src/

RUN npm install

# define program default port

EXPOSE 3000

# run the program command

CMD ["node", "app.js"]

5.4. The current directory should contain only three files

$ls-la

Total 24

Drwxr-xr-x 5 sequoiadb staff 160 7 16 15:22.

Drwxr-xr-x 94 sequoiadb staff 3008 7 16 10:50..

-rw-r--r-- 1 sequoiadb staff 206 7 16 12:24 Dockerfile

-rw-r--r-- 1 sequoiadb staff 766 7 16 12:27 app.js

-rw-r--r-- 1 sequoiadb staff 278 7 16 12:03 package.json

5.5.Create Nodejs service image

Docker build-t nodetest.

Running the Nodejs service container

Docker run-d-p 30003000nodetest

Open a browser and connect to the local port 3000

5.8. Change the record in the database, and you can see that the content displayed by the browser is adjusted accordingly.

$docker exec-it cc17df22a908 "/ opt/sequoiasql/mysql/bin/mysql"-h 127.0.0.1-u root

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 7

Server version: 5.7.25 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

No entry for terminal type "xterm"

Using dumb terminal settings.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql > use sample

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changed

Mysql > update T1 set C1 = "Node" where C1 = "SequoiaDB"

Query OK, 1 row affected (0.04 sec)

Rows matched: 1 Changed: 1 Warnings: 0

After refreshing the browser, it displays:

6. Summary

This article shows how to quickly build a Web application through the Docker container of SequoiaDB Giant Sequoia database and Nodejs. The flexible use of distributed database combined with containers can enable users to quickly build a development and test environment and greatly reduce the cost of infrastructure maintenance in the development process.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report