Docker deploys Mysql, .Net6, Sqlserver and other containers

Docker deploys Mysql, .Net6, Sqlserver and other containers

Install Docker on CentOS 8

1. Update yum

[root@VM-24-9-centos ~]# yum -y update

2. Install containerd.io

# centos8 uses podman instead of docker by default, so containerd.io is required
[root@VM-24-9-centos ~]# yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm -y

# Install some other dependencies [root@VM-24-9-centos ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@VM-24-9-centos ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install Docker

[root@VM-24-9-centos ~]# yum install -y docker-ce

4. Start Docker

# Start Docker
[root@VM-24-9-centos ~]# systemctl start docker
# Set to start automatically at boot [root@VM-24-9-centos ~]# systemctl enable docker

5. Set the container to start automatically

[root@VM-16-7-centos ~]# docker update --restart=always Container name --restart Specific parameter value details:
	no: Do ​​not restart the container when the container exits on-failure: Restart the container only when the container exits with a non-zero status always: Restart the container regardless of the exit status

Mysql8.0 deployment

1. Pull the image

[root@VM-24-9-centos ~]# docker pull mysql
# If you need to pull a specific version of the image, add the version number: [root@VM-24-9-centos ~]# docker pull mysql:7.6

2. Create a local file for mounting

[root@VM-24-9-centos ~]# mkdir -p /data/mysql/data
[root@VM-24-9-centos ~]# mkdir -p /data/mysql/conf
[root@VM-24-9-centos ~]# mkdir -p /data/mysql/conf/conf.d

3. Start a container and copy the configuration file /etc/mysql/my.cnf in the container to our local computer for the default configuration file

# Start a container to copy the configuration file [root@VM-24-9-centos ~]# docker run -d -p 3306:3306 --name mysqlone mysql:latest
07c314a5e57c3a3ca8ab8ffe5937b4fdb6c87a831b7e15666ee7266feb5af42a
[root@VM-24-9-centos ~]# docker cp mysqlone:/etc/mysql/my.cnf /data/mysql/conf/

# Stop and delete the container [root@VM-24-9-centos ~]# docker stop mysqlone
mysqlone
[root@VM-24-9-centos ~]# docker rm mysqlone
mysqlone

# Check whether the configuration file is copied successfully [root@VM-24-9-centos ~]# cd /data/mysql/conf/
[root@VM-24-9-centos conf]# ls
my.cnf

4. Use local configuration files to mount the configuration files in the container and mount the data files

docker run -d -p 3306:3306 --name mysqlmaster -e MYSQL_ROOT_PASSWORD='jing1996' -v /data/mysql/conf:/etc/mysql -v /data/mysql/data:/var/lib/mysql mysql

Mysql8.0 deployment master-slave replication

1. Write the configuration file

