web服务,ftp服务以及共享实现

在开始服务前一定要确保可以ping通外网,在虚拟机联网但ping 不通外网下

确认vim /etc/sysconfig/network-scripts/ifcfg-ens33 (nmcli connectoin show查看自己网卡名)下确保这两句正确

BOOTPROTO="dhcp",ONBOOT=yes

一、搭建web服务器

  软件包:httpd  服务名称:httpd 安装后使用命令开启服务 

1
2
3
[root@localhost ~]# cd /var/www/html
[root@localhost html]# ls
index.html

[root@localhost html]# echo huihkj > index.html
[root@localhost html]# systemctl restart httpd
[root@localhost html]# firefox 192.168.142.140

  在默认情况下存放网页的目录为/var/www/html     默认文件名为index.html

当网页默认路径不在/var/www/html下时,要修改相关文件配置

但是文件最好还是放在/var/www下目录下的index.html 下

/etc/httpd/conf/httpd.conf为确定网页文件目录的主配置文件,需要修改里面的DocumentRoot

但主配置文件的修改会带来风险,一般修改调用配置文件:/etc/httpd/conf.d/myweb.conf

只需要点名网页根文件改变了就好:DocumentRoot "/var/www/myweb"

1
2
3
4
5
6
7
8
[root@localhost ~]# mkdir -p /var/www/myweb
[root@localhost ~]# cd /var/www/myweb
[root@localhost myweb]# echo 'I m myweb! ' >  index.html
[root@localhost myweb]# cd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
[root@localhost ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/myweb.conf
[root@localhost ~]# vim /etc/httpd/conf.d/myweb.conf
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

  若想把文件放在根下或其他地方,得在调用配置文件中书写

<Directory "文件路径">

Require all granted;

</Directory>

但是selinux会阻止,这里使用安全上下文

chcon -R --reference= 模板目录路径(默认网页文件存放路径)  新目录路径(修改后的路径点)

虚拟web主机

web主机的区分方式:(为每个虚拟站点添加配置)

    基于域名的虚拟主机

    基于端口的虚拟主机

    基于IP地址的虚拟主机

 

 

二、ftp 服务 

    安装包:vsftpd  服务名称 vsftpd  安装后开启服务

1
2
3
4
5
6
7
8
9
10
[root@localhost html]# systemctl restart vsftpd
[root@localhost html]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@localhost html]# cd /var/ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir haha
[root@localhost ftp]# cd
[root@localhost ~]# systemctl restart vsftpd
[root@localhost ~]# firefox ftp://192.168.142.140

  

 

 

 ftp 默认存放路径为/var/ftp

 

 

三、共享的几种方法

服务端:

    1.nfs共享:服务机为客户机提供共享使用的文件夹

    安装包:nfs-utils  服务名称:nfs-server

    创建供共享的文件夹:/nfsd   默认共享的配置文件:/etc/exports

    [root@localhost ~]# mkdir /nfsd
    [root@localhost ~]# vim /etc/exports

    在配置文件下指明:

    /共享文件路径   /客户机地址(权限)

      /nfsd      *(ro)

启服:

[root@localhost ~]# systemctl restart nfs-server
[root@localhost ~]# systemctl enable nfs-server

客户端:

客户端使用挂载来访问共享文件

    1.首先查找可供共享的文件   showmount -e 服务端IP

    2.进行本地挂载,使得访问挂载点时就可访问到挂载文件

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@zhanglei ~]# exit
登出
Connection to 192.168.142.138 closed.
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# !sys
systemctl enable nfs-server
[root@localhost ~]# systemctl restart nfs-server
[root@localhost ~]# gos
root@192.168.142.138's password:
Last login: Sat Sep 14 14:29:48 2019 from 192.168.142.142
[root@zhanglei ~]# showmount -e 192.168.142.140
Export list for 192.168.142.140:
/nfsd *
[root@zhanglei ~]# mount 192.168.142.140:/nfsd /nfsd1
[root@zhanglei ~]# ls /nfsd1
1.txt
[root@zhanglei ~]#   

这样挂载之后开机会取消,可以设置开机自动挂载,自动挂载的文件在/etc/fstab下

共享文件路径       挂载点目录  类型    参数      备份标记  检测顺序

192.168.142.140:/nfsd   /nfsd1    nfs   default,_netdev    0      0

posted @   辛周  阅读(890)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示