Simple documentation of CentOS server configuration Jdk+tomcat+mysql

Source: Internet
Author: User
Tags centos server ssh server tomcat server

The project needs to be deployed to a CentOS server, which already has an nginx and MySQL installed on it, running in a PHP environment, and a project is in progress. And our latest project is written in Java, the server is used tomcat, so it is bound to have nginx and Tomcat to do a consolidation, but the project is still in the development phase, we first use the Tomcat default port 8080, OK, the following is probably your "terminal" ( Because I am using a Mac system, the default is SSH, if it is win system, please choose other corresponding tools, believe that g God will help you ~ ~).
Hundred Cattle Information Technology Bainiu.ltd organized and published in the blog Park
First step: Connect the server
Leased server support SSH connection, that is, graphics is not with us, by the way we can also enjoy the "master" feeling
Enter the following command at the terminal:
The code is as follows:

SSH server IP address-L user name
After you enter, the screen will appear similar to the following:
The code is as follows:

User name @ server IP address ' s password:
Enter the password directly in the back, for the sake of security, you enter the content is really invisible, do not doubt your eyes, do not doubt your keyboard, do not doubt your hand, you boldly enter the password it, please remember, you have three chances Oh ~
When you see the following words, congratulations, you have logged on to the server, you can do whatever you like ~ haha
The code is as follows:

[User name @ server IP address ~]#
Step Two: Uninstall the open JDK
Cent OS default will install an open JDK, but we do not appreciate, in order to reduce the trouble, we still like to use Sun's JDK, so we have to uninstall the open JDK first.
First, let's use the following command to find out what we have installed on Java.
The code is as follows:

Rpm-qa|grep Java
The information returned on my server is as follows:
The code 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
This is what we really want to delete is Java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5 and java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 on the can, respectively, using the following command can be done:
The code is as follows:

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 again, openjdk whether really be uninstalled clean:
The code is as follows:

Java-version
The system returns the following:
The code is as follows:

-bash:/usr/bin/java:no such file or directory
Well, so far we've completely done the open JDK, thanks to RPM, it's a lot to save
Step three: Get Software (JDK\TOMCAT)
We went to Sun's official and Apache website to download the JDK and Tomcat to the local computer, as follows:
Jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk6-downloads-1637591.html
I choose
This version, 64-bit version, for RPM, and now the project does not use what JAVA7 advanced features, we will be honest with JDK6.
Tomcat:http://labs.renren.com/apache-mirror/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz
Tomcat this decompression of the use of green software is the best, less worry, continue to the old version of the document, over paragraph selected Tomcat6.
Here we upload these two files separately to my other FTP server, and then use wget this tool to download two software to the server, wget This tool is a simple and powerful download tools, in fact, we can also choose to download directly from the official website, But the JDK because of the need to manually agree to a protocol, so then a piece of the use of FTP as a broker, the specific command line is as follows:
The code is as follows:

wget ftp://ftp Server Address/jdk-6i33-linux-x64-rpm.bin
The code is as follows:

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>
It is important to note here that you are executing this command in that directory, and the file will be downloaded in that directory. For the students who are not familiar with Linux, still need to remember the main folders and use, so as not to waste time.
Fourth step: Installing the JDK
In the directory where you just downloaded the software, execute the following command directly:
The code is as follows:

./jdk-6u33-linux-x64-rpm.bin
Then the screen will show the progress, after completion, or test it, enter:
The code is as follows:

Java-version
If the following content is displayed, congratulations, the Java environment has been done!
The code is as follows:

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)
Fifth step: Installing Tomcat installation Tomcat is actually quite simple, first select a directory, usually using the/usr/local directory, using the CD command to jump:
The code is as follows:

Cd/usr/local
Then download the directory from Tomcat's official website with the following command:
The code is as follows:

wget http://labs.mop.com/apache-mirror/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz
Then unzip the compressed package file
The code is as follows:

TAR-ZXVF apache-tomcat-6.0.35.tar.gz Tomcat
This time using the LS command to see a directory called Tomcat. So tomcat is installed, simple. Starting Tomcat is also straightforward, go directly to the Tomcat/bin directory and execute:
The code is as follows:

SH statrup.sh
If there is no error, congratulations, this time you directly in the browser input your IP (or domain name): 8080, you can see the three-legged cat. If you start an error, or do not see a three-foot cat, it may be because of a configuration file where I then modified the/etc/profile file to include the following in the last line:
The code is as follows:

