Server offline deployment of docker, image migration, mysql master-slave construction and other services

The company's project is about to go online, bought two cloud servers, and needs to deploy the environment (one access to the public network, one can only be accessed by the LAN), the main deployment is as follows

1. Configure ssh password-free between servers

2. Offline docker deployment

3. docker image migration

4. redis service

5. minio file service

6. kkFileView file preview service

7. Mysql master-slave construction

Table of contents

1. Configure two servers to ssh without encryption, which is convenient for file transfer

2. Offline docker deployment

 3. docker image migration

4. redis service

5. minio file service

6. kkFileView file preview service

7. Mysql master-slave construction

1. mysql master node

2. mysql slave node

3. Problems that arise

1. slave_io_running:connecting solution

 2. slave_io_running: no solution (possible reason: server-uuid master and slave nodes are the same)

3、Slave_SQL_Running: No 


1. Configure two servers to ssh without encryption, which is convenient for file transfer

Configure password-free

1. Change the host and modify the host name

vim /etc/hosts

  Map the IP at the bottom, so that the configured node01 is mapped to 192.168.52.100 

192.168.52.100 node01
192.168.52.101 node02

vim /etc/hostname 

2. Configure password-free, generate the public key and private key of the server ,

 If you are a root user, enter cd /root/.ssh/ 

ssh-keygen -t rsa

3. Copy the public key to node01, and generate an authorized_keys file containing the public keys of the two nodes

ssh-copy-id  node01

4. Copy the generated public key authorized_keys to node02 on node01 

scp authorized_keys node02:$PWD

5. The same operation is performed on node02, and now you can use ssh to log in without password

2. Offline docker deployment

Download address: Index of linux/static/stable/x86_64/

I downloaded the following

Because I uploaded the downloaded docker file to the public network, and then uploaded it to the node02 server outside Ningwai through the LAN.

scp docker-24.0.4.tgz node02:$PWD

1. Unzip the file

tar zxf  docker-24.0.4.tgz 

 2. Copy docker related commands to /usr/bin

