Linux(二十)搭建JavaEE环境
Posted leeqico
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux(二十)搭建JavaEE环境相关的知识,希望对你有一定的参考价值。
如果需要在Linux下进行JavaEE的开发,我们需要安装如下软件:
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-d2df238167cf418e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
先将软件通过Xftp5上传到/opt下
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-de2abea377ba3fd9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
20.1 安装JDK
(1)解压到/opt
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-2b5d466127f6854a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(2)配置环境变量的配置文件vim /etc/profile
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-cf6a962263e82661.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
按G就会切换到最后一行,按i进行编辑,esc退出,然后输入:qw!,保存退出!
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-7525ec21fede3f51.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(3)需要注销用户,环境变量才能生效
(4)在任何目录下都可以使用java或者javac
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-756073c2a941ea1a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(5)测试是否安装成功,编写一个简单的Hello.java
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-f06d5e11d30a2625.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-75ece1c6ac274b0f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
20.2 安装tomcat
(1)解压到/opt下
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-cf7f2c217e0fea68.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-339575d93ac45221.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(2)启动tomcat,先进入到tomcat的bin目录下,然后输入./startup.sh
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-2ff205e01ca92e09.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
如果你不是远程登录linux的话,而且是在运行级别为5的情况下,可以利用linux浏览器访问。
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-efa20658e9dc0cde.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(3)开放端口8080,这样外网才能访问到tomcat
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-e0feec42d63741e5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
yy+c复制22端口的那行,然后修改为8080即可
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-ce7c7e26f59de032.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
重启防火墙
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-ca9dfb4da2fe67c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(4)测试是否安装成功,在window的浏览器下输入http://linuxip:8080
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-d9801bcd48efabed.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-d7ab8830d9548595.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
20.3 Eclipse的安装
(1)解压到/opt下
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-df4f3de895b4291b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(2)启动Eclipse,配置jre和server
启动方式1:创建一个快捷方式
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-9135c3a475ece7a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-a744e09067049a45.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-07a2f5950949f733.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
启动方式2:进入到eclipse解压后的文件夹,然后执行./eclipse即可
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-d4ed936d5704ff11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(3)编写jsp,并测试成功
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-f1c3b9980a8b5f92.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-f6c36534d6621749.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-5efbd3ecbdfceb5d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
16.4 mysql的安装和配置
CentOS 6.8下编译安装MySQL5.6.14
(1)卸载旧版本
使用下面的命令检查是否安装有MySQL Server
rpm -qa | grep mysql
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-6250f32c677dfc65.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
有的话通过下面的命令来卸载掉
目前我们查询到的是有的,接下来解删除它吧
rpm -e mysql-libs-5.1.73-7.el6.x86_64 //普通删除模式
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-987aac2bdfa76efa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64 // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-9a0ed41cb0cc243e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
再检查一下,确定没有mysql了
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-551e1529ddb13ac7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
(2)安装MySQL
安装编译代码需要的包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
解压
tar -zxvf mysql-5.6.14.tar.gz
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-2e0baf1409a52427.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
cd mysql-5.6.14
编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
编译并安装
make && make install
整个过程需要30分钟左右……漫长的等待
(3)配置MySQL
设置权限
使用下面的命令查看是否有mysql用户及用户组
cat /etc/passwd 查看用户列表
cat /etc/group 查看用户组列表
如果没有就创建
groupadd mysql
useradd -g mysql mysql
修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
初始化配置,进入安装路径(在执行下面的指令),执行初始化配置脚本,创建系统自带的数据库和表
cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql [这是一条指令]
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是/usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在CentOS6.8版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
修改名称,防止干扰:
mv /etc/my.cnf /etc/my.cnf.bak
我的系统中没有,就忽略吧。进行
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-b3ff325afd3ccf19.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
启动MySQL
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
[注意在 /usr/local/mysql 下执行]
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start --启动MySQL
执行下面的命令修改root密码
cd /usr/local/mysql/bin
./mysql -uroot
mysql> SET PASSWORD = PASSWORD(‘123456‘);
简单使用:
show databases;
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-753a8177d9da5320.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建一个数据库 DB1
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-85fe85057a679607.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建一张表user
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-79d0ddc5a72379bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
添加一个用户,如果成功,说明我们的数据库就安装成功了!
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-4c2c3ef90537ef44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-e4e1d32f64e65aeb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
下次登录就要这样了!
![技术分享图片](https://upload-images.jianshu.io/upload_images/2058461-58e4018258bcf1ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
以上是关于Linux(二十)搭建JavaEE环境的主要内容,如果未能解决你的问题,请参考以下文章
Linux中搭建JavaEE环境之安装jdk-1.8和Tomcat
Linux 学习笔记Linux 搭建 JavaEE 环境(包括 JDKIDEAMySQLtomcat)