redhat httpd服务安装、访问浏览器及自定义访问页面

该文描述了在CentOS系统中创建本地YUM仓库,安装httpd服务,修改配置文件监听所有IP,然后重启服务并检查IP地址。由于防火墙限制,无法访问Web服务,通过firewall-cmd命令添加http服务到防火墙规则,最终实现了httpd服务的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

1.查看本地仓库,如果没有配置,就在这目录创建一个

2.挂载

 3.下载httpd服务

 4.修改httpd配置文件

5.重启httpd服务

 6.查看当前可用IP地址

 7.随便用一个IP 看是否有东西

 8.无法访问,原因是我们防火墙没有放行httpd服务


1.查看本地仓库,如果没有配置,就在这目录创建一个

cd到 /etc/yum.repos.d

#创建vim  rpm.repo

[baseos]
name=baseos
baseurl=/mnt/BaseOS
gpgcheck=0
[appstream]
name=appstream
baseurl=/mnt/AppStream
gpgcheck=0

#查看

[root@ctrol yum.repos.d]# cat rpm.repo
[baseos]
name=baseos
baseurl=/mnt/BaseOS
gpgcheck=0
[appstream]
name=appstream
baseurl=/mnt/AppStream
gpgcheck=0

2.挂载

 [root@ctrol yum.repos.d]# mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 already mounted on /mnt.

 3.下载httpd服务

yum  install  httpd  -y

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 1 day, 11:24:41 ago on Sun 19 Mar 2023 09:43:01 AM CST.
Dependencies resolved.
======================================================================================================
 Package                Arch       Version                                        Repository     Size
======================================================================================================
Installing:
 httpd                  x86_64     2.4.37-41.module+el8.5.0+11772+c8e0c271        appstream     1.4 M
Installing dependencies:
 apr                    x86_64     1.6.3-12.el8                                   appstream     130 k
 apr-util               x86_64     1.6.1-6.el8                                    appstream     105 k
 httpd-filesystem       noarch     2.4.37-41.module+el8.5.0+11772+c8e0c271        appstream      39 k
 httpd-tools            x86_64     2.4.37-41.module+el8.5.0+11772+c8e0c271        appstream     106 k
 mod_http2              x86_64     1.15.7-3.module+el8.4.0+8625+d397f3da          appstream     154 k
 redhat-logos-httpd     noarch     84.5-1.el8                                     baseos         29 k
Installing weak dependencies:
 apr-util-bdb           x86_64     1.6.1-6.el8                                    appstream      25 k
 apr-util-openssl       x86_64     1.6.1-6.el8                                    appstream      27 k
Enabling module streams:
 httpd                             2.4

Transaction Summary
======================================================================================================
Install  9 Packages

Total size: 2.0 M
Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                              1/1
  Installing       : apr-1.6.3-12.el8.x86_64                                                      1/9
  Running scriptlet: apr-1.6.3-12.el8.x86_64                                                      1/9
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                                              2/9
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                                          3/9
  Installing       : apr-util-1.6.1-6.el8.x86_64                                                  4/9
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                                                  4/9
  Installing       : httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64                   5/9
  Running scriptlet: httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch              6/9
  Installing       : httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch              6/9
  Installing       : redhat-logos-httpd-84.5-1.el8.noarch                                         7/9
  Installing       : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                       8/9
  Installing       : httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64                         9/9
  Running scriptlet: httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64                         9/9
  Verifying        : redhat-logos-httpd-84.5-1.el8.noarch                                         1/9
  Verifying        : apr-1.6.3-12.el8.x86_64                                                      2/9
  Verifying        : apr-util-1.6.1-6.el8.x86_64                                                  3/9
  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                                              4/9
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                                          5/9
  Verifying        : httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64                         6/9
  Verifying        : httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch              7/9
  Verifying        : httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64                   8/9
  Verifying        : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                       9/9
Installed products updated.

Installed:
  apr-1.6.3-12.el8.x86_64
  apr-util-1.6.1-6.el8.x86_64
  apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64
  httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
  httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch
  httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
  mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64
  redhat-logos-httpd-84.5-1.el8.noarch

Complete!

 4.修改httpd配置文件

 [root@ctrol yum.repos.d]# vim /etc/httpd/conf/httpd.conf

#不会设置行号,可以输入  set  number

#在99行添加如下:ServerName 0.0.0.0:80

5.重启httpd服务