sudo cp docker/* /usr/bin/

3. Start the Docker daemon

 sudo dockerd &

4. To verify whether the installation is successful, execute the docker info command. If the version information is printed normally, the installation is successful.

 docker info

5. Create a docker.service file in the /usr/lib/systemd/system/ directory

sudo vi /usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target
 

6. Set docker to boot

systemctl enable/disable docker 

 3. docker image migration

Because the docker in the LAN cannot pull the image remotely, it is necessary to transfer the target server through the LAN after pulling the image file from the public network

1. Package the image of the public network server (I packaged mysql)

docker save mysql:5.7 > /home/soft/mysql5.7.tar

2. Transfer the packaged image to the LAN node02 server

 scp  mysql5.7.tar node02:$PWD

3. Restore the compressed package to a mirror image on the node02 server

docker load < /home/soft/mysql5.7.tar

4. redis service

requirepass: redis password

 docker run --name=redis -p 6333:6379  \
    -v /data/redis/data:/data  \
     -v /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf  \
    -d redis:latest --requirepass 123456 redis-server /usr/local/etc/redis/redis.conf  \
    --appendonly yes

5. minio file service

Pull the latest version, or other versions

docker pull minio/minio

MINIO_ACCESS_KEY: login username

MINIO_ACCESS_KEY: login user password

docker run -p 9000:9000 -p 9090:9090 \
 --name minio \
 -d --restart=always \
 -e "MINIO_ACCESS_KEY=test" \
 -e "MINIO_SECRET_KEY=123456" \
 -v /root/docker/minio/data:/data  \
 -v /root/docker/minio/config:/root/.minio \
 minio/minio  server\
 /data --console-address ":9090" -address ":9000"

6. kkFileView file preview service

kkFileView official website: kkFileView - online file preview

# The network environment facilitates access to the docker central warehouse

docker pull keking/kkfileview:4.1.0

docker run -it -p 8012:8012 keking/kkfileview:4.1.0 

7. Mysql master-slave construction

1. mysql master node

1. Deploy the mysql master node container

docker run -p 3333:3306 --name mysql-master \
-v /mydata/mysql-master/log:/var/log/mysql \
-v /mydata/mysql-master/data:/var/lib/mysql \
-v /mydata/mysql-master/conf:/etc/mysql/conf.d \
-e  MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7

 Catalog description:

-v /mydata/mysql-master/conf:/etc/mysql; mount the configuration folder to the host
-v /mydata/mysql-master/log:/var/log/mysql: mount the log folder to On the host
-v /mydata/mysql-master/data:/var/lib/mysql: mount the data folder on the host

2. Modify the master node my.conf configuration

vim /mydata/mysql-master/conf/my.cnf 

[mysqld] ## Set server_id, unique server_id=101 
is required in the same local area network ## Specify the database name that does not need to be synchronized binlog-ignore-db=mysql   ## Enable binary log function log-bin=mall-mysql-bin   ## Setting Binary log uses memory size (transaction) binlog_cache_size=1M   ## Set the binary log format used (mixed, statement, row) binlog_format=mixed   ## Binary log expiration cleanup time. The default value is 0, which means no automatic cleanup. expire_logs_days=7  










## Ignore case configuration

 lower_case_table_names = 1 
## Skip all errors or specified types of errors encountered in master-slave replication to avoid interruption of slave-side replication.
## Such as: 1062 error means that some primary keys are duplicated, 1032 error is because the master-slave database data is inconsistent
slave_skip_errors=1062

Restart the master node container 

 docker restart mysql-master

3. Enter the master node container and add a synchronization user account

docker exec -it mysql-master /bin/bash

mysql -uroot -p123456

Create sync account 

CREATE USER 'slave' @'%' IDENTIFIED BY '123456';


GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'slave'@'%';

2. mysql slave node

1. Create a slave node container

docker run -p 3334:3306 --name mysql-slave \
-v /mydata/mysql-slave/log:/var/log/mysql \
-v /mydata/mysql-slave/data:/var/lib/mysql \
-v /mydata/mysql-slave/conf:/etc/mysql/conf.d \
-e  MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7

2. Modify the master node my.conf configuration

vim /mydata/mysql-master/conf/my.cnf 

[mysqld] ## Set server_id, unique server_id=122
is required in the same LAN ## Specify the database name that does not need to be synchronized binlog-ignore-db=mysql   ## Enable the binary log function, in case Slave is used as the Master of other database instances log-bin=mall-mysql-slave1-bin   ## Set the binary log memory size (transaction) binlog_cache_size=1M   ## Set the binary log format used (mixed, statement, row) binlog_format=mixed   ## Binary log expiration cleanup time . The default value is 0, which means no automatic cleanup. expire_logs_days=7   ## Skip all errors or specified types of errors encountered in master-slave replication to avoid interruption of slave-side replication. ## Such as: 1062 error means that some primary keys are duplicated, 1032   error is because the data in the master-slave database is   inconsistent Own binary log log_slave_updates=1   ## slave is set to read-only (except for users with super authority)



















read_only=1

## Ignore case configuration
lower_case_table_names = 1 

Restart the child node container 

docker restart mysql-slave

3. Check the Position parameter of the main database. Because there are already some data, it is 5483771. Generally, the position is 443 at the beginning

show master status;

 4. Enter the slave database

docker exec -it mysql-slave /bin/bash

mysql -uroot -p123456

 5. View the master-slave synchronization status in the slave database

show slave status \G

change master to 
master_host='10.0.0.4',master_user='slave',master_password='123456',master_port=3333,
master_log_file='mall-mysql-bin.000002',master_log_pos=684,master_connect_retry=30;

master_host: IP address of the master database;
master_port: running port of the master database;
master_user: user account created in the master database for synchronizing data;
master_password: user password created in the master database for synchronizing data;
master_log_file: specified slave The log file of the database to copy data, by viewing the status of the master data, obtain the File parameter;
master_log_pos: specify the position from which to start copying data from the database, and obtain the Position parameter by viewing the status of the master data;
master_connect_retry: the time for retrying the connection failure Interval, in seconds.

 6. Start the service from the data

start slave;

slave_io_running is responsible for io communication with the host;
slave_sql_running is responsible for its own slave mysql process.

Two yes means success

3. Problems that arise

1. slave_io_running:connecting solution

1. Network failure

Ping the IP of the master node to see if it can be pinged. If the ping fails, check whether the security group or the firewall has opened the ICMP protocol.

2. Whether the slave account can remotely connect to the master node service

docker exec -it mysql-slave /bin/bash

mysql -u slave -p123456 -h10.0.0.4 -P 3333

 3. Check whether the slave node starts the service, whether the command is correct, whether the starting file and starting node are correct, and whether the hostIP is correct

 First stop, then modify, and then start the service

stop slave;

start slave; 

show slave status \G

 2. slave_io_running: no solution (possible reason: server-uuid master and slave nodes are the same)

1. Find the file location

find / -iname "auto.cnf"

2. Enter the file directory and delete the file

rm auto.cnf

3. Restart the child node service

stop slave;

start slave; 

show slave status \G

3、Slave_SQL_Running: No 


1. The program may have written on the slave

2. It may also be caused by the transaction rollback after the slave machine is restarted.

mysql> stop slave ;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> start slave ;

Guess you like

Origin blog.csdn.net/weixin_43288858/article/details/131664353