在企业中使用JavaEE开发,大部分都是基于Linux系统开发,至于是选择Ubuntu或Debian、还是Centos或Redhat等等,那就要看公司的开发环境是什么。不管使用的是哪种linux版本,作为JavaEE开发程序员,都应该学会在Linux上搭建JAVAEE环境,这是每一个java程序员所需要掌握的。
系统版本:centos6.5
1.下载: jdk-7u80-linux-x64.tar.gz
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
2.解压和安装JDK
切换到root用户
[jiang@localhost ~]$ su root
检查系统原版本
[root@localhost jiang]$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
查看JDK信息
[root@localhost jiang]# rpm -qa|grep jdk
java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64
tzdata-java-2016d-1.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.101-2.6.6.1.el7_2.x86_64
java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64
java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
卸载OpenJDK,执行以下操作
[root@localhost jiang]# sudo rpm -e --nodeps tzdata-java-2016d-1.el7.noarch
[root@localhost jiang]# sudo rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.101-2.6.6.1.el7_2.x86_64
[root@localhost jiang]# sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64
[root@localhost jiang]# sudo rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
[root@localhost jiang]# sudo rpm -e --nodeps java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64
进入下载目录
[root@localhost jiang]# cd /home/jiang/Downloads/
[root@localhost jiang]# ll
拷贝JDK压缩文件到/opt目录下
[root@localhost jiang]# cp jdk-7u80-linux-x64.tar.gz /opt
[root@localhost jiang]# cd /opt
[root@localhost jiang]# ll
解压JDK的压缩包
[root@localhost jiang]# tar -zxvf jdk-7u80-linux-x64.tar.gz
[root@localhost jiang]# ll
更改用户组为自己的
[root@localhost jiang]# chown jiang:root jdk1.7.0_80
编辑/etc/profile文件
[root@localhost jiang]# gedit /etc/profice
==================添加以下内容:===================
export JAVA_HOME=/opt/jdk1.7.0_80
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
使修改立即生效
[root@localhost jiang]# source /etc/profice
检测安装是否成功
[root@localhost jiang]# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
(看到以上JDK的版本信息,恭喜U,哈哈……说明已成功安装和配置JDK)
下载:apache-tomcat-7.0.75.tar.gz
http://tomcat.apache.org/download-70.cgi
解压和安装Tomcat7
切换到root用户,并解压tomcat文件
[jiang@localhost ~]$ su root
[root@localhost jiang]$ tar -zxvf apache-tomcat-7.0.75.tar.gz
配置tomcat的环境变量
[root@localhost jiang]$ gedit /etc/profile
==================添加以下内容:===================
#行尾添加tomcat的存放目录
export CATALINA_HOME=/opt/apache-tomcat-7.0.75
使修改立即生效
[root@localhost jiang]# source /etc/profice
进入到apache-tomcat-7.0.75的bin目录
[root@localhost jiang]# cd /opt/apache-tomcat-7.0.75/bin
启动服务器
[root@localhost jiang]# ./startup.sh
检查服务是否成功启动
[root@localhost jiang]# ps -ef | grep tomcat
如果要关闭服务器,使用命令shutdown.sh即可
[root@localhost jiang]# ./shutdown.sh
(汤姆猫也启动成功,主人带你喝杯鱼腥草去。。。。。。)
1.下载:MySQL-server-5.5.48-1.linux2.6.x86_64.rpm、MySQL-client-5.5.48-1.linux2.6.x86_64.rpm、MySQL-devel-5.5.48-1.linux2.6.x86_64.rpm
https://downloads.mysql.com/archives/community/
分别下载以下三个文件(由于我的机器是64位,下载的是64位版本的包,如果你的机器是32位的请下载32位版本):
MySQL-server-5.5.16-1.rhel5.i386.rpm
MySQL-client-5.5.16-1.rhel4.i386.rpm
MySQL-devel-5.5.16-1.rhel4.i386.rpm
使用wget命令使用断点传输的方式将这三个文件下载:
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.48-1.linux2.6.x86_64.rpm/from/http://mysql.spd.co.il/
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.48-1.linux2.6.x86_64.rpm/from/http://mysql.spd.co.il/
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.48-1.linux2.6.x86_64.rpm/from/http://mysql.spd.co.il/
2.检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost ~]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64
要将 /var/lib/mysql文件夹下的所有文件都删除干净
[root@localhost ~]# rm -rf /var/lib/mysql
3.安装MySQL
[root@localhost downloads]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.x86_64.rpm
[root@localhost downloads]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.x86_64.rpm
[root@localhost downloads]# rpm -ivh MySQL-devel-5.5.48-1.linux2.6.x86_64.rpm
4.启动mysql服务
[root@localhost ~]# service mysql start
Starting MySQL SUCCESS!
5.进入mysql后台
[root@localhost ~]# mysql
===============若出现以下提示信息,说明成功=================
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
6.修改配置文件位置,此版本的默认配置文件是my-huge.cnf,有些版本的是
my-default.cnf。
[root@localhost ~]# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
7.修改默认密码
首次安装时,默认密码为空,可以使用如下命令修改root密码。
[root@localhost ~]# mysqladmin -u root password yourpassword(后面跟着是这里设置你的新密码)
8.远程登陆用户设置
mysql> use mysql;
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| 127.0.0.1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| ::1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
+-----------------------+------+-------------------------------------------+
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit
9.设置开机自启动
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
10.MySQL的默认安装位置
/var/lib/mysql/ #数据库目录
/usr/share/mysql #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/mysql #启动脚本
11.修改字符集和数据存储路径
配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8。
[client]
password = 123456
port = 3306
default-character-set=utf8
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
lower_case_table_names=1
#(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )
max_connections=1000
[mysql]
default-character-set = utf8
12.如果想远程连接登录mysql,则需要:授权,关闭防火墙。
a. 授权;在服务端进入mysql,输入以下命令。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里是你的密码' WITH GRANT OPTION;
b. 关闭防火墙
[root@localhost ~]# service iptables stop 关闭命令
[root@localhost ~]# chkconfig iptables off 永久关闭防火墙
下载:eclipse-jee-mars-R-linux-gtk-x86_64.tar.gz
http://www.eclipse.org/downloads/packages/release/mars/r
解压和安装Eclipse
解压缩下载的文件到/opt目录下
[jiang@localhost ~]$ sudo tar -zxvf eclipse-jee-mars-R-linux-gtk-x86_64.tar.gz -C /opt
快捷启动eclipse方式一:创建链接
[jiang@localhost ~]$ su root
[root@localhost jiang]$ ln -s /opt/eclipse/eclipse /usr/bin/eclipse
快捷启动eclipse方式二:创建桌面快捷方式之编写文件
[root@localhost jiang]$ gedit /usr/share/applications/eclipse.desktop
==================添加以下内容:===================
[Desktop Entry]
Type=Application
Name=eclipse
Exec=/opt/eclips/eclipse //eclipse应用程序
GenericName=eclipse
Comment=Java development tools
Icon=/opt/eclipse/icon.xpm //eclipse图标
Categories=Application;Development;
Terminal=false
然后保存,就可以在application->development下面看到eclipse选项了。
快捷启动eclipse方式三:创建桌面快捷方式之直接操作
桌面右击鼠标选择Create Launcher(创建启动器),点击Browse…(浏览(B)),找到eclipse应用程序的解压目录/opt/eclipse/eclipse,点击OK(确定(O)),就完成了。
(至此已成功安装Eclipse)