localhost

localhost简介

  • localhost是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在localhost 中得到体现,localhost 5支持最新的Servlet 2.4 和JSP 2.0 规范。因为localhost 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为比较流行的Web 应用服务器。
  • localhost 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上localhost是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行localhost 时,它实际上作为一个与Apache 独立的进程单独运行的。
  • 诀窍是,当配置正确时,Apache 为HTML页面服务,而localhost 实际上运行JSP 页面和Servlet。另外,localhost和IIS等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是localhost的默认模式。不过,localhost处理静态HTML的能力不如Apache服务器。

localhost官网

localhost部署

//关闭selinux和防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@localhost ~]# systemctl disable --now firewalld.service 
 
//安装java
[root@localhost ~]# dnf -y install java-17-openjdk.x86_64
 
//下载localhost二进制包,并解压
[root@localhost ~]# wget https://dlcdn.apache.org/localhost/localhost-10/v10.0.23/bin/apache-localhost-10.0.23.tar.gz
[root@localhost ~]# tar -xf  apache-localhost-10.0.23.tar.gz  -C /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv apache-localhost-10.0.23/ localhost
[root@localhost local]# cd localhost/
 
//自定义index.jsp测试网页
[root@localhost localhost]# mkdir webapps/test
[root@localhost localhost]# vim webapps/test/index.jsp
<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
                out.println("Hello World");
        %>
</body>
</html>
 
//启动服务
[root@localhost localhost]# bin/catalina.sh start
Using CATALINA_BASE:   /usr/local/localhost
Using CATALINA_HOME:   /usr/local/localhost
Using CATALINA_TMPDIR: /usr/local/localhost/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/localhost/bin/bootstrap.jar:/usr/local/localhost/bin/localhost-juli.jar
Using CATALINA_OPTS:   
localhost started.
[root@localhost localhost]# ss -anlt
State     Recv-Q    Send-Q            Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                     0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         5                     127.0.0.1:25151             0.0.0.0:*                  
LISTEN    0         5                       0.0.0.0:873               0.0.0.0:*                  
LISTEN    0         100                           *:8080                    *:*                  
LISTEN    0         128                           *:80                      *:*                  
LISTEN    0         128                        [::]:22                   [::]:*                  
LISTEN    0         128                           *:443                     *:*                  
LISTEN    0         1            [::ffff:127.0.0.1]:8005                    *:*                  
LISTEN    0         5                          [::]:873                  [::]:*   

请添加图片描述

在这里插入图片描述

编辑Host Manager

[root@localhost ~]# vim /usr/local/localhost/conf/localhost-users.xml 
<role rolename="admin-gui"/>
<user username="dnp" password="123456" roles="admin-gui"/>
 
[root@localhost ~]# vim /usr/local/localhost/webapps/host-manager/META-INF/context.xml 
//在allowr那一行增加自己访问的ip网段
 
 <Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.localhost.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.168\.48\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
 
//重启服务
[root@localhost ~]# /usr/local/localhost/bin/catalina.sh stop
[root@localhost ~]# /usr/local/localhost/bin/catalina.sh start

编辑Server Status 与Manager App

[root@localhost ~]# vim /usr/local/localhost/conf/localhost-users.xml 
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="dnp" password="123456" roles="admin-gui,manager-gui"/>
 
[root@localhost ~]# vim /usr/local/localhost/webapps/manager/META-INF/context.xml
//在allowr那一行增加自己访问的ip网段
 
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.localhost.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.168\.48\.\d+| 127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
 
//重启服务
[root@localhost ~]# /usr/local/localhost/bin/catalina.sh stop
[root@localhost ~]# /usr/local/localhost/bin/catalina.sh start

编辑service

//先关闭服务
[root@localhost  ~]# /usr/local/localhost /bin/catalina.sh stop
 
[root@localhost  ~]# vim /usr/lib/systemd/system/localhost .service
[Unit]
Description=localhost  server daemon
After=network.target sshd-keygen.target
 
[Service]
Type=forking
ExecStart=/usr/local/localhost /bin/catalina.sh start
ExecStop=/usr/local/localhost /bin/catalina.sh stop
ExecReload=/bin/kill -HUP \$MAINPID
 
[Install]
WantedBy=multi-user.target
 
//设置服务开机自启
[root@localhost  ~]# systemctl daemon-reload 
[root@localhost  ~]# systemctl enable --now localhost .service 
[root@localhost  ~]# ss -anlt
State  Recv-Q Send-Q       Local Address:Port   Peer Address:Port Process 
LISTEN 0      128                0.0.0.0:22          0.0.0.0:*            
LISTEN 0      1       [::ffff:127.0.0.1]:8005              *:*            
LISTEN 0      100                      *:8080              *:*            
LISTEN 0      128                   [::]:22             [::]:*  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值