Simply record Cent OS server configuration JDK+Tomcat+MySQL

  • 2020-05-13 03:59:21
  • OfStack

The project needs to be deployed on a server of CentOS, which has installed an Nginx and an MySQL environment before, and one project is running. And our latest project is written in Java, server is to use Tomcat, so need to integrate Nginx and Tomcat do 1 time, but the project is still in development stage, we first use Tomcat the default port 8080, ok, here are probably your "terminal" (because I use is Mac system, default SSH, if is Win system, please choose other corresponding tools, believe G god will help you ~ ~).

Step 1: connect to the server

The rented server supports SSH connection, that is to say, the graphics is out of our way, by the way, we can also enjoy 1 "master" feeling
Enter the following command at the terminal:


ssh The server IP address -l The user name  

When you hit enter, the screen will display something like this:


The user name @ The server IP address 's password: 

In the back of the direct input password is, for the sake of security, you enter the content is really invisible, don't doubt your eyes, don't doubt your keyboard, also don't doubt your hand, you boldly enter the password, please remember, you have three chances oh ~
When you see the following words, congratulations, you have logged in to the server, you can do whatever you want ~~ haha


[ The user name @ The server IP address ~]# 

Step 2: uninstall Open JDK

By default, Cent OS will install one Open JDK for us, but we don't appreciate it. In order to reduce the trouble, we still prefer Sun JDK, so we need to uninstall Open JDK first.
First let's use the following command to look up 1 and see what we have installed regarding Java


rpm -qa|grep java 

The information returned on my server is as follows:


xmlrpc-javadoc-2.0.1-3jpp.1 
gcc-java-4.1.2-48.el5 
java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115 
java-1.4.2-gcj-compat-javadoc-1.4.2.0-40jpp.115 
java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5 
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 
java-1.4.2-gcj-compat-src-1.4.2.0-40jpp.115 
bsh-javadoc-1.3.0-9jpp.1 
java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115 

java-1.6.0-openjdk-1.6.0-1.7.b09.el5 and java-1.4.2-gcj-compat-1.4.2-40jpp.115 are all right.


rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5 
rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 

Ok, finally, I will verify 1 more, whether OpenJDK is really uninstalled:


java -version 

The system returns the following:


-bash: /usr/bin/java: No such file or directory 

All right, so far we've got Open JDK completely covered, and thanks to rpm, we've saved a lot of things

Step 3: get the software (JDK\Tomcat)

We will download JDK and Tomcat to the local computer from Sun's official website and Apache's official website respectively. The download address is as follows:
JDK: http: / / www. oracle. com/technetwork/java/javase downloads/jdk6 - downloads - 1637591. html
I choose to
This version, the 64-bit version, is for rpm, and the current project doesn't use any of the advanced features of Java7, so let's be honest and use JDK6.
Tomcat: http: / / labs. renren. com/apache - mirror/tomcat/tomcat - 6 / v6. 0.35 / bin/apache - tomcat - 6.0.35. tar. gz
Tomcat is the best green software for decompression, with less worries. In accordance with the old version of the document, Tomcat6 is selected after paragraph.
Here we are the two files uploaded to alone me another 1 FTP server, and then use the wget this tool will be two software download to the server, using a simple and powerful wget this tool is a download tool, in fact, we can also choose to download from the website directly, but JDK must manually due to agree to a deal, so 1 piece of transit use FTP do at that time, the specific command line is as follows:


wget ftp://ftp Server address /jdk-6i33-linux-x64-rpm.bin 


wget ftp://ftp Server address /<span style="font-family:Consolas, Lucida Console, monospace;"><span style="white-space: pre-wrap;">apache-tomcat-6.0.35.tar.gz</span></span> 

Note here that you are executing this command in that directory, and the file will be downloaded in that directory. For those of you who are not familiar with Linux, you still need to keep in mind the main folders and their USES so as not to waste time.

Step 4: install JDK

Directly execute the following command in the directory where you just downloaded the software:


The user name @ The server IP address 's password: 
0

Then the progress will be displayed on the screen. When you are finished, let's do test 1. Enter:


java -version 

If the following content is displayed, congratulations, the Java environment has been completed!


java version "1.6.0_33" 
Java(TM) SE Runtime Environment (build 1.6.0_33-b03) 
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode) 

Step 5: install Tomcat installing Tomcat is actually quite simple. First select a directory, which generally USES the /usr/local directory, and then use the cd command to jump to:


cd /usr/local 

Then download to the directory from tomcat's official website with the following command:


