yum安装java和tomcat环境
前言
linux上安装软件,可以用yum非常方便,不需要下载解压,一个指令就能用yum安装java和tomcat环境。
前面一篇已经实现在阿里云服务器上搭建一个禅道系统的网站,算是小有成就,但并不是每个网站搭建都是这么简单的。
一般开发包是一个.war的文件,这就需要用到一个中间键,比如tomcat了,tomcat又是依赖于java环境的,所以先安装java环境
环境准备:
1.Linux 系统服务器: CentOS 7
2.yum 3.4.3
3.java 1.8
4.tomcat
yun环境
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。
基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
由于需要安装java环境,按照前面一篇先下载安装包,再通过Xftp传到服务器上指定目录,再解压安装当然是可以的,只是过程太繁琐。
为了解决每次下载拖过去这种复杂的操作,于是linux上有个非常方便的小工具yum,可以直接下载安装。有点类似于python里面的pip工具,用过的人都知道好!
首先检查下当前系统里面有没有yum工具,有的话就不用安装了。我这边系统里面显示已经有这个工具了yum-3.4.3,所以无需安装。
rpm -qa | grep yum
yum-plugin-fastestmirror-1.1.31-52.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-3.4.3-163.el7.centos.noarch
java环境
先查看是否有java环境: rpm -qa | grep java
如果没有java环境的话,接着就去查找java-1.8.0的可以使用的安装包:yum list | grep java-1.8.0-openjdk
java-1.8.0-openjdk.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-accessibility-debug.i686
java-1.8.0-openjdk-accessibility-debug.x86_64
java-1.8.0-openjdk-debug.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch
java-1.8.0-openjdk-src.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-src-debug.i686 1:1.8.0.191.b12-1.el7_6 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
安装java-1.8.0-openjdk所有的文件
yum -y install java-1.8.0-openjdk*
安装过程需要1-2分钟,查看版本号:java -version
[root@iZuf6ioqjurm735f27tylyZ ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
接着输入javac,如果能看到内容输出就说明已经安装好了
[root@iZuf6ioqjurm735f27tylyZ ~]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
tomcat安装
tomcat安装可以先下载安装包,再解压。也可以直接用yum在线安装,这里我们直接用yum在线安装更方便
yum install tomcat
//或者
yum -y install tomcat
-y 代表遇到询问都选 y,这样安装过程中就不需要手动输入y了
安装完成后,安装目录在 “/usr/share/tomcat” , 我们用 cd 命令切到这个目录,用 ls(或ll) 命令查看这个目录里面的文件
[root@yoyo tomcat]# ls
bin conf lib logs temp webapps work
[root@yoyo tomcat]# ll
total 4
drwxr-xr-x 2 root root 4096 Dec 28 10:41 bin
lrwxrwxrwx 1 root tomcat 11 Dec 28 10:41 conf -> /etc/tomcat
lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 lib -> /usr/share/java/tomcat
lrwxrwxrwx 1 root tomcat 15 Dec 28 10:41 logs -> /var/log/tomcat
lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 temp -> /var/cache/tomcat/temp
lrwxrwxrwx 1 root tomcat 23 Dec 28 10:41 webapps -> /var/lib/tomcat/webapps
lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 work -> /var/cache/tomcat/work
启动tomcat服务
查看tomcat的状态:systemctl status tomcat
[root@yoyo tomcat]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: inactive (dead)
启动tomcat: systemctl start tomcat (或systemctl start tomcat.service)
[root@yoyo tomcat]# systemctl start tomcat
[root@yoyo tomcat]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2018-12-28 10:48:38 CST; 5s ago
Main PID: 5216 (java)
CGroup: /system.slice/tomcat.service
└─5216 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin...
Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.core.StandardService startInternal
Dec 28 10:48:38 yoyo server[5216]: INFO: Starting service Catalina
Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.core.StandardEngine startInternal
Dec 28 10:48:38 yoyo server[5216]: INFO: Starting Servlet Engine: Apache Tomcat/7.0.76
Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.coyote.AbstractProtocol start
Dec 28 10:48:38 yoyo server[5216]: INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.coyote.AbstractProtocol start
Dec 28 10:48:38 yoyo server[5216]: INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.startup.Catalina start
Dec 28 10:48:38 yoyo server[5216]: INFO: Server startup in 61 ms
Hint: Some lines were ellipsized, use -l to show in full.
[root@yoyo tomcat]#
访问tomcat
tomcat默认端口是8080,接下来浏览输入地址:http://服务器公网ip:8080/。这个页面暂时是无法访问
由于tomcat的web页面是需要安装插件的,这里继续用 tomcat-webapps 和 tomcat-admin-webapps 两个插件包
yum install tomcat-webapps tomcat-admin-webapps
安装完之后,8080端口还是无法访问,需要登录阿里云 ECS后台管理,打开云服务器ECS-安全组-配置规则
添加安全组规则,新增8080端口访问权限
- 规则方向:入方向
- 协议类型:自定义 FTP
- 端口范围: 8080/8080
- 授权对象:0.0.0.0/0
再去浏览器访问http://服务器公网ip:8080, 就可以打开tomcat的地址了
Manager App用户名和密码
如果想进入 Manager App,在首页点 Manager App
会有个弹出框,输入用户名和密码
直接点取消,会出现401界面
复制出红色框框的这两行,可以直接设置username=“root” password=“root”
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
接着点开xshell,进入 tomcat 安装目录(cd /usr/share/tomcat),进入 conf 目录,打开 tomcat-users.xml 文件,在 标签下,添加如下配置:
<role rolename="manager-gui"/>
<user username="root" password="root" roles="manager-gui"/>
编辑文件,可以用vi或vim点开文件直接编辑
cd /usr/share/tomcat
cd conf
vim tomcat-users.xml
vim点开后,按键盘是 i 键 ,进入编辑状态,鼠标移动到最后一行 上方,直接粘贴进去就行了
tomcat相关命令
停止tomcat服务
systemctl stop tomcat
重启tomcat
systemctl restart tomcat
开机启动
systemctl enable tomcat
查看tomcat状态
systemctl status tomcat
启动tomcat
systemctl start tomcat