Teach you how to deploy a web development environment on Alibaba Cloud Server (Ubuntu system)

         This blog post mainly explains how to build a web development environment in the Linux environment, because if you can't deploy the project, you are destined to be a code farmer, so this is also something you need to understand. I believe, after you read it , there will definitely be something to gain, because they are all dry goods, and they are all the configuration environment that I specially set up to write this blog post, so it is convenient for more people to learn from scratch~~~~~~! Seriously After reading this blog post, if you still don't know it, please contact me. However, I believe that this does not exist, because it is completely dry goods~!

System environment :

1: Alibaba Cloud Server (Linux system ------- Specifically, Ubuntu system), if the system used is different, there are some configurations in it, which are slightly changed, but not much

2: Windows7------this is still necessary

3: Linux version of JDK8

4: Linux version of Tomcat8

5: Linux version of Mysql5.1

6: It is recommended that at least have a certain understanding of the Linux system, at least the basic commands and the meaning of each root directory. welcome to read,

I have another article for a detailed explanation of the Linux system.

http://blog.csdn.net/cs_hnu_scw/article/details/77745322

(1) JDK installation

step:

(1) Download the JDK of Linux. It is recommended to use 1.8. After all, there are many new features in 1.8. I think it is very good. Of course, there is no problem with using 1.7.

JDK download link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Note: Pay attention to how many digits your server has, and download the corresponding digits, otherwise there will be problems later. If you are on Alibaba Cloud and use the Ubuntu system, then it should be 32-bit. You can see this by looking at your own server.



