Table of contents
1. Process of virtual machine deployment project
2.Virtual machine deployment project
3. Front-end and back-end separation projects
Preface
In the software development process, deploying and releasing projects is a very important part. Use virtual machine technology to deploy and publish projects conveniently, flexibly, and reusably. This blog will introduce how to use virtual machines to deploy and publish Linux projects in a Windows environment.
1. Process of virtual machine deployment project
For the first four steps, you can view this blog’s nanny-level tutorial for installing a virtual machine (VMware), configuring the virtual network editor, installing Windows Server, and accessing the virtual machine from the host and configuring the server environment.
1. Preparation
First, you need to download and install the virtual machine software. Common virtual machine software includes VMware Workstation, Oracle VirtualBox, etc. Secondly, you need to obtain the required Linux operating system image file. It can be downloaded from the official website or other trusted sources.
2. Create a virtual machine
Create a new virtual machine instance using virtual machine software. When creating a virtual machine, you need to configure the hardware settings of the virtual machine, such as memory, processor, etc. Next, you need to install the Linux operating system and perform basic configuration.
3. Configure the network
Set the virtual machine's network connection method, such as bridge mode or NAT mode. Bridge mode allows the virtual machine to connect directly to the physical network, while NAT mode allows the virtual machine to access the external network through the host. Configure network parameters, such as IP address, subnet mask, etc.
4.Install Linux software
Download and install the required Linux software, such as Apache, MySQL, jdk, etc. Software can be installed using a package manager.
5. Import and configure projects
Import the Linux project into the virtual machine. It is necessary to configure the project's dependencies, database connection, etc. Configuration can be done using an editor or command line tool.
6. Run and test the project
Start the application server in the virtual machine, such as Apache, Tomcat, etc. Deploy the project and start the application. Use a browser to access the project and perform functional testing.
7. Back up and copy virtual machines
Learn how to back up and copy virtual machines for later use or to share with others. You can use the snapshot feature provided by the virtual machine software for backup and replication.
2. Stand-alone project
After getting the developed project, unzip it. At least there will be several files as shown below:
1. Local testing
Import the SQL file into this machine to test whether there is any problem
Copy the war of the developed project to the webapps directory under tomcat of the host machine
In tomcat's bin directory, find the startup.bat file and double-click it to start tomcat.
After running it, enter the address in the browser to access it. If it runs successfully, it means there is no problem with the project itself.
2.Virtual machine deployment project
Share project to virtual machine
Unzip and put the war package into webapps under tomcat
Go to the host database, find the database connected to the virtual machine, create a database with the same name as the database in the stand-alone project, and import the database script into the database.
Run tomcat and view the database configuration of the project
Access the project deployed in the virtual machine in the host's browser. You need to add the IP of the virtual machine to the access request address. You can provide access instructions to complete the deployment.
3. Front-end and back-end separation projects
The local testing here will not show you the step-by-step testing. It is almost the same and very simple. Next, we will continue to introduce how to deploy the front-end and back-end separation projects through virtual machines.
Unzip and put the war package into tomcat
Run tomcat and view the database configuration of the project
Import our database script
Configure node.js environment
Decompress
the file to the specified location (for example: C:\software\NodeJS), and create two directories, node_global and node_cache, in the decompressed directory.Note: Instructions for creating a new directory
node_global: npm global installation location
node_cache: npm cache path
Configure environment variables
and add NODE_HOMEModify PATH and add at the end: ;%NODE_HOME%;%NODE_HOME%\node_global;
Test whether the installation is successful: Open the cmd window and output the following command:
node -v outputs the NodeJs version number
npm -v outputs the version number of npm
Configure the npm global module path and cache default installation location
. Open cmd and execute the following commands separately:npm config set cache "D:\software\NodeJS\node-v10.15.3-win-x64\node-v10.15.3-win-x64\node_cache"
npm config set prefix "D:\software\NodeJS\node-v10.15.3-win-x64\node-v10.15.3-win-x64\node_global"
Note 1: Connect node_global (npm global installation location) and node_cache (npm cache path) created in step 1 with npm
Note 2: If the execution of the command is stuck, you can delete C:\Users\username\.npmrc and execute it again. (Username: is the username of the current computer)
Note 3: "D:\software\NodeJS\node-v10.15.3-win-x64\node-v10.15.3-win-x64\node_global", double quotes cannot be missing
Modify the npm image to improve download speed.
You can use cnpm or directly set --registry. It is recommended to set --registry.--registry
Set up Taobao source
npm config set registry https://registry.npm.taobao.org/
View sources, you can see all the sources that have been set
npm config get registry
Note 1: In fact, the content of this step is to add the following code to the C:\Users\username\.npmrc file
registry=https://registry.npm.taobao.org
cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
Note 1: After the cnpm installation is completed, you can use the cnpm command instead of the npm command. At this time, npm will still use the official image, and cnpm will use the domestic image.
Note 2: If you want to restore to the original settings, perform the following:
npm config set registry https://registry.npmjs.org/
Verify installation results
1 version verificationnode -v
npm -v
2 Check Taobao mirror settings
npm get registry
3 Check npm global path settings
In this step, you can just install a module globally and you can evaluate it.
npm install webpack -g
After the above command is executed, the following file will be generated
%node_home%\node_global\node_modules\webpack
Note: Don’t worry if a warning occurs during the downloading process. If an Error occurs, delete the downloaded broken file and download it again.
How to run the downloaded Node.js project.
Unzip the downloaded project to the specified directory. In this example, unzip it to: C:\Users\86155\Desktop\pro\nmgwap-vueproject-master\vueproject.Directly enter cmd to enter
Then enter npm i
Our module is being downloaded, please note that you must be online here
After the command is executed, you will find that there is an additional node_modules folder in the root directory of the project.
There are modules downloaded from the npm remote library and then "installed" into your project.
This step can be understood as modifying maven's pom file to add dependencies, and then maven downloads the dependencies from the central warehouse
Where is the pom file? In fact, it is package.json in the project
Execute the command npm run dev to start the project
Run the project
Projects with separate front-end and back-end will not be accessible if they are accessed directly in this way. Only the virtual machine itself can access it.
Below I provide two solutions:
1. Solve the problem of spa project host access
Use nginx anti-proxy tool
Enter the nginx.conf file under the conf folder under nginx to configure the proxy url
Enter cmd in the nginx root directory to enter the command window and enter nginx.exe -s reload to restart.
Next we can visit
Solve the problem of spa project host access
Find index.js under the config file in the spa project and change localhost to 0.0.0.0
http://192.168.137.128:8081/ can also be accessed