Centos + JDK + Tomcat + MySQL & jdbcdriver

Source: Internet
Author: User
0 Introduction

Tomcat is the classic and most popular environment for Java Web development. It is not only free, open-source, but also very stable, and has a large number of users. As a result, various related resources on the Internet are also abundant. Tomcat is a cross-platform product that supports common Server OS. MySQL is the preferred Database Management System for individuals and small and medium-sized enterprises. It is open-source and free of charge and widely used. It also supports various Server OS. In the spirit of open-source and free-of-charge, of course, OS is also the most suitable for the same open-source and free. Currently, it is not centos.

The basic idea for setting up this environment is not to install useless things, to keep the system simple and efficient. Java, tomcat, and MySQL are all installed in green, rather than using Installation Tools such as Yum or RPM.

1. Currently, centos virtualization is very common. Therefore, this environment is also deployed on virtual machines. This time, esxi5 is selected as the host system to install the centos client OS. The allocated hard disk size is 100 GB, And the partition is arranged as follows: /Dev/sda1 50 GB/var /Dev/sda2 30 GB/OPT --------------------------------- install Java, tomcat, and MySQL in green /Dev/sda3 10 Gb/usr /Dev/sda5 5 Gb/ /Dev/sda6 5 GB swap1.1 download and install the latest centos to the http://www.centos.org official website to download the CentOS-6.3-x86_64-minimal.iso this minimum installation version can be, as the server to use, it is strongly recommended not to install useless things, especially gnome such GUI components, it is unnecessary. 1.2 after centos is installed by default, perform the following Configuration: (0) configure the network to enable Internet accessI don't want to elaborate on this step. Anyone familiar with Linux knows it. Note: if any problem occurs, refer to the solution to the conflict between netmanager and network services. (1) run the following script to disable SELinux.Setenforce 0 # Close immediately. This start time is effective. For the next start time, you need to modify the/etc/SELinux/CONF file and set SELinux = disabled. (2) install wget and VIM with yumYum install wget # wget is used to download tomcat, Java, MySQL, and other installation packages. Yum install Vim # Vim is used to modify the configuration file. Note: If yum is faulty, see http://blog.csdn.net/smstong/article/details. (3) configure the firewall to prepare for Tomcat and MySQLIptables-I input-P TCP -- dport = 8080-J accept # open port 8080 (Tomcat) iptables-I input-P TCP -- dport = 3306-J accept # Open Port 3306 (MySQL) Service iptables save # Save the firewall configuration to the configuration file 2 install and configure JDK 2.1 install JDK in greenUse wget to the http://www.oracle.com official website to download the jdk-7u2-linux-x64.tar.gz and tar-xzvf unzip the installation package to/opt/, unzip the installation, which is green installed. 2.2 configure Environment VariablesHowever, you also need to configure some environment variables as follows: Export java_home =/opt/jdk1.7.0 _ 05 export Path =/opt/jdk1.7.0 _ 05/bin: /opt/jdk1.7.0 _ 05/JRE/bin: $ pathexport classpath =. /:/opt/jdk1.7.0 _ 05/JRE/lib/DT. jar:/opt/jdk1.7.0 _ 05/JRE/lib/tools. jar at this time, you can write a helloworld Java Applet, and then compile it through javac and execute it through java. If it can be executed smoothly, it indicates that JDK installation is no problem. 3 install and configure MySQL 3.1 install MySql in greenDownload mysql-5.25a-linux2.6-x86_64.tar.gz from the http://www.mysql.com official network and decompress it to/OPT through tar-xzvf. Follow the instructions on the install-binary file in the installation package. The excerpt is as follows:
Shell> groupadd MySQL
Shell> useradd-r-g MySQL
Shell> Cd/OPT
Shell> tar zxvf/path/to/mysql-VERSION-OS.tar.gz
Shell> ln-s full-path-to-mysql-version-OS MySQL
Shell> Cd MySQL
Shell> chown-r MySQL.
Shell> chgrp-r MySQL.
Shell> scripts/mysql_install_db -- user = MySQL
Shell> chown-r root.
Shell> chown-r Mysql Data
# Next command is optional
Shells> CP support-files/my-medium.cnf/etc/My. CNF
Shell> bin/mysqld_safe -- user = MySQL & shell> CP support-files/MySQL. server/etc/init. d/MySQL and then modify/etc/init. in the D/MySQL file, set basedir =/opt/mysqldatadir =/opt/MySQL/data to start/stop the MySQL database service through service MySQL start/stop. Shell> chkconfig -- add MySQL to automatically start the MySQL service. 3.2 configure the root password and remote access
Mysqladmin-u root-P oldpassword newpassword then, go to the bin directory and run./MySQL-u root-pnewpassword to enter the MySQL command interface. Mysql> grant all privileges on *. * to root @ "%"
Identified by "yourpasswd ";
Mysql> flush privileges; in this way, you can access it from other machines and find a machine with a mysql client. If the machine IP address can be accessed through mysql-uroot-ppassword-h, the installation is correct. 3.3 modify MySQL encoding to UTF-8Refer to my blog: http://blog.csdn.net/smstong/article/details/7285495 4. Install the MySQL JDBC driver 4.1 download and decompressDownload mysql-connector-java-5.1.21.tar.gz from the http://www.mysql.com and decompress it to/OPT. 4.2 modify Environment VariablesExport classpath = $ classpath:/opt/mysql-connector-java-5.1.21/mysql-connector-java-5.1.21-bin.jar Add the driver jar package to classpath. Write a test JDBC test program. If the program can be compiled and run successfully, the JDBC driver is installed correctly.
5 installation configuration tomcat5.1 download unzip Tomcat Go To The http://tomcat.apache.org official website to download the latest version: apache-tomcat-7.0.29.tar.gz, unzip to/opt /. 5.2 Configuration (0) Configure Environment VariablesCatalina_home =/opt/apache-tomcat-7.0.29
Catalina_base =/opt/apache-tomcat-7.0.29
(1) Modify connector encoding to UTF-8In the configuration file CONF/server. XML, <connector Port = "8080" protocol = "HTTP/1.1"
Connectiontimeout = "20000"
Uriencoding = "UTF-8"
Redirectport = "8443" type = "regxph" text = "yourobjectname"/>
(2) start TomcatRun bin/startup. SH and enter: http: // machine IP Address: 8080 in the browser. If it is correctly displayed, the Tomcat deployment is correct. If it is incorrect, check the logs/catalinaxxx. log analysis solution. (3) Add the Tomcat class library to classpath for javac compilation and useExport classpath = $ classpath:/opt/Apache-Tomcat-7.0.29/lib/servlet-api.jar create a servlet application under webapps. After javac is compiled, test whether it can be correctly executed.
6. Only temporary environment variables are set after environment variables are integrated. The correct environment variables will be automatically configured even after restart, integrate the preceding environment variables and write them into the/etc/profile configuration file: java_home =/opt/jdk1.7.0 _ 05
Path =/opt/jdk1.7.0 _ 05/bin:/opt/jdk1.7.0 _ 05/JRE/bin: $ path
Classpath =. /:/opt/jdk1.7.0 _ 05/JRE/lib/DT. jar:/opt/jdk1.7.0 _ 05/JRE/lib/tools. jar:/opt/Apache-Tomcat-7.0.29/lib/servlet-api.jar:/opt/mysql-connector-java-5.1.21/mysql-connector-java-5.1.21-bin.jar
Catalina_home =/opt/apache-tomcat-7.0.29
Catalina_base =/opt/apache-tomcat-7.0.29
Export java_home path classpath catalina_home catalina_base
7. So far, a pure open-source, pure free, and pure green Java Web development and runtime environment has been set up, and development has started. Please continue to pay attention to it.

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.