[root@ctrol ~]# systemctl restart httpd

stop停止

start  开启

status  查看运行状态

 查看服务状态

[root@ctrol ~]# systemctl  status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-03-20 22:21:33 CST; 43s ago
     Docs: man:httpd.service(8)
 Main PID: 3959 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 49304)
   Memory: 43.4M
   CGroup: /system.slice/httpd.service
           ├─3959 /usr/sbin/httpd -DFOREGROUND
           ├─3960 /usr/sbin/httpd -DFOREGROUND
           ├─3961 /usr/sbin/httpd -DFOREGROUND
           ├─3962 /usr/sbin/httpd -DFOREGROUND
           └─3963 /usr/sbin/httpd -DFOREGROUND

Mar 20 22:21:32 ctrol systemd[1]: Starting The Apache HTTP Server...
Mar 20 22:21:33 ctrol systemd[1]: Started The Apache HTTP Server.
Mar 20 22:21:33 ctrol httpd[3959]: Server configured, listening on: port 80

 6.查看当前可用IP地址

[root@ctrol ~]# ip ad
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:48:6a:ec brd ff:ff:ff:ff:ff:ff
    inet 192.168.197.142/24 brd 192.168.197.255 scope global dynamic noprefixroute ens160
       valid_lft 1695sec preferred_lft 1695sec
    inet6 fe80::20c:29ff:fe48:6aec/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:82:f7:ab brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:82:f7:ab brd ff:ff:ff:ff:ff:ff

 7.随便用一个IP 看是否有东西

# 可以用回环地址127.0.0.1或者你网卡上的

[root@ctrol ~]# curl  192.168.197.142

       <h2>If you are the website administrator:</h2>
        <p>You may now add content to the webroot directory. Note that until you do so, people visiting your website will see this page, and not your content.</p>
        <p>For systems using the Apache HTTP Server: You may now add content to the directory <code>/var/www/html/</code>. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file <code>/etc/httpd/conf.d/welcome.conf</code>.</p>
        <p>For systems using NGINX: You should now put your content in a location of your choice and edit the <code>root</code> configuration directive in the <strong>nginx</strong> configuration file <code>/etc/nginx/nginx.conf</code>.</p>
        <p><a href="https://www.centos.org/"><img src="/icons/poweredby.png" alt="[ Powered by CentOS ]"></a> <img src="poweredby.png" alt="[ Powered by CentOS ]"></p>
      </div>
    </div>
    <hr>
    <div class="row">
      <div class="col">
        <h2 class="alert-heading">Important note!</h2>
        <p>The CentOS Project has nothing to do with this website or its content, it just provides the software that makes the website run.</p>
        <p>If you have issues with the content of this site, contact the owner of the domain, not the CentOS project. Unless you intended to visit CentOS.org, the CentOS Project does not have anything to do with this website, the content or the lack of it.</p>
        <p>For example, if this website is www.example.com, you would find the owner of the example.com domain at the following WHOIS server: <a href="http://www.internic.net/whois.html">http://www.internic.net/whois.html</a></p>
      </div>
    </div>
  </main>
  <footer class="container">
    <div>&#xA9; 2021 The CentOS Project | <a href="https://www.centos.org/legal/">Legal</a> | <a href="https://www.centos.org/legal/privacy/">Privacy</a></div>
  </footer>
</body>
</html>

这时我们可以打开浏览器看看是否能访问

 8.无法访问,原因是我们防火墙没有放行httpd服务

#可以使用--permanent  放行

                --reload    重新加载

[root@ctrol ~]# firewall-cmd --permanent --add-service=http  
success

[root@ctrol ~]# firewall-cmd --reload
success

看截图:哥们先进去了

 

 9.那我们怎么自定义呢   

#进入如下文件位置

[root@ctrol ~]# cd /var/www/html/

#查看是否有文件 
[root@ctrol html]# ll
total 0

#重定向一个内容到文件
[root@ctrol html]# echo welcome to RHCE > index.html
[root@ctrol html]# ll
total 4
-rw-r--r--. 1 root root 16 Mar 20 22:35 index.html
[root@ctrol html]# cat index.html
welcome to RHCE

 其实你也可以直接vim进去,改变他的内容,

[root@ctrol html]# vim index.html
[root@ctrol html]# cat index.html
welcome to RHCE
i
i

i
i
i
i
i
ii
i
i

i
ii
i
i
i

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
[root@ctrol html]#

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值