Export java_home=/usr/java/jdk1.6.0_33/
Export JRE_HOME=/USR/JAVA/JDK1.6.0_33/JRE
Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH
Export lasspath=.:/ Usr/java/jdk1.6.0_33/lib:/usr/java/jdk1.6.0_33/jre/lib: $CLASSPATH
Export Tomcat_home=/usr/local/tomcat
Then go back to the command line and execute:
The code is as follows:

Source/etc/profile
So that we have just the configuration to take effect, so you can try again, should be able to, but must pay attention to the directory is correct, must!
Sixth step: Configure MySQL (for garbled characters)
Because I got the server, MySQL is already installed, it was thought to be easy, but later the project deployment, English is no problem, but the Chinese have become hello, let me very angry, after a Google, once again sacrificed, Utf-8 Dafa, Make sure all the codes are utf-8. If you also encounter this problem, believe that the following content can help you.
1, Login database:
The code is as follows:

Mysql-u root-p
Then enter a password, enter after you can see the following conditions on behalf of the success of the login:
The code is as follows:

Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 11218
Server version:5.0.95 Source Distribution

Copyright (c), +, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>
2 Select the database to which you want to change the encoding
The code is as follows:

Mysql>use database name
3 Checking the current database encoding situation
The code is as follows:

Show variables like "%char%";
The results returned on my machine are as follows:
The code is 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)
Of these attributes, our goal is actually to change those encodings to utf-8, and after I have tested them, the real impact of the value should be character_set_database\character_set_server\character_set_ System This three value, especially the first one, if it is not utf-8, no matter how all will appear question mark, and like above results, Chinese actually also show normal, this I also feel very strange also.
4 Modify the encoding of the database to Utf-8, execute the following statement
The code is as follows:

Mysql>set names UTF8;
Especially note that in MySQL, there is no connector in the middle of the Utf-8 code, this particular note!
5 exiting MySQL
The code is as follows:

mysql>exit;
6 editing the MySQL configuration file
The code is as follows:

Vim/etc/my.cnf
7 Modify the configuration file to the following conditions:
The code is as follows:

[Mysqld]
Datadir=/var/mysql
Socket=/var/lib/mysql/mysql.sock
User=mysql
Default-character-set = UTF8
# Default to using old password format for compatibility with MySQL 3.x
# clients (those using the Mysqlclient10 compatibility package).
Old_passwords=1

# Disabling Symbolic-links is recommended to prevent assorted security risks;
# to does so, uncomment the line:
# symbolic-links=0

[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
In fact, add the following sentence:
The code is as follows:

Default-character-set = UTF8
8 restarting MySQL
The code is as follows:

/etc/init.d/mysqld start
This configuration down, the database garbled problem can be solved.
Of course, database garbled is not only a database configuration problem, may also be due to the page file itself encoding, page file to the program encoding and other places need attention, the current solution is in fact unified into utf-8!
Seventh Step: Deploy the Code
Because we only run one project, there is no directory configuration, the project files are packaged directly, extracted into the Tomcat directory under the WebApps directory.
Then reboot the server and get it done!
Tomcat's start command:
The code is as follows:

SH startup.sh
Tomcat's Stop command:
The code is as follows:

SH shutdown.sh
Postscript:
In fact, this note about the end of June began to write, when the project was first deployed to the server, a variety of issues to engage in two nights, a variety of search, but unfortunately their knowledge management did not do well, a lot of good information is so put past, each encounter the same problem, we have to search again, desperately want to search for keywords, Very crazy, this is only the deployment of the situation at the time to tidy up a bit. Some of the mistakes and omissions, welcome to point!
Besides, I've had two more problems lately.
11 deployments, when the Tomcat server was stopped, the Tomcat was turned on immediately, then the newspapers port was occupied, followed by the method mentioned here http://pmfou-site.iteye.com/blog/1484447:
"We ps-ef|grep Java
Find all Java process numbers
Kill-9 Process Number
Take out the process that appears, except username xxx xxx 0 20:56 pts/0 00:00:00 grep--color=auto java "
But when I actually execute it, every kill process is reported without this process, which is normal after various reboots.
2 later the next day, the server often on their own down, and I suspect that the problem was caused by yesterday, and then look at log, found to be memory overflow, in fact, because I was lazy at that time, the project backup has done WebApps, so every time you start Tomcat will bring up, It can then cause a memory overflow, or it may be because our JVM also uses the default configuration. After removing those backups so far the server is working properly!!

Simple documentation of CentOS server configuration Jdk+tomcat+mysql

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.