Docker deployment OKR project replay

Posted by wazo00 on Thu, 20 Jan 2022 19:42:30 +0100

Docker deployment OKR project replay

1, Run OKR project locally

 (1)The problem of Chinese and English garbled code on the home page: the problem of coding logic
 Reference address:
 https://www.cnblogs.com/shihaiming/p/7792876.html
 https://www.cnblogs.com/kingsonfu/p/10395522.html
 
 (2)An exception occurs during database initialization because Mysql of connection Question of
 
 (3)Pictures cannot be uploaded normally. Alibaba's image file configuration is faulty. You need to adjust the configuration

2, Linux common commands, review

  • vi's basic operations, insert, modify, exit, cache files

Reference address: https://blog.csdn.net/kenhins/article/details/50781071

  • Basic operation of sudo role switching

  • Service, the basic operation of systemctl service

  • netstat, ipconfig basic operation of network service

  • Basic operations of yum

  • Use of wget tool

  • Use of compression and decompression

  • Common Docker commands: Reference: https://www.runoob.com/docker/docker-container-usage.html

docker kill 312eac170c03 (docker turns off the image service)
docker run -d -p 8080:8080 tomcat (running Tomcat service to port 8080)
docker run -d -p 80:80 nginx (run Nginx service to port 80)
docker ps (view the running image of docker)
docker ps -a (view all docker services, including those that have been closed)
docker exec -it 312eac170c03 /bin/bash (access the internal image according to the image ID: Method 1)
docker exec -it 312eac170c03 sh (access the image interior according to the image ID: Method 2)
Exit (exit the image and return to the linux Environment)
docker logs --tail 30000 -f wstever (view real-time project output)

Reference address: https://www.cnblogs.com/q4486233/p/6482711.html

(a series of operations to delete images and containers, because there will be a problem of container occupation, ignore the ID, which is just a hint here)
docker stop 9df85803323b
docker kill 9df85803323b
docker rmi 3218b38490ce
docker rm -f d05460bd8127

  • history related commands

cd ~
ls -a
history > okr_ deploy. Txt (redirect the contents of history to the file)

3, Use alicloud's lightweight server operation to add ports that you need to open

(1) You can directly enter the service through the web side
ifconfig (check the IP address of the machine and test to see if it is an IP address problem)

(2) Connect directly through putty or xshell client. Note: be sure to add the root password

(3) Use the terminal to view the address:

(4) Port number of open firewall:
The project includes:

  • 8080: tomcat port (for test)
  • 80: nginx port (for test)
  • 3306: mysql service external port
  • 8088: external port of OKR project

Note: Port 8080 must be opened to the outside world, otherwise it cannot be accessed outside. The setting address is at the firewall.
service firewalld stop

4, Install JDK on alicloud lightweight ECs

cd opt (Switch to opt (in directory)
mkdir java(New folder Java)
cd java(Switch to java (in directory)

Failed (method 1: want to pass wget Go download jdk1.8,After downloading, it is found that it cannot be decompressed!)
wget http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
tar -zxvf jdk-8u131-linux-x64.tar.gz(Decompression attempt (1)
tar -xvf jdk-8u131-linux-x64.tar.gz(Decompression attempt (2)

Success (method 2: want to pass yum Go download jdk1.8)
yum list java* (see java Source)
yum list java8 (see java8 (source of)
yum install java-1.8.0-openjdk* -y (install java8 (source of)
java -version(Verify whether the download is successful)
javac -version(Verify whether the download is successful)

5, Install Docker and pay attention to the daemon JSON can be written in Alibaba cloud

reference resources: https://www.cnblogs.com/jim-xu/p/11788726.html

yum install docker (use yum To install docker)
service docker start (start-up Docker If the service starts abnormally, it is likely that daemon.json (incorrect preparation of)
service docker start
docker version (see docker (installed successfully)
vi /etc/docker/daemon.json (to write docker of daemon.json,(mirror file)
cd /etc/docker (visit docker (directory of configuration file)
vi daemon.json(to write daemon.json (file)
systemctl daemon-reload (restart docker of daemon.json,Image file)
systemctl restart docker.service(restart docker (services)
docker logs --tail  30000 -f  burt(View the output of the internal operation of the service)

6, (for testing) install Nginx and open port 80 for external access

docker search nginx (Check for Nginx (mirror image of)
docker pull nginx(Pull Nginx (mirror of)
docker image ls(View the list of all images: mode 1)
docker images(View the list of all images: mode 2)
yum install -y libseccomp-devel  (Installation dependency. An error will be reported if the plug-in is missing cannot start a stopped process: unknow) 
docker run -d -p 80:80 nginx (function Nginx,Open 80 ports)
docker ps(View the currently running image content)
netstat -tunlp |grep 80(Check whether the 80 port number is Nginx Occupied? Or port conflict)
docker exec -it 312eac170c03 /bin/bash(Access to Nginx Internal container: mode 1)
docker exec -it 312eac170c03 sh(Access to Nginx Internal container: mode 2)

Directly access port 80 externally to verify whether the installation is successful? Because this port has been opened by default, it can be accessed

7, (for testing) install Tomcat and open port 8080

Reference address:
https://blog.csdn.net/u011374582/article/details/82867242
https://www.cnblogs.com/jxldjsn/p/10540549.html
https://www.cnblogs.com/xiaozhang666/p/12382114.html

docker ps  (View current)
docker pull tomcat (go docker Middle pull tomcat)
docker images (View all docker Mirror image)
docker run -d -p 8080:8080 tomcat (function Tomcat)
sudo docker run -d -p 8080:8080 tomcat (switch root User to run Tomcat)
yum update (May need to be yum File update takes a long time)
docker exec -it 312eac170c03 sh (get into Tomcat Container interior: mode 1)
docker exec -it 312eac170c03 /bin/bash(get into Tomcat Container interior: mode 2)
wget http://www.localhost:8080 (test this function to see if it can normally access the interior of Tomcat)
docker restart 312eac170c03(Restart mirror service)

8, Deploy Mysql project in Docker

reference resources:
https://blog.csdn.net/u013068184/article/details/89434781
https://blog.csdn.net/You_are_my_Mr_Right/article/details/100512956
https://blog.csdn.net/qq_35868412/article/details/82874778

Note 1: because of Alibaba cloud's services, the company's internal Mysql services cannot be linked. You can only install another Mysql service.

Note 2: be sure to install mysql version 5.7 or lower to prevent the exception that the remote client cannot be linked.

(1) Failed attempt: install the latest mysql. The latest version of MySQL has security restrictions

Reference address: https://www.cnblogs.com/zhurong/p/9898675.html

docker pull mysql:latest (Pull (latest)
docker images(View all images to see if the latest version of is installed Mysql)
docker run -d --name wstever -p 8088:8088 burt/demo (Deployment project)
docker logs --tail  30000 -f  wstever(If you view the real-time output, there will be Mysql (error report on link failure)
docker images(Check all the images and find that the latest version is installed mysql,Local client link exception)
docker run -itd --name mysql-burt -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Aa123456 mysql(docker function mysql (latest version)
docker ps((check whether the installation is successful)
docker exec -it mysql-burt bash(get into mysql-burt (internal) 
> mysql -h localhost -u -root -p(Execute internally, view mysql (version number of)

(A series of operations to delete images and containers are ignored because of the problem of container occupation ID,(only for illustration)
 docker stop 9df85803323b
 docker kill 9df85803323b
 docker rmi 3218b38490ce
  docker rm -f d05460bd8127

(2) Wrong attempt: case sensitive problem. There is no vi problem inside the terminal in Mysql

(1) Case sensitivity in Linux and Windows is encountered, which will cause exceptions to uppercase tables in Quartz
See the address for detailed problem description: https://www.cnblogs.com/z_lb/articles/8352013.html
https://blog.csdn.net/ohh_lang/article/details/120542797
https://blog.csdn.net/p793049488/article/details/108365929
Important: in this way, it is best to back up the data to prevent loss.

find / -name my.cnf
vi /etc/mysql/my.cnf

(2) There is no vi inside the terminal in Mysql. You need to install vim to modify the Mysql configuration file (wrong attempt)
Reference address: https://blog.csdn.net/weixin_32301287/article/details/113639464

(3) Successful attempt: install mysql version 5.7 and configure it to the file when running

docker pull mysql:5.7(Pull mysql5.7 (mirror of version)
docker images(docker Mirror view)
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Aa123456 --name mysql-wst mysql:5.7 --lower-case-table-names=1 (function docker Mirror image)
docker ps(Check for normal operation mysql Service)
docker exec -it mysql-wst bash(Run in mysql (inside container)
mysql -uroot -p(Enter into mysql You should enter the database password to test whether you can log in to the database normally mysql)

The referenced commands are as follows:

Other steps include:

  1. The local Navicat client links to the remote Mysql service

  2. Check whether the case problem can be ignored

  3. Change the database pointed to by the code to a remote data service

  4. Re project file and publish docker service

docker build -t burt/demo . (Rebuild project)
docker run -d --name burt -p 8088:8088 burt/demo ((running project)
 docker logs --tail  30000 -f  burt (View the real-time output of the project)

9, Maven forms a jar package and deploys the OKR project to Docker

Reference address: https://blog.csdn.net/cookie_turbo/article/details/105274606

(1) After maven operates the clean, install and package steps, generate a jar file and access the target directory to get the jar package
(2) Upload the jar package to the server directory through the terminal
(3) Write a dockerfile file (in the peer directory)

Refer to the following dockerfile file, dockerfile file reference

(4)

cd /opt/java/ (Access to the specified directory, dockerfile (also uploaded to the current directory)
docker build -t burt/demo .(Run build docker Our services, le (file of)
docker run -d --name burt -p 8088:8088 burt/demo((running project)
docker run -d --name wstever -p 8088:8088 burt/demo (Maybe the name is repeated, you can change it)
docker run -d --name wst -p 8088:8088 burt/demo (Maybe the name is repeated, you can change it)
docker ps(see docker Whether the service has been accessed normally)
docker logs --tail  30000 -f  burt(View real-time output)
docker logs --tail  30000 -f  wstever(View real-time output)
docker logs --tail  30000 -f  wst (View real-time output)
docker kill burt(close docker (services)
docker kill wstever(close docker (services)
docker kill wst(close docker (services)
docker ps(View again docker Whether the service has been shut down normally)
docker ps -a (View all docker Services, including those that have been closed)

10, Summary

(1) Docker is very easy to use, reducing many complex configuration problems
(2) If the code has no ideas, you can find inspiration Baidu
(3) In fact, there is nothing about ECs. One terminal can handle it!
(4) Markdown file is still good. Keep it!
(5)Mysql5.7 version is used by many people for a reason!
(6) It's good to use history in Linux to copy the code.

Topics: Linux Operation & Maintenance Docker