(2) Move the downloaded JDK to the Linux server

     Here you need to download a software called FileZlilla ( https://filezilla-project.org/download.php?type=client ) for file uploading and downloading between local computers and remote servers.

In addition, it is necessary to download a software for Windows to link the Linux system. You can use putty ( http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html ) for Windows to operate a remote server ( Linux ), Can also be used . . I use the latter, get used to it. .

After downloading the FileZlilla software, run the login directly, and then move the Windows resources to the desired directory corresponding to Linux as normal. . . If it is recommended, generally put the JDK installation in the directory under /usr/ in the Linux server, and you can create a directory called java yourself. Then move the JDK to the server here.

(3) Decompress the compressed package of JDK

This is the operation of connecting from Windows to Linux server through the second software. If you have not learned Linux, I suggest you read my other article,

Command: tar zxvf JDK archive name

(4) Configure environment variables

Command: vim /etc/profile

In the last part of the file content, add the following


(5) Information about restarting the configuration file

Command: source /etc/profile

Or, just restart the server directly, which can be restarted directly on Alibaba Cloud, or through the command : reboot

(6) Test whether the JDK is installed successfully

Command: java -version

The following content appears, which means the installation is successful


Problems that may arise:

1: If an error message similar to binary .........XXXXXXX appears,

Solution: That means that the number of bits of the JDK you installed does not match the number of bits of the server, so this must be optimistic and choose the corresponding version. . . . . .

2: The commands of the system itself cannot be used.

Solution: This is because, when configuring environment variables, the system tools command was not added, and there was a statement problem in the configuration file, so it was caused. Since the commands of the system itself cannot be used, vim cannot be opened, and the only way to do it is to edit and modify it again through /usr/bin/vi /etc/profile.

(2) Installation of Tomcat

step:

(1) Download the Linux version of Tomcat (the download suffix is ​​tar.zip )

In this case, you can use tomcat7 or tomcat8 according to your own needs, there are no hard and fast rules.

(2) Move the downloaded Tomcat to the Linux server

Regarding how to move (copy) files from Windows to Linux system, there are actually many methods. This has been introduced in the knowledge points of installing JDK. If you don't understand, please refer to the above knowledge points.

As for the upload path, just upload it to your favorite path, but it is recommended to put it in the /usr/ directory, and I created a new directory under /usr/ called tomcat.

(3) Decompress the uploaded Tomcat archive on the server

Use the command: taz zxvf xxxxxxxxxxxx.tar.zip

Remarks: For this decompression, you can decompress it in the path after uploading. Of course, you can also copy this file to the directory you want to change, and then decompress it, which is no problem. And here I unzip it to the /usr/tomcat/ directory.

(4) Start tomcat

Go to the bin directory under the installed tomcat directory

For example: my own: cd /usr/tomcat/apache-tomcat-8.5.24/bin

Then run ./startup.sh directly

(5) Display the result


(6) Access via browser

Note: Here, we generally look in the server to see which ports support access, that is, to see which ports the firewall supports access to. (The default firewall in the Ubuntu system is not turned on, so this step can actually be omitted, but let’s talk about it, because someone may have set it on before, and there will be problems here. You can check it through the command ufw status, if it shows It is inactive, which means that the firewall is not turned on, then there is no problem. If active is displayed, then the display is turned on, and the corresponding port information will be displayed below, and then enter the command ufw allow 8080, which means that port 8080 supports access. )

interview method:

http://IP address:8080


(7) I thought it was very successful,,,, however, the access was shown as inaccessible, what is going on? The configuration went smoothly. . . . . .

Here comes the point~~~~~~~~~~~~~~~

Reason analysis: This is because, using Alibaba Cloud's server, the management of security groups is set in it, and for port 8080, access is not supported by default. Therefore, when we access in this way, the port is blocked. Yes, so,,, the result is that it cannot be accessed, then, how to solve it, please continue to read~!

(8) Enter the Alibaba Cloud server management interface


click for more:


(9) Enter the interface of the server security group


(10) Configuration rules



(11) Configuration result


(12) Re-pass http://IP address:8080

We can see that,,,, finally shows success. . . moved


(3) Mysql installation

Version: mysql5.7

step:

Execute the following steps directly under the server: (Pay attention to distinguish your own role permissions, corresponding to different execution commands)

(1) Upgrade apt-get

apt-get update

If you are not root user, use the following code:

sudo apt-get update

(2) Install mysql-client-core-5.7

apt-get install mysql-client-core-5.7
If you are not the root user, use the following command:
sudo apt-get install mysql-client-core-5.7

(3) Install mysql-client-5.7

apt-get install mysql-client-5.7
If you are not root user, execute the following command:
sudo apt-get install mysql-client-5.7

(4) Install mysql-server-5.7

apt-get install mysql-server-5.7
If not root, execute the following command:
sudo apt-get install mysql-server-5.7

(5) Check whether mysql is started

1. Check if the mysql process is running

ps -ef | grep mysql

2. View the msyql listening port

netstat -tap | grep mysql

(6) Open mysql

service mysql start

(7) Close mysql

service mysql stop

(8) restart mysql

service mysql restart

(9) When the mysql service is turned on, enter mysql

Excuting an order:

mysql -u username -p-------------------" and then enter the password we entered when we installed mysql.

E.g:

Then, it is the same as the dos control content of mysql in windows. .

Solution: The database problem of external network access server

Question: After the server's mysql service is successfully installed, then we must want to access the server's database through the Windows client. If we have not configured the above, the external network client must not be able to access it. The following aspects need to be set:

(1) Modify the configuration file of mysql in the server

Use the command:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Then, comment the code below:


Note: About this, many people have seen it on Baidu, through:

vim /etc/mysql/my.cnf
Then, execute the above command from the server and find the following:


It is found that it is different from what we want to configure. . . . . . Therefore, for the system is Ubuntu must pay attention. . . . .

(2) Modify the security group port control problem of Alibaba Cloud

For specific steps, please check, for Tomcat installation steps

Just need to add the port 3306 to the security group. Please refer to the steps for adding port 8080. .

(3) Set the access permission to run the external network in mysql

Note: This code is executed after entering mysql, that is, after passing the mysql -u account -p password. .

grant all privileges on *.* to root@"%" identified by "xxxx" with grant option;

Then execute the following code:

FLUSH PRIVILEGES;

Solved: MySQL cannot insert Chinese, and the problem of inserting Chinese garbled characters

Method: through the following command:

vim /etc/mysql/mysql.conf.d/mysqld.cnf
Then, add the following annotations:
character-set-server=utf8  
collation-server = utf8_unicode_ci  
init_connect = 'set collation_connection = utf8_unicode_ci;'


Then, enter mysql again and execute the command


You can see that the encoding method of the database has become utf8, so that the problem of garbled characters will not be displayed when inserting Chinese. The test results are as follows (the results viewed on the windows client):


Solution: The method for the self-starting of the mysql service in the server

In this case, there are many methods, the following are mainly two methods:

method one:

Execute the command on the server:

update-rc.d mysql defaults

Note: To remove the MySQL boot service, execute the command update-rc.d mysql remove

Method Two:

Execute the command on the server:

apt-get install sysv-rc-conf
Then execute the command:
sysv-rc-conf
The result is as follows:

The above indicates that the mysql service has been started automatically. . . The specific operation method: click with the mouse, or use the keyboard direction keys to locate, and use the space bar to select, "X" means to open the service. Use Ctrl+N to turn to the next page, Ctrl+P to turn to the previous page, and Q to exit.

The mysql service can be self-started. Similarly, Tomcat can also be turned into a function of self-starting when the server is turned on, but it is generally not set up in this way, because Tomcat does not need this and is relatively better.

(4) Package the Web project into a war package and publish it to the server

Description: Since we already have a server, and through the above steps, the environment has been tested and passed, then we need to carry out a real server deployment project. In this way, we can use the external network to access our Web projects can be accessed by other people, avoiding the disadvantage of only local access. We all know that the Web project uses the release of war, and compared with a tool class we wrote, if we want to refer to other people's projects, then we need to package the corresponding class into a jar package, so that others can refer to the jar package. implement the methods in it.

Therefore, the following is to explain how to package the web project written by yourself into war, and then publish it to the server.

step:

(1) Write your own web project in Windows. (Of course, you can also write this in the Linux system, but it's a little inconvenient, you know it)

(2) Package the written project. (The editor I use is IDEA, so, explain this. If you are using Eclipse, you can read other blog posts, this is very simple, no complicated problems)

Step point:

1:

2:

3:

4:

5: Click OK to complete. . . . .

6:

7:

8: Then go to your own corresponding project, out--"artifacts---"fill in the name---" to find the corresponding war package

(3) Through the FileZilla software (the above knowledge points have said what it is for and how to use it), upload the war package just generated to the webapp directory under the Tomcat directory you installed on the server. . .

(4) Start Tomcat. . . . . . . . . .

(5) TEST. . . . . . . . . . You only need to enter the IP address corresponding to your server: 8080/project name/entry URL. . . . . (This is actually the same as the local test, but the access address is changed)

-------------------------------------- You're done ------------- -------------------------------------------------- ---

Another little knowledge: For example, when we don't want to access port 8080, how to configure this? In fact, it is the same as configuring tomcat under windows. .

Steps: (1) Open server.xml in tomcat in the server

Command: vim server.xml ---------------" premise, you are in the conf directory under the tomcat directory

(2) Find the Connector label, and then change port=8080 to 80. . . Because the default is port 8080.... . . . As for why this tag is modified, I won't say much here, because it is related to the specific content of the configuration file in tomcat and the workflow of tomcat. I think it is necessary to understand this, so that the reason why tomcat can connect to the project, Its workflow is very useful, mainly the work of the connector Connect and the container container.


(3) Save and exit, and then restart Tomcat, so that you can access without adding port 8080.

     OK, the above content is explained. How to deploy the entire web environment on Alibaba Cloud is actually not difficult, as long as you are familiar with it slowly, it is worthwhile to be familiar with some common commands of Linux. . . . Thank you for your browsing, welcome to communicate~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578982&siteId=291194637