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

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

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

BOOTPROTO="dhcp",ONBOOT=yes

一、搭建web服务器

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

[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

扫描二维码关注公众号,回复: 7279195 查看本文章

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

[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  安装后开启服务

[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.进行本地挂载,使得访问挂载点时就可访问到挂载文件

    

[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
[email protected]'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

猜你喜欢

转载自www.cnblogs.com/zhanglei97/p/11519385.html