2020 system comprehensive practice first practice operation

1. Course Survey

When I saw this course during the course selection last semester, I thought it was a pure hardware course, and I felt like running lights and running lights. In the first class, I was a little scared when I mentioned the software engineering of the last semester when I was introduced by the teacher. I also used the same blog system. Subconscious prayer will not be a very time-consuming class (after all, I am going to take the postgraduate study ). The teacher mentioned that this course is divided into three parts, docker, raspberry pi and the final comprehensive homework, personally I still look forward to it, docker and raspberry pi have heard of it before, and it is pretty cool, this time finally You can experience it yourself. The teacher gave us a few learning links to let us toss ourselves. Individuals are not very accustomed to this kind of stocking education, and they have to get out of their comfort zone and rush.

2. Understand microservices

1. What is a microservice

Microservice architecture is an architectural model that advocates the division of a single application into a set of small services. The services coordinate and cooperate with each other to provide users with ultimate value. Each service runs in its own process, and a lightweight communication mechanism is used to communicate with each other (usually HTTP-based Restful API). Each service is built around a specific business and can be Independent deployment to production environment, production-like environment, etc. In addition, a unified and centralized service management mechanism should be avoided as much as possible. For a specific service, it should be constructed according to the business context by selecting the appropriate language and tools.

2. Features of microservices

  • Small intensity and focus on one thing
  • Separate process
  • Lightweight communication mechanism, usually HTTP / REST interface
  • Loosely coupled, can be deployed independently

3. Advantages of microservices

  • Improve development communication, each service is cohesive enough, small enough, and the code is easy to understand
  • Independent service testing, deployment, upgrade, release
  • Customized DFX, resource utilization, each service can be independently x-scaled and z-scaled, and each service can be deployed to a suitable hardware server according to its needs
  • Need to choose HA mode, select the number of instances to receive services
  • Easy to expand the development team, you can develop the team for each service (service) component
  • Improve fault isolation (fault isolation), memory leak of a service does not paralyze the entire system
  • The application of new technologies, the system will not be restricted to a certain technology stack for a long time

4. Disadvantages of microservices

  • Without silver bullets, microservices increase the complexity of the system

  • Developers have to deal with the complexity of distributed systems

  • Distributed communication problems between services

  • Service registration and discovery problems

  • Distributed transaction issues between services

  • Report processing problems with data isolation

  • Distributed consistency issues between services

  • Service management complexity, service orchestration

  • Management of different service instances

5. Deployment of microservices

  • One host deploys multiple service instances
  • One service instance per host
  • One service instance per container
  • Loosely coupled, can be deployed independently

3. Learn docker technology

1. Related concepts of docker

  • docker: allows developers to package their applications and dependent packages into a portable image, and then publish to any popular linux or windows machine, can also be virtualized
  • docker compose: can easily and efficiently manage containers, it is an application tool for defining and running multi-container Docker
  • Dockerfile: The most common way to create an image in Docker is a description file for a Docker image
  • docker machine: a tool that allows you to install Docker on a virtual host and use the docker-machine command to manage this host
  • Swarm: provides Docker container cluster service, is the core solution of Docker official support for container cloud ecological image
  • k8s: Open source container cluster management system, which can realize automatic deployment, automatic expansion and contraction, maintenance, etc. of container clusters

2. Build your own docker environment

The environment used for this assignment is ubuntu 18.04 LTS

1. Ubuntu Docker installation

Update apt package index

sudo apt-get update

Install apt dependency package, used to obtain the repository through HTTPS

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Add Docker's official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Use the following instructions to set up a stable version of the warehouse

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

Update apt package index

sudo apt-get update

Install the latest version of Docker Engine-Community and containerd

sudo apt-get install docker-ce docker-ce-cli containerd.io

Test whether Docker is installed successfully

sudo docker run hello-world

At this point, docker is finally installed

2. Mirror acceleration

When I saw a teacher on station B explaining docker, it said that when pulling the image from dockerhub, it would be slower. It is better to speed up the whole one. At that time, it was demoed by Alibaba Cloud, so I also imitated it
first. Alibaba Cloud account https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
and then get its own Alibaba Cloud acceleration address

Configure the image accelerator, you can use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["自己的加速器地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

3. Use of containers

This is a case in the rookie post. Following the tutorial step by step gave me a preliminary impression of the operation of docker.
Use the docker run command to run an application in the container. Here I first checked the image of the machine and found that it is not If it exists, go to the mirror warehouse to download the mirror, then create a container, execute bin / echo "Hello world" in the container and output the result

docker run ubuntu:15.10 /bin/echo "Hello world"

To run an interactive container, we use the two parameters of docker -i -t to enable the container that docker runs to achieve the ability of "dialogue", -t: specify a pseudo terminal or terminal in the new container, -i: allows you to Interact with the standard input (STDIN) in the container, you can exit the container through exit

docker run -i -t ubuntu:15.10 /bin/bash

Create a container that runs as a process. Unlike the previous method, it works in the background and the output is the full version of the container id

docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"

View running containers

docker ps

Use the container id to view the standard output of the container

Docker logs 7a3aa39a4291

Use the docker stop command to stop the container. When you look at the running container again, the id just found is not found.

docker stop 7a3aa39a4291

When starting the container in a process, you can use the attach method to enter the container

docker attach 1e560fca3906 

There are two ways here, one is exit and the other is exec, the difference is that the former will cause the container to stop when exiting the container, the latter will not

docker exec -it 3dd2895db7ed /bin/bash

Export and import containers

docker export 3dd2895db7ed > ubuntu.tar
cat ubuntu.tar | docker import - test/ubuntu:v1

Delete container

docker rm -f 3dd2895db7ed

4. Use of mirror

Use the docker search command to search the image

docker search httpd

Use the docker pull command to download the image

docker pull httpd

To delete an image, first stop all containers, then delete the container, and finally delete the specified image

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi hello-world

To update the image, first create a container, use the apt-get update command to update, and use docker commit to submit the container copy after exiting the container

docker run -t -i ubuntu:15.10 /bin/bash
apt-get update

Submit a copy of the container with the command docker commit

docker commit -m="has update" -a="runoob" 5a230ff0a626 runoob/ubuntu:v2

Create a container, that is, update the container

docker run -t -i runoob/ubuntu:v2 /bin/bash    

Query container information

docker inspect be5bdc4f013c

5. Warehouse management

Because the docker hub is too slow, I chose Alibaba Cloud Mirror to
first establish an open warehouse in Alibaba Cloud

Then log in to Alibaba Cloud in docker

sudo docker login --username=郑裕恒 registry.cn-hangzhou.aliyuncs.com

Pull image from Registry

sudo docker pull registry.cn-hangzhou.aliyuncs.com/dyssl/dyssl:[镜像版本号]

Push the image to the Registry

sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/dyssl/dyssl:[镜像版本号]
sudo docker push registry.cn-hangzhou.aliyuncs.com/dyssl/dyssl:[镜像版本号]

Then you can see that it has been successful on Alibaba Cloud

Guess you like

Origin www.cnblogs.com/dyssl/p/12683565.html