[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/
server-id=1
log-bin=mysql-bin
binlog-do-db=morin
binlog-ignore-db=mysql
  • server-id: Server ID. They cannot be the same.
  • log-bin: Binary file storage path, not required, after mysql8, it is stored in /var/lib/mysql by default
  • binlog-do-db: The databases that need to be synchronized. If there are multiple databases, separate them with spaces: db1 db2 db3
  • binlog-ignore-db: If there are multiple databases that do not need to be synchronized, separate them with spaces: db1 db2 db3

2. Node configuration

2.1 Master Node Configuration

# Add a database account for synchronization CREATE USER 'rootslave1'@'110.40.158.72' IDENTIFIED WITH mysql_native_password BY '123456';
# Authorize grant replication slave on *.* to 'rootslave1'@'110.40.158.72';
# Refresh configuration FLUSH PRIVILEGES;
# Query all select user,host from mysql.user;
#Query the master node status show master status;

2.2 Slave Node Configuration

# Configure master-slave synchronization change master to master_host='xxxx',master_user='rootslave1',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=2384;
# Enable synchronization start slave;
# View the slave node status show slave status;

Note:

  • The master_log_file and master_log_pos parameters for configuring master-slave synchronization are based on the query master node status command in the master node configuration. The parameters here are copied directly for use
  • After starting the synchronization, check the slave node status. You must ensure that Salve_IO_Running and Salve_SQL_Running are Yes for the synchronization to succeed. If it is No, it usually means that the values ​​of the two fields mentioned above are incorrect.

If the database to be synchronized already exists in the master database, it will not be automatically synchronized. It is recommended to keep the data and delete the database and rebuild it, and it will be automatically synchronized to the slave database.

.Net6 project released

1. Publish the project in VS and write the Dockerfile file

The contents of the Dockerfile are as follows:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 8989

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .

ENTRYPOINT ["dotnet", "x.API.dll"]

2. Build the image

Copy the release files (including Dockerfile files) to the Centos server, and then build the image in the current directory

[root@VM-0-17-centos conf]# docker build -t image name: version number.

eg:注意最后有個小點. This點指的是Dockerfile文件所在的目錄. If it is in the current directory, it is. In other directories, you must enter the full directory path.

3. Build the container and mount the configuration file

[root@VM-0-17-centos conf]# docker run -d -p 9999:9999 -v /usr/local/release/project/appsettings.json:/src/appsettings.json --name projectapi project:1.0

Sqlserver deployment

Prerequisites:

  • The server needs more than 2G of memory. If it is not enough, it may not start properly

1. Get the sqlserver image

[root@VM-24-9-centos ~]# docker pull mcr.microsoft.com/mssql/server:2019-latest

2. Create data files for data mounting

[root@VM-24-9-centos ~]# mkdir -p /data/sqlserver/data

# Modify the directory permissions. If you do not modify the permissions, an error will be reported [root@VM-24-9-centos ~]# chown -R 10001:0 /data/sqlserver/data/

3. Run the container

[root@VM-24-9-centos sqlserverdata]# docker run -d -p 1433:1433 -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=sa123456.?' -v /data/sqlserver/data:/var/opt/mssql --name sqlserver mcr.microsoft.com/mssql/server:2019-latest

Note:

  • ACCEPT_EULA=Y means agree to the license agreement, required
  • MSSQL_SA_PASSWORD is the password. It must be a strong password of at least 8 characters, with uppercase letters, lowercase letters, numbers, and special symbols. Otherwise, Docker will stop after a few seconds after starting the SQL Server container.
  • When using navcat to connect, the port number and IP address are separated by commas instead of colons.
  • The created data mount directory needs to modify permissions

ElasticSearch Cluster Deployment

Deploy ElasticSearch

1. Pull images and generate configuration files in batches

# Pull the image [root@VM-24-9-centos ~]# docker pull elasticsearch:7.2.0

# Generate configuration files and directories for port in $(seq 1 6); \
do \
mkdir -p /data/es/node-${port}/conf
mkdir -p /data/es/node-${port}/data
mkdir -p /data/es/node-${port}/plugins
chmod 777 /data/es/node-${port}/data
touch /data/es/node-${port}/conf/es.yml
cat << EOF >>/data/es/node-${port}/conf/es.yml
cluster.name: lbj
node.name: node${port}
node.master: true
node.data: true
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 920${port}
transport.tcp.port: 930${port}
discovery.seed_hosts: ["xxxx:9301","xxxx:9302","xxxx:9303","xxxx:9304"]
cluster.initial_master_nodes: ["node1","node2","node3","node4"]
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
EOF
done;

2. Create containers in batches and view cluster information

# Batch create containers for port in $(seq 1 4); \
do \
docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-d -p 920${port}:920${port} -p 930${port}:930${port} \
-e ES_MIN_MEM=128m \
-e ES_MAX_MEM=2048m \
-v /data/es/node-${port}/conf/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /data/es/node-${port}/data/:/usr/share/elasticsearch/data/ \
-v /data/es/node-${port}/plugins/:/usr/share/elasticsearch/plugins \
--name ES-${port} \
elasticsearch:7.2.0
done

# View single node information [root@VM-24-9-centos ~]# curl http://xxxx:9201/
{
  "name" : "node1",
  "cluster_name" : "lbj",
  "cluster_uuid" : "Vjb7cu6fQ6y2-ZWk0YGIiQ",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

# View cluster information [root@VM-24-9-centos ~]# curl http://xxxx:9201/_cat/nodes?pretty
172.17.0.2 37 97 0 0.00 0.00 0.08 mdi * node1
172.17.0.4 35 97 0 0.00 0.00 0.08 mdi - node3
172.17.0.3 39 97 1 0.00 0.00 0.08 mdi - node2
172.17.0.6 34 97 1 0.00 0.00 0.08 mdi - node4

Deploy ElasticSearch-Head

ElasticSearch-Head is a management interface where you can view ElasticSearch related information

1. Pull the ElasticSearch-Head image

[root@VM-24-9-centos ~]# docker pull mobz/elasticsearch-head:5

2. Run the ElasticSearch-Head container

# Create container [root@VM-24-9-centos ~]# docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5

# Access IP:9100 from PC to view cluster information using management tools

This concludes this article about deploying Mysql, .Net6, Sqlserver and other containers with Docker. I hope it will be helpful for everyone’s study, and I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Install SQL Server database on Linux system through Docker
  • Detailed steps for deploying Microsoft Sql Server with Docker
  • Implementation of Docker deployment of SQL Server 2019 Always On cluster
  • Implementation of running SQL Server using Docker
  • How to run Microsoft SQL Server 2017 using Docker
  • Deploy MSSQL in a Docker container

<<:  Three ways to jump to a page by clicking a button tag in HTML

>>:  CSS uses position + margin to achieve the method of horizontal and vertical centering of fixed boxes

Recommend

How to set up PostgreSQL startup on Ubuntu 16.04

Since PostgreSQL is compiled and installed, you n...

RGB color table collection

RGB color table color English name RGB 16 colors ...

How to query and update the same table in MySQL database at the same time

In ordinary projects, I often encounter this prob...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...

mysql5.7.21.zip installation tutorial

The detailed installation process of mysql5.7.21 ...

Detailed explanation of the use of Join in Mysql

In the previous chapters, we have learned how to ...

How to clear the cache after using keep-alive in vue

What is keepalive? In normal development, some co...

HTML table tag tutorial (25): vertical alignment attribute VALIGN

In the vertical direction, you can set the row al...

A brief analysis of HTML space code

How much do you know about HTML? If you are learni...

html page!--[if IE]...![endif]--Detailed introduction to usage

Copy code The code is as follows: <!--[if IE]&...

Summary of pitfalls in virtualbox centos7 nat+host-only networking

Table of contents 1. Problem Background 2. What a...

CSS to implement sprites and font icons

Sprites: In the past, each image resource was an ...