CentOS 6 安装配置JDK+tomcat环境
程序员文章站
2022-12-16 09:55:33
1.安装OpenJDK 这里安装的OpenJDK,是开源版本的JDK,我们平时自己电脑上安装的是 Sun JDK(也叫Oracle JDK),OpenJDK可以看作Sun JDK的精简版。 如果想安装SunJDK,请参照下方的tomcat安装方法,步骤是一样的,注意liunx有些自带OpenJDK, ......
1.安装openjdk
这里安装的openjdk,是开源版本的jdk,我们平时自己电脑上安装的是 sun jdk(也叫oracle jdk),openjdk可以看作sun jdk的精简版。
如果想安装sunjdk,请参照下方的tomcat安装方法,步骤是一样的,注意liunx有些自带openjdk,需卸载。
注意,安装openjdk简单迅速,只需一条命令,且无需配置环境变量
①查看是否已经安装了jdk
java -version rpm -qa |grep java rpm -qa |grep jdk
②若有如何卸载
卸载jdk相关文件输入:
yum -y remove java-1.8.0-openjdk*
卸载tzdata-java输入:
yum -y remove tzdata-java.noarch
③安装
yum list java* #查看版本 yum list java-1.8* #查看1.8版本 yum install java-1.8.0-openjdk* -y # 安装
执行:
[root@localhost ~]# yum -y install java-1.8.0-openjdk* loaded plugins: fastestmirror setting up install process loading mirror speeds from cached hostfile * base: repos-lax.psychz.net * elrepo-kernel: repos.lax-noc.com * extras: repos-lax.psychz.net * updates: mirrors.oit.uci.edu resolving dependencies --> running transaction check ---> package java-1.8.0-openjdk.i686 1:1.8.0.191.b12-0.el6_10 will be installed ... complete!
④检查安装结果
[root@localhost ~]# java -version openjdk version "1.8.0_191" openjdk runtime environment (build 1.8.0_191-b12) openjdk server vm (build 25.191-b12, mixed mode)
执行java和javac,正常,无需配置环境变量
3.安装tomcat
①去官网下载安装包
https://tomcat.apache.org/download-90.cgi 这里我下的是9.0的版本
②上传至服务器然后解压
这里我用的filezilla 上传到ftp账户里
[root@localhost ftpuser]# ls 222 apache-tomcat-9.0.13.tar.gz dir1-0 dir1-1
然后复制此文件到/usr/local/tomcat/目录下
tomcat目录为自己创建,安装对路径并无要求
[root@localhost ftpuser]# cp apache-tomcat-9.0.13.tar.gz /usr/local/tomcat/ [root@localhost ftpuser]# cd /usr/local/tomcat [root@localhost tomcat]# ls apache-tomcat-9.0.13.tar.gz
进入文件所在目录解压即可
[root@localhost tomcat]# tar zxvf apache-tomcat-9.0.13.tar.gz
③启动tomcat
[root@localhost tomcat]# cd apache-tomcat-9.0.13/bin [root@localhost bin]# ./startup.sh using catalina_base: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_home: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_tmpdir: /usr/local/tomcat/apache-tomcat-9.0.13/temp using jre_home: /usr using classpath: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar tomcat started.
关闭防火墙或者开放端口后,即可用任意一台设备访问tomcat
开启端口 [root@localhost ~]# /sbin/iptables -i input -p tcp –dport 8080 -j accept #开启8080端口 [root@localhost ~]# /etc/rc.d/init.d/iptables save #保存配置 [root@localhost ~]# /etc/rc.d/init.d/iptables restart #重启防火墙 关闭防火墙 service iptables stop #暂时关闭 chkconfig iptables off #设置成开启不自启
如我在自己电脑的浏览器输入 服务器ip:8080
④查看tomcat版本
[root@localhost bin]# ./catalina.sh version using catalina_base: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_home: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_tmpdir: /usr/local/tomcat/apache-tomcat-9.0.13/temp using jre_home: /usr using classpath: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar server version: apache tomcat/9.0.13 server built: nov 2 2018 14:27:55 utc server number: 9.0.13.0 os name: linux os version: 4.10.4-1.el6.elrepo.i686 architecture: i386 jvm version: 1.8.0_191-b12 jvm vendor: oracle corporation [root@localhost bin]#
⑤关闭tomcat
查看tomcat是否运行
ps -ef | grep tomcat [root@localhost bin]# ps -ef | grep tomcat root 6975 6663 0 11:43 pts/1 00:00:00 grep tomcat
关闭tomcat(执行shutdown.sh脚本)
[root@localhost apache-tomcat-9.0.13]# cd bin [root@localhost bin]# ./shutdown.sh using catalina_base: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_home: /usr/local/tomcat/apache-tomcat-9.0.13 using catalina_tmpdir: /usr/local/tomcat/apache-tomcat-9.0.13/temp using jre_home: /usr using classpath: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar
⑥卸载tomcat
直接删除安装目录
rm -rf /usr/local/tomcat/apache-tomcat-9.0.13
上一篇: C# 遍历Dictionary并修改其中的Value
下一篇: 自媒体如何变现,再分享几点盈利之道!