Centos配置J2EE环境

步骤一:安装JDK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# cd /usr/java
# wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u76-b13/jdk-7u76-linux-x64.rpm -O jdk-7u76-linux-x64.rpm
[root@VM_49_244_centos java]# rpm -ivh jdk-7u76-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...
[root@VM_49_244_centos java]# java -version
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

步骤二:设置默认JDK

1
2
3
4
5
6
7
8
9
10
[root@VM_49_244_centos /]# alternatives --install /usr/bin/java java /usr/java/default/bin/java 776
[root@VM_49_244_centos /]# alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/java/default/bin/java
Enter to keep the current selection[+], or type selection number: 1

步骤三:设置环境变量

修改/etc/profile
在末尾加上

1
2
3
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

步骤四:测试JDK

新建测试文件test.java

1
2
3
4
5
public class test{
public static void main(String args[])
{
System.out.println("hello world");
}

测试

1
2
3
[root@VM_49_244_centos]# javac test.java
[root@VM_49_244_centos]# java test
hello world

步骤五:安装Maven

1
2
3
4
5
# cd /usr/maven
# wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip
# unzip apache-maven-3.1.1-bin.zip
# mv apache-maven-3.1.1/ /opt/maven
# ln -s /opt/maven/bin/mvn /usr/bin/mvn

步骤六:配置环境变量

编辑 /etc/profile
在尾部添加MAVEN_HOME,并在PATH中添加$MAVEN_HOME/bin

1
2
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
export MAVEN_HOME=/opt/maven

步骤七:测试Maven

1
2
3
4
5
6
7
[root@VM_49_244_centos ~]# mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /opt/maven
Java version: 1.7.0_76, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_76/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-504.30.3.el6.x86_64", arch: "amd64", family: "unix"

步骤八:配置mysql

1
# yum install -y mysql-server mysql mysql-deve

查看刚安装好的mysql-server的版本

1
# rpm -qi mysql-server

步骤九:安装Tomcat

1
2
#cd /usr/Tomcat
# wget http://http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.68/bin/apache-tomcat-7.0.68.zip

解压后启动Tomcat(__为Tomcat所在路径,本案例为/usr)

1
2
# cd __/Tomcat/apache-tomcat-7.0.68/bin/
# startup.sh

步骤十:测试Tomcat

访问 http:\ip:8080,如果出现以下界面则成功:
这里写图片描述


其他事项

事项一:开机自动开启tomcat
编辑 /etc/rc.d/rc.local
加入如下内容(__为Tomcat所在路径,本案例为/usr)

1
2
# __/Tomcat/apache-tomcat-7.0.68/bin/startup.sh
```

事项二:开启SSLv3
进入java.security文件(__为java所在路径,本案例为/usr)

1
2
# cd __/java/default/jre/lib/security
# vi java.security

在最后一行jdk.tls.disabledAlgorithms=SSLv3前加上“#”

1
# jdk.tls.disabledAlgorithms=SSLv3