The user name @ The server IP address 's password: 
4

Then unzip the zip file


The user name @ The server IP address 's password: 
5

Use the ls command to see a directory called tomcat. So tomcat is installed, simple. Launching tomcat is also easy. Go directly to the tomcat/bin directory and execute:


The user name @ The server IP address 's password: 
6

If there is no error, congratulations, at this point you can type your IP(or domain name):8080 directly into your browser and see the three-legged cat. If you start something wrong, or you don't see the 3-pin cat, it may be because of a configuration file. I modified /etc/profile file and added the following content in the last line:


The user name @ The server IP address 's password: 
7

Then go back to the command line and execute:


The user name @ The server IP address 's password: 
8

Enable the configuration we just did, so you can try again 1, should be ok, but 1 must be careful that the directory is correct, 1 must be!

Step 6: configure MySQL(for scrambled code)

When I got the server, MySQL had already been installed, which was supposed to save me a lot of trouble at that time. However, when the project was later deployed, there was no problem with English, but all the Chinese turned into greetings. After one Google, I was asked to use the utf-8 method again to ensure that all the codes were utf-8. If you have this problem, I believe the following can help you.
1. Log in the database:


The user name @ The server IP address 's password: 
9

Then enter your password and press enter to see the following:


[ The user name @ The server IP address ~]# 
0

Select the database that needs to change the encoding


mysql>use Database name  

Check the current database encoding


show variables like "%char%"; 

The results returned on my machine are as follows:


+--------------------------+----------------------------+ 
| Variable_name            | Value                      | 
+--------------------------+----------------------------+ 
| character_set_client     | latin1                     |  
| character_set_connection | latin1                     |  
| character_set_database   | utf8                       |  
| character_set_filesystem | binary                     |  
| character_set_results    | latin1                     |  
| character_set_server     | utf8                       |  
| character_set_system     | utf8                       |  
| character_sets_dir       | /usr/share/mysql/charsets/ |  
+--------------------------+----------------------------+ 
8 rows in set (0.00 sec) 

These attributes, our goal is to put those all coding utf instead - 8, and after I test, which influence the value of the real should be character_set_database \ character_set_server \ character_set_system this three values, especially the first, if it is not a utf - 8, no matter how again is there will be a question mark, and as a result, such as the one above is displayed in Chinese normal, I find that odd, too.
4. Change the encoding of the database to utf-8 and execute the following statement


mysql>set names utf8; 

Note that in MySQL, the utf-8 code has no concatenation in between.
5 out of MySQL


mysql>exit; 

Edit the configuration file for MySQL


vim /etc/my.cnf 

7. Modify the configuration file as follows:


[ The user name @ The server IP address ~]# 
7

The following sentence was added:


[ The user name @ The server IP address ~]# 
8

8 restart MySQL


/etc/init.d/mysqld start 

So down configuration, database garbled code problem can be solved.
Of course, database messy code is not only a database configuration problem, but also may be due to the coding of the page file itself, the coding of the page file when it is sent to the program, etc., need to pay attention to, the current solution is actually 1 into utf-8!
Step 7: deploy the code
Since we only run one project, we did not do the directory configuration. After packaging the project files, we can extract them into tomcat directory and webapps directory.
Then restart the server 1 time, done!
Launch command for tomcat:


rpm -qa|grep java 
0

tomcat stop command:


rpm -qa|grep java 
1

Postscript:
Actually began to write this article's note about the end of June, when the project first deployed to the server, various problems have two in the evening, all kinds of search, but unfortunately their knowledge management was not well done, a lot of good information so to put the past, each time you encounter the same problem, all want to search again, desperately want to search keywords, very crazy, there is only on the deployment situation compiled under 1. One of the mistakes, welcome to point out!
I've had two other problems recently
1 1 time deployment and stopped tomcat servers, opens the tomcat immediately, and then press the mouth, then USES http: / / pmfou - site iteye. com/blog / 1484447 method mentioned here:
"We ps-ef |grep java
Find all java process Numbers
kill-9 process number
Kill the process that appears, except for the username XXX XXX 0 20:56 pts/0 00:00:00 grep --color=auto java"
But when I actually executed it, every time the kill process failed to report this process, it was only normal after various restarts.
2 2 days later, the server often down off myself, and I doubt is the problem of yesterday, and then look at log, found to be out of memory, is because I was lazy, the project webapps backup is done, so each time you start tomcat will show up, and then cause of memory, it may also be because our JVM also USES the default configuration. Remove those backups and the server is running fine so far!!


Related articles: