Article directory
-
- 1. Initial Linux
- 2. Create a new virtual machine
- 3. Install Linux in the virtual machine
- 4. Set up the network
- 5. Install Xmanager5 tool
- 6. Initial Docker container
- 7. Use Docker to install software
- 8. Deployment projects
-
- 8.1 One-click deployment of the backend into the Docker container
- 8.2. Initial Nginx
-
- 1. Introduction to Nginx
- 2. Installation of Nginx reverse proxy server
- 3. Nginx configuration
- 4. Deploy the litemall front-end to Linux
1. Initial Linux
1.1 Materials provided
1.1.2 Material download
1.2 Introduction to Linux
1.2.1 The difference between Linux and Windows
Linux is an operating system.
Server project deployments are all placed on the Linux operating system.
Windows is an operating system developed by Microsoft. It is a civilian operating system and can be used for entertainment, audio and video, and Internet access. The Windows operating system has a powerful logging system and powerful desktop applications . The advantage is that it can help us achieve a lot of colorful effects, and it is very convenient for entertainment, audio and video, and Internet access. However, if Windows is turned on and is not turned off for ten days or half a month, you will find that the computer becomes extremely stuck when you operate it again. This is because the Windows operating system's continuous logging and desktop rendering occupy a large amount of system resources .
For example : the application server (tomcat) is installed on the Windows operating system, and a project is deployed on tomcat. It may be relatively smooth for the first ten days, but then it becomes stuck after ten days, and then it freezes. Some people say that it is a big deal to restart the Windows operating system, but during the restart period, a large number of users may be lost , causing a lot of losses.
1.2.2 Virtual machine
Introduction to virtual machines
Virtual machine: It is a virtual computer, a computer virtualized by software.
When you open a notepad software on your computer, is the notepad software you open really the notepad you have? No, it is a virtual notepad that can simulate a real notepad . For example, record some text.
Now when I open a drawing software, do I really have a drawing board in my hand? No, it is a drawing board virtualized using software, which can achieve the same functions as a real drawing board.
As shown in the figure below, in the Windows operating system, you can run drawing and notepad software, and you can also run virtual machine software. When the virtual machine software is turned on, the virtual machine software is equivalent to an independent small computer , so in This independent small computer has a virtual CPU, memory, hard disk, and keyboard ( whatever is on your computer will be on this virtual computer .). Next, you can install the Linux operating system on the virtual machine.
Advantages : Install the Linux operating system on a virtual machine. If the Linux operating system is damaged by you, it will not affect the external Windows operating system. You only need to reinstall a Linux operating system on the virtual machine .
Uninstall VMWare virtual machine software
- Install VMWare virtual machine software
3.
4.
5.
6.
7.
2. Create a new virtual machine
Open VMware, go to the upper left corner of the current window - "File -" Create a new virtual machine
1.
2.
3.
Next, set the directory and name of the virtual machine configuration file:
4.
I put it here on the D drive, which requires that the available memory of the D drive is more than 20 G.
5.
6.
After clicking [Customize Hardware] in the picture above, the memory is allocated to 2 G and the number of processor (CPU) cores is one in the picture below.
Select CD/DVD (IDE), check [Use ISO image file] on the right side of it à browse à select CenterOS provided in the material.
Then click Close and Done. Then the computer virtualized using the software is created. The created virtual machine is as shown in the figure below.
3. Install Linux in the virtual machine
- Click [Start this virtual machine] in the picture below
- When turned on, the virtual machine will automatically read the virtual optical drive we inserted before. Then press the Enter key.
Note : alt + ctrl can switch the mouse out of the virtual machine.
- After waiting for a while, the interface shown below will pop up.
- Click [Keyboard] in the picture below —»+ —»English (US) —»Add —»Done (D)
- Click [Language Support (L)] in the picture below —》English —》English(United States)
-
Then select System -> Set installation location in the lower left corner.
Select the partition I want to configure in the picture below -> then click "Finish" in the upper left corner
- Select the standard partition in the drop-down box in the figure below -> Then click the + sign in the lower left corner à Enter the mount point as swap in the pop-up window , and the expected container is 2GB -> Then click the Add mount point button.
- Then click the + sign in the lower left corner to add a /partition with a size of 20GB. This time click to add a mount point and directly click the Done button in the upper left corner.
- Click Finish -> Accept changes
- After returning to the previous window, select the "Start Installation" button in the lower right corner to install Linux.
- In the picture above, click the first icon to create a ROOT password. The first icon creates a user. My Root password is set to 123456 .
ROOT password
Create user
Open the "Complete Configuration" button in the lower corner. After restarting , the entire Linux installation is completed.
After the virtual machine is restarted, some related processes will be killed. After that we can log in to our Linux.
When logging in, because Linux focuses on stability, security, and efficiency, you cannot see the password when you enter it .
Enter username and password. Then press Enter.
[root@Linux-01 ~]#
Detailed explanation: root is to log in as the root user
Linux-01 is the hostname
~ means I am currently in the root directory
# means waiting for the user to enter a command.
Question : If after entering the ip addr command and pressing Enter, the IP address does not appear, but 127.0.0.1, then the network needs to be reset.
4. Set up the network
Use the vi command vi /etc/sysconfig/network-scripts/ifcfg-ens33 and press Enter to edit the ifcfg-ens33 network configuration file. Change the value of ONBOOT in the figure below from no to yes. Press i,o to edit
Note : ens33 in the above picture is the network configuration file name.
Use the Esc key to exit. Use the :wq command to exit editing and save the file.
a) Use the service network restart command to restart the network. Then enter ip addr.
As shown above, we can see that my IP address is LinuxIP .
5. Install Xmanager5 tool
- Double-click the Xmanager5 installation package in the material.
Then continue to the next step until the following picture appears.
- Enter your company name in the image below and copy the product key from the source material.
- After that, keep going to the next step - "Install." There will be a file as shown below on the desktop.
- Double-click the icon shown above on the desktop. In the pop-up window, we can access the Xftp and Xshell tools. These two tools are our most commonly used remote tools.
The installation of the Linux remote connection tool/client is now complete.
5.1 Use Linux client to connect docker run -d -p 8081:8081inux server for command operation
Here we use the previous Xshell for the Linux client. Usage steps ( install the Xmanager5 tool in advance )
- Open Xshell and fill in the name and host (your own Linux IP address).
Enter your own Linux IP address into the host in the picture above .
- After clicking the "OK" button in the above picture, select the newly created connection in the pop-up window - "Click the link button.
- Enter the username of the Linux system.
- Enter the password for the Linux system.
- The connection is successful, as shown in the figure below.
6. Initial Docker container
6.1 Docker concept
Docker is a virtualization container technology. Docker is based on images and can start various containers in seconds. Each container is a complete running environment (each container embeds a Linux), and the containers are isolated from each other.
Analysis :
In the past, when we installed mysql or redis in Linux, the installation steps were relatively cumbersome, such as following the compiled source code step by step, compiling and then executing, starting the service, etc., which was very troublesome. And if a problem occurs during the operation of a certain software and affects the Linux system, other software installed by Linux, such as MySQL, may also have problems. With docker, these problems are no longer a problem.
Docker is based on mirroring, so what is a mirror? Here is an example. When we installed the window operating system in the past, we could go to System Home or Yulin Mufeng to download a window system, use a U disk to enter the PE system, and then install the computer Partition the disk, then install it with one click. Wait until the system is installed. After restarting the system, install the learning tools, chat tools, games, etc. you need in the new system. The entire window will be installed. If there is a problem with the window one day, we have to reinstall the system according to the previous process, which is really screwed up. The system of an Internet cafe is an image file , which encapsulates the window system, learning tools, and chat tools. When we install the system, if we select this system image file, we can install it with one click and wait slowly until the system is installed. , after restarting, we will find that the new system has all learning tools and chat tools.
Docker can go online to obtain the image file of related software. After obtaining the image file, Docker can start a container directly based on the image file. This container is the complete operating environment of the image. So if we want to install a certain operating environment in the future, we only need to install docker in Linux and let docker go to the image market to download the image files corresponding to the relevant software.
In the picture above, Registry is the image market. We use DOCKER_HOST (docker container) to the image market https://hub.docker.com/ to pull the image files of relevant software into the docker container. The current docker can be listed in images. All image files in the container, and each image file can start multiple containers, and multiple containers can form a cluster. Each container is a complete operating environment, and the containers are isolated from each other.
After introducing docker, we will install docker in linux.
6.2 Install Docker
Docker installation documentation: https://docs.docker.com/install/linux/docker-ce/centos/
6.2.1 Uninstall the old docker in the Linux operating system (if it was installed before)
Older versions of Docker are called docker or docker-engine. If these programs are installed, uninstall them and their associated dependencies.
Command : (If you are not using root to log in to Linux, add sudo before the following command, which means running as an administrator)
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
After entering the above command, yum reports that these software packages are not installed, and you can proceed with subsequent docker installation.
6.2.2 Installing using a repository
Before installing Docker Engine on a new host for the first time, you need to set up a Docker repository. After that, you can install and update Docker from the repository.
Set up a repository
Install the yum-utils package (which provides the yum-config-manager utility) and set up a stable repository.
sudo yum install -y yum-utils
或
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2123
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo 国外
或
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 国内
Solving problems when downloading docker images
6.2.3 Install Docker engine
1. Install the latest version of Docker Engine and containers.
Order:
sudo yum install docker-ce docker-ce-cli containerd.io
2. Start docker
sudo systemctl start docker
3. Verify Docker is installed correctly by running docker -v and docker images
4. Set docker to start automatically when booting
sudo systemctl enable docker
At this point, the docker installation is complete.
6.2.4 Configuring image acceleration for Docker
If Docker wants to download the image files of related software, it will go to the image market by default , and this docker hub is a foreign website. Downloading image files from foreign websites will be slower. We configure Alibaba Cloud's image acceleration so that image file downloads will be faster in the future.
Website: Website You need to use Alipay to scan the QR code to log in - "Products and Services -" Search for container image services - "Container image services -" Mirror tools
Select Image Accelerator in the left sidebar of the pop-up interface .
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://6ytxqy54.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
You need to execute the above commands separately , as shown in the figure below
7. Use Docker to install software
7.1 Docker commonly used image operation commands
operate | Order | illustrate |
---|---|---|
Search | docker search keyword | We often go to docker hub to retrieve the detailed information of the image, such as the TAG of the image. |
Pull | docker pull image name:tag | :tag is optional, tag represents the label, mostly the version of the software, the default is latest (go to docker hub to extract the image file) |
list | docker images | View all local mirrors |
delete | docker rmi image-id | Delete the specified local image, image_id is the image ID |
7.2 Docker’s commonly used container operation commands
The first step is to use docker pull to pull the image file from the docker warehouse.
The second step is to use docker create to create the container of the image file.
The third step uses docker run to run the image file created in the previous step. (The first and second steps can be combined)
operate | Order | illustrate |
---|---|---|
run | docker run --name container-name -d image-name示例:docker run --name myredis -d redis | –name: Custom container name -d: Run in the background image-name: Specify the image template |
list | docker ps (view running containers) | Add -a to view all containers |
stop | docker stop container-name/container-id | Stop the container you are currently running |
start up | docker start container-name/container-id | Start container |
delete | docker rm container-id | Delete the specified container based on the container ID |
Port Mapping | -p 13306:3306 Example: docker run -d -p 6379:6379 --name myredis docker.io/redis | -p: Host port (Linux external port) (mapped to) the port inside the container . |
Container logs | docker logs container-name/container-id & tail -f 容器id | View the container's startup log when starting the container |
After understanding the commonly used image operation commands and container operation commands of docker, use these commands to install the software.
7.3 Install MySQL
1. Download the MySQL image file
docker pull mysql:8.0.28
In this way, you can pull the mysql image from the image warehouse into the docker container, and then use : 8.0.28 to specify the version of the mysql image as 8.0.28.
Then use docker images to view the list of images in the current docker container. The mysql just downloaded is in the list.
In the image list, REPOSITORY is the name of the image file, TAG is the version number of the image, and IMAGE ID is the ID of the image file.
2. Create an instance and start Mysql
Order:
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:8.0.30
Parameter Description:
-p 3306:3306: Map the 3306 port of the docker container to the 3306 port of the host ( the former is the host and the latter is the docker container )
-v /mydata/mysql/conf:/etc/mysql: Mount the configuration file in the /etc/mysql directory inside the docker container to the host's /mydata/mysql/conf directory.
-v /mydata/mysql/log:/var/log/mysql: Mount the log files in the /var/log/mysql directory inside the docker container to the /mydata/mysql/log directory of the host.
-v /mydata/mysql/data:/var/lib/mysql: Mount the configuration file in the /var/lib/mysql directory inside the docker container to the host's /mydata/mysql/data directory.
docker ps
docker ps -a
Found that startup failed, check the log
docker logs mysql
错误:Upgrade is not supported after a crash or shutdown with innodb_fast_shutdown = 2. This redo log was created with MySQL 5.7.36, and it appears logically non empty. Please follow the instructions at http://dev.mysql.com/doc/refman/8.0/en/upgrading.html
Solution: 1. https://blog.minirplus.com/author/admin/
2. After version 5.7, you need to upgrade the previous mounting file, otherwise it will not be used. If there is no important data, it is recommended to delete the previous mounting file directly, or make a backup
命令:cp ib_logfile1 ib_logfile1.backupJar & rm ib_logfile1
Delete the mounted file directly
and then restart
As shown in the picture above, after running the above command, a string of random values will appear. Use the command docker ps to view all running containers.
In the above figure, CONTAINER ID is the container ID, IMAGE is the image file used to run the container, COMMAND is the command to run the container, CREATED creation time, PORTS is the mapping of the container internal port to the host port, and NAMES is the image file name.
Open the cmd window on the host and use the telnet command to see if the port can be pinged. Command: telnet IP address port
As shown in the picture below, it is successful
Use SQLYog to connect to MySQL installed on Linux, fill in your IP address as shown in the figure below, and the password is root.
As shown in the figure below, our MySQL connection is successful
3. Docker container file mounting and port mapping
In the above figure, docker run is the command to run the docker container. The running containers are isolated from each other, and each container is a complete operating environment .
- How can we see that this docker container is a complete operating environment?
We use docker ps to view the running container, and we can see the just-running docker container. How can we see that this docker container is a complete operating environment ?
First of all, MySQL is installed into the Linux system, so the running container is actually a complete Linux . How to manifest it? We can go inside this MySQL container with the command: docker exec -it container ID /bin/bash
In the above picture, the MySQL container ID is 0ac86dfdb085. Then the command to enter the MySQL container is docker exec -it 0ac86dfdb085 /bin/bash . After entering the MySQL container, use the command: ls / to view the directory structure inside the MySQL container. It can be obviously seen that this directory is similar to the directory of the Linux system, so the MySQL container is a complete Linux .
- Check which directories MySQL is installed into in the MySQL container.
Command: whereis mysql Check which directories in the MySQL container mysql is installed into.
- Parsing -p 3306:3306 in the run container command
In the MySQL container, there will be a default 3306 port, but this 3306 port is inside the MySQL container. If we want to access mysql in this MySQL container, we need to map the port in the container to the external Linux host . The -p 3306:3306 in the command means the 3306 port in the host and the 3306 port number in the MySQL container. One-to-one correspondence, that is, if we access 3306 in the Linux host, we can access the 3306 port number in the MySQL container.
- Parse the command to run the container: -v /mydata/mysql/conf:/etc/mysql/conf.d
Mount the configuration file in the /etc/mysql directory inside the MySQL container to the host's /mydata/mysql/conf directory.
Before mounting, we need to enter the /etc/mysql directory in the MySQL container to modify the mysql configuration file in this directory. This will be more troublesome . At this time, we hope to add folders or files that we often need to see inside the container. The file is mapped to the relevant directory on the Linux host.
The other commands in the running container command are basically the same. Finally, enter exit to exit the container .
4. Set mysql to start automatically when booting
命令:sudo docker update 容器名称 --restart=always
- To view the current mysql container name or container ID, command: docker ps -a
As shown in the figure above, the current container ID of mysql is 0ac86dfdb085.
- Instruction: sudo docker update 0ac86dfdb085 --restart=always
7.4 Install Redis
1. Download the Redis image
命令: docker pull redis 拉取最新版本的redis
Then use the docker images command to view all image files in the current docker container.
2. Create an instance and start Redis
mkdir -p /usr/local/redis/conf #Create the /usr/local/redis/conf folder
touch /usr/local/redis/conf/redis.conf #Create the redis.conf configuration file in the /usr/local/redis/conf folder.
docker run -p 6379:6379 --name redis -v /usr/local/redis/data:/data \
-v /usr/local/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf --requirepass "zzw-2022"
As shown in the figure below, after a string of random values appears, it means that the Redis container is running.
We then use docker ps to view the list of running containers. The first one is the redis container.
3. Use the Redis image to execute the Redis-cli command to connect
- Execute the redis-cli command to connect to the redis client
命令:docker exec -it redis redis-cli
As shown in the figure above, we save the string a into the memory of redis with key b. Note that it is in the memory of redis and is not persisted .
If you restart redis and then use the get b command to get the value of b, you cannot get it, and the value is nil. As shown in the figure below, the command to restart the container:
redis restart container ID/container name
- Persist data into redis
How to achieve data persistence? First use the cd command to switch to the /usr/local/redis/conf directory.
Then use the command vi redis.conf to edit the redis.conf file in the current directory, enter the letter i to enter insert mode, add appendonly yes to the file , then esc to exit the editing mode, and then enter **:wq to save and exit. Finally, use the command docker restart redis to restart the redis container**.
- Connect to the redis client again to test whether the data can be persisted.
命令:docker restart redis 重启redis容器,再来获取b的值,如下图所示。
In order to view the data saved in redis, we can use the redis visualization tool RESP.app
4. Set Redis to start automatically when booting
命令:sudo docker update 容器名称 --restart=always
- To view the current redis container name or container ID, command: docker ps -a
- Instruction: sudo docker update 47f1–restart=always
7.5 Install and deploy RabbitMQ
7.5.1 Pull RabbitMQ image file
命令:docker pull rabbitmq:management
Note: Management is added here, indicating that it has a web management interface for easy management.
Off topic: When you search for image files, you can search directly in the Docker store. The address is: https://hub.docker.com/. The related image of RabbiMQ is: https://hub.docker.com/_/rabbitmq /, view tags to view version information.
7.5.2 View the pulled RabbitMQ image file
命令:docker images
7.5.3 Running the image
命令: docker run -d --hostname my-rabbit -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 25672:25672 -p 15671:15671 -p 15672:15672 --name okong-rabbit rabbitmq:management
7.5.4 Open the browser for access
Access address: http://LinuxIP address:15672/
Username and password are both guest
The above management interface contains 6 function menus
Overview: used to view basic information about RabbitMQ
Connections: used to view the connection information of the RabbitMQ client
Channels: used to view RabbitMQ channels
Exchanges: Exchanges for viewing RabbitMQ
Queues: Queues for viewing RabbitMQ
Admin: used to manage RabbitMQ users, virtual hosts, policies and other data
7.6 Install JDK
1. Use mkdir -p /usr/local/java to create related directories in cascade.
Use cd to jump to the /usr/local/java directory
2. Upload the Linux version of the JDK compressed package and decompress it
Click the icon in the Xshell tool as shown below to enter the Xftp tool.
- Use the Xftp tool to enter the /usr/local/java directory and upload the JDK compressed package provided by the material.
- Then use the sudo tar -zxvf jdk-8u341-linux-x64.tar.gz command to decompress the just uploaded Linux version of JDK.
After the JDK compressed package is decompressed, as shown in the figure below, an additional folder will appear after decompression.
3. Command: vi /etc/profile
Configure environment variables and add the following commands ( at the end of the file, add the following configuration ).
Two different configuration methods
#set java environment
JAVA_HOME=/usr/local/java/jdk1.8.0_341
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
export JAVA_HOME=/usr/local/java/jdk1.8.0_11
export JRE_HOME=${
JAVA_HOME}/jre
export CLASSPATH=.:${
JAVA_HOME}/lib:${
JRE_HOME}/lib:$JAVA_HOME/lib.tools.jar:$CLASSPATH
export JAVA_PATH=${
JAVA_HOME}/bin:${
JRE_HOME}/bin
export PATH=$PATH:${
JAVA_PATH}
4. Reload configuration file
source /etc/profile
5. Enter java, javac and java -version as shown below.
At this point, the JDK is installed.
8. Deployment projects
8.1 One-click deployment of the backend into the Docker container
Let's take the deployment project as an example.
1. Configure docker remote port
1. Configure the remote port
命令:vi /usr/lib/systemd/system/docker.service
在第13行找到 ExecStart=/usr/bin/dockerd 后面添加 -H tcp://0.0.0.0:2375
Note : You can modify it directly through commands, or you can use a text editor to open it in the Xftp tool and then modify it.
2. Restart docker
执行命令重新加载配置: systemctl daemon-reload
执行命令重启Docker: systemctl restart docker
3. Open port
开放docker远程端口: firewall-cmd --zone=public --add-port=2375/tcp --permanen
再刷新防火墙: systemctl reload firewalld
OK, the server-side configuration is now complete.
2. Configure Docker in the IDEA tool
1. Install the Docker plug-in in IDEA.
Open IDEA —> File —> settings —> Plugins —> Markplace —> search for docker.
2. Remotely connect to Docker on the Linux server in the IDEA tool.
File —> Settings —> Build… —> Docker —> Click the + sign —> Select TCP socket-> Enter your server’s IP and Docker remote connection port number 2375. After entering, the connection will be automatically established. If you see After the successful connection is displayed—》apply—》ok.
Note : If it shows that the connection failed, please turn off the Windows firewall and confirm whether port 2375 of the Linux server-side firewall is open and in the listening state (netstat -tnl to find out whether there is xxxx and the Listen state is displayed)
After connecting, you can find Docker in the lower left corner of IDEA.
Indicates that there are two images in the docker container on Linux and two in the Containers container.
3. Pack the project to be deployed into a Jar package
Click Maven on the right side of the IDEA tool - "Find the parent project -" Double-click clean, compile, and package in order to package the entire project.
After double-clicking the package at the end, the effect of the entire OA project after it is successfully packaged is as follows:
You can see the generated jar package files in the target directory of each module, as shown below.
Note : Here, change the litemall-admin-api-0.1.0.jar file name ** in the above picture to litemall-admin-1.0.jar **
3. Deploy litemall-admin-api to the Docker container with one click
1. Right-click oa-server -> NewFile (if it is a Dockerfile), the file name is DockerFile
The configuration content in the DockerFile file is as follows.
#格式FROM image:tag,指定使用java:8作为运行环境。
FROM java:8
#将本地target/目录下的litemall-admin-1.0.jar包复制到docker容器中,并再次取名litemall-admin-1.0.jar
ADD target/litemall-admin-1.0.jar litemall-admin-1.0.jar
#设置itripeureka注册中心容器运行时的服务端口号
EXPOSE 8081
#意思是:使用java -jar命令运行litemall-admin-1.0.jar项目。
ENTRYPOINT ["java","-jar","litemall-admin-1.0.jar"]
As follows.
2. Configure Docker for one-click deployment
Click Edit Configurations… in the upper right corner of the IDEA tool
Then click the + sign -> Select Docker -> Dockerfile -> Then fill in the information as shown in the picture, and click OK after filling in.
3. Run Docker in IDEA tool
- Find the newly configured Docker in Tomcat, named litemall-admin, and run it.
- In the docker plug-in interface, we can see the deployed image files and container files.
- In the Linux system, we use docker images and docker ps -a to view the deployed image files and containers.
Error: no main manifest attribute, in litemall-admin-1.0.jar Solution
- Open port 8083 in Linux
Open docker remote port : firewall-cmd --zone=public --add-port=8083/tcp --permanen
Refresh the firewall: systemctl reload firewalld
Restart docker in Idea
Use docker ps to view and you can see that the operation is successful.
- Enter http://Linux IP address:8083/doc.html in the browser. The effect is as follows.
At this point, the litemall-admin project can be easily deployed into the Docker container.
8.2. Initial Nginx
1. Introduction to Nginx
1.1 Proxy mode
Speaking of agents, first of all we need to clarify a concept. The so-called agent is a representative and a channel ;
At this time, two roles are involved, one is the proxy role , and the other is the target role . The process in which the target role accesses the proxy role to complete some tasks through this proxy is called the proxy operation process ;
Just like a real life case : a customer buys a pair of shoes at an adidas store. The store is an agent (intermediary), the agent is the adidas manufacturer , and the target person is the customer .
1. Forward proxy
Before talking about reverse proxy, let’s take a look at forward proxy first. Forward proxy is also the most common proxy mode that everyone comes into contact with . We will talk about the processing mode of forward proxy from two aspects, namely software and life . Let ’s explain what a forward agent is .
In today's network environment, we need to access certain foreign websites. At this time, you will find that we cannot access certain foreign websites through a browser . At this time, everyone may use an operation "FQ" to bypass the wall . "To access, the main method of FQ is to find a proxy server that can access foreign websites. We send the request to the proxy server, and the proxy server accesses the foreign website, and then passes the accessed data to us !
The above proxy mode is called a forward proxy . The biggest feature of a forward proxy is that the client is very clear about the server address ( www.facebook.com ) it wants to access ; the server ( referring to the server where the official website is located ) only knows which proxy the request comes from. server , without knowing which specific client it comes from; the forward proxy mode blocks or hides the real client information .
2. Reverse proxy (Nginx)
Now that we understand what a forward proxy is, let’s continue to look at the processing methods of reverse proxy . For example , the Taobao website has an overwhelming number of visitors connected to the website at the same time every day. A single server is far from being able to satisfy the people’s growing desire to buy. This At that time, a familiar term appeared: distributed deployment ; that is, by deploying multiple servers to solve the problem of limiting the number of visitors ; most functions of the Taobao website are also implemented directly using nginx for reverse proxy , and by encapsulating nginx and other components later got a fancy name: Tengine . Interested children can visit Tengine's official website to view specific information: http://tengine.taobao.org/ So what is the specific method of reverse proxy ? As for the distributed cluster operation implemented , let’s first look at a schematic diagram:
From the above illustration, you can clearly see that after receiving the requests sent by multiple clients to the server, the nginx reverse proxy server distributes them to the back-end business processing server for processing according to certain rules .
Characteristics of reverse : At this time, the source of the request, which is the client, is clear , but it is not clear which server the request is processed by. nginx plays the role of a reverse proxy .
Reverse proxy is mainly used in distributed deployment of server clusters. Reverse proxy hides server information!
1.2 Nginx concept
Nginx is a lightweight , high- performance web server/ reverse proxy server that can achieve load balancing . Because it is lightweight, it takes up less memory, starts very quickly, and has high concurrency capabilities. It is widely used in Internet projects application.
Load Balance refers to allocating requests/data (evenly) to multiple servers for execution. Its core is balanced pressure sharing.
2. Installation of Nginx reverse proxy server
2.1 First check whether Nginx is installed on the server
Command: whereis nginx
2.2 Install Nginx
1. Add source
-
Use the command: cd /etc/yum.repos.d/ to switch to the etc/yum.repos.d directory
-
Enter the command: vi nginx.repo to create a new file
- Enter the following information in the above file (note: after pasting the following content, enter: colon, and then enter wq)
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
2. Use yum to install nginx
Command: yum install -y nginx
3. View the Nginx installation directory
View the installation directory: whereis nginx
Check the installed version: nginx -v
If the version number nginx/1.22.0 shown above appears, it means that your nginx installation is complete.
4. Start Nginx
-
After installation, check the command: rpm -qa | grep nginx
-
Start nginx command: systemctl start nginx
-
Stop nginx command: systemctl stop nginx
-
Add startup: systemctl enable nginx
-
Check the status of nginx: systemctl status nginx
As shown in the figure above, active (running) indicates that Nginx is running. In the future, Nginx will start automatically at boot.
2.3 Enter your Linux IP address on the browser to access Nginx
Enter the IP address of your server in the browser to access Nginx . As shown in the figure below, the default port of the nginx service is 80 ( you need to pay attention to firewall restrictions and port conflicts here ).
1. When accessing, if the following picture appears - connection timeout
Analysis reason: The default port number of Nginx is 80. Maybe this 80 port is restricted by the firewall on Linux. In this case, we need to use the command to open port 80 from the Linux firewall.
2. Open port 80
First, let’s take a look at the common commands of the firewall, as shown below.
开放端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
刷新:systemctl reload firewalld
查看端口是否开放:firewall-cmd --query-port=80/tcp --zone=public
查看所有端口:firewall-cmd --list-port --zone=public
启动:systemctl start firewalld
查看状态:systemctl status firewalld
停止: systemctl stop firewalld
禁用: systemctl disable firewalld
删除端口:firewall-cmd --zone=public --remove-port=80/tcp --permanent
cmd命令:telnet Linux的ip地址 端口号 在window系统中查询是否访问端口
- First check whether port 80 is open.
As shown in the figure above, after entering the command to view port 80, no is displayed, which means that port 80 is not currently open.
- Open port 80
As shown in the figure above, after entering the command to open port 80, success is displayed, which means the opening is successful.
- After refreshing the firewall , enter the command to check whether port 80 is open.
3. Enter your Linux IP address into the browser to access it, as shown in the figure below.
As shown in the figure above, Welcome to nginx! appears, indicating that nginx is configured.
3. Nginx configuration
3.1 Nginx configuration file location
1. Command: whereis nginx can view the location of the nginx configuration file
As shown in the figure above, the path of the nginx configuration file is /etc/nginx . Use the Xftp tool to find nginx.conf.
2. Configure the nginx.conf file to be opened with the EditPlus tool
- If the EdisPlus tool is not installed, install it in advance.
Download in material
- Click the [gear] icon in the Xftp tool shown below
- Click [Advanced] in the picture below - "Find the installation path of the EditPlus tool -" and then click [OK] to complete.
After configuring, you can right-click nginx.conf, as shown in the figure below.
Note : We are installing a new version of nginx, so there are two nginx configuration files: /etc/nginx/nginx.conf and **/etc/nginx/conf.d/default.conf** We will mainly modify this later. default.conf file .
3.2 Detailed explanation of the contents of the default.conf configuration file
1. nginx default listening port
- Back up the default.conf file first.
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
- We use the EditPlus tool to open the default.conf file and add the following box comments.
server {
listen 80; #监听端口为80
server_name localhost; #配置要访问的域名,localhost为本地访问
#access_log /var/log/nginx/host.access.log main;
location / {
#当访问http://linux的Ip地址:80/时,进入到本location中
# root 代表项目的根目录,然后后面接的是前端静态工程,即nginx的首页文件
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
- Modify the default listening port to 9000
In the code above, you can see that the default listening port is 80, so we can directly access the server IP. Next, we change the default listening port to 9000:
- Open port 9000 (because port 9000 is blocked by the firewall by default)
查看端口是否开放:firewall-cmd --query-port=9000/tcp
开放端口:firewall-cmd --zone=public --add-port=9000/tcp --permanent
刷新:systemctl reload firewalld
- Restart Nginx
Check the nginx configuration file for errors: nginx -t
Restart nginx, command: nginx -s reload
At this time, you need to bring the 9000 port number when accessing, and the access address ip : 9000
Enter the access address as shown below: http://linux ip address: 9000
3.3 Configure website page storage path (storage path for Vue front-end deployment)
Use the Xftp tool to open the /etc/nginx/conf.d/default.conf file and find the root field. What follows this field is the path to the website page, which is the path where the website is stored.
1. Modify the storage path when the Vue front-end is deployed on Linux
Assume that the storage path of our Vue front-end is: /home/www/dist
The value of root is modified as shown in the figure below:
2. Create the /home/www path in linux
命令:mkdir -p /home/www
We did not create a new dist folder because we will generate a dist folder when the vue project is packaged.
4. Deploy the litemall front-end to Linux
4.1 Edit the /etc/nginx/conf.d/default.conf file in Linux
Add the code as shown below to successfully reverse proxy requests from the front end to the back end.
location /prod-api/ {
#使用proxy_pass配置反向代理的服务器地址
proxy_pass http://localhost:8081/; #这里是后端api的真实地址
}
4.2 Package and deploy Vue project
Note: /prod-api is the base path of the back-end request. All requests issued by the front-end will add this base path /prod-api after the port number. For example, when issuing a login request/login, axios.create() in request.js In the method, the base path /prod-api will be added before the /login address, and the full path will become http://localhost:8080/prod-api/login. Then the reverse proxy configured in vue.config.js will be implemented. This request is proxied to the destination address http://localhost:8083/login
1. Change IP
Change all used service IPs to server IPs
2. Package Vue project
Use the vue packaging command npm run build to generate the dist folder. It should be noted that the packaging command for the oa project is npm run build:prod (this command packages the project into the production environment)
- Modify the .env_production configuration file as shown below (we will not modify it here yet).
- Select litemall-admin (Vue project), right-click -> Open in Terminal -> Enter the following command.
If DONE Build complete in the red box in the picture above finally appears, it means that the vue front-end project is packaged.
After successful packaging, there will be an additional dist directory in the root directory of the litemall-admin project , as shown in the figure below.
3. Upload the dist directory to the Linux server
Open the Xftp tool, as shown in the figure below. The left side is the root directory of the litemall-admin front-end project, and the right side is the saving directory where the Vue front-end project is deployed to Linux.
The dist directory of the litemall-admin project on the right - "Transfer -" realizes the transfer to the /home/www directory
4. Modify nginx.conf
Use the Xftp tool to open the /etc/nginx/nginx.conf file and change the value of user to root, as shown in the figure below.
5. Command: vi /etc/selinux/config to edit the config file in /etc/selinux
In addition to using the vi /etc/selinux/config file to edit, you can also use the Xftp tool to open the config file, and then change the SELINUX value in the config file to disabled
Then enter the reboot command to restart Linux, and then click Linux in the picture below to enter.
6. Enter http://LinuxIP address:9000 in the browser
At this point our project has been deployed.