当时第一次对着敲对指令理解不完全,总体感觉脑子很乱,所以这里整理一下
首先打开虚拟机点击如图所示按钮,显示控制台视图
点开网络适配器
如果是学校的电脑改为桥接模式
学校电脑
点击有线 已连接
点击有线设置
如图点击
IPv4 Method改为手动
Addresses
设置地址10.22.126.130 这只是个例子,按学校的来
子网掩码24或255.255.255.0 这只是个例子,按学校的来
网关10.22.126.254 这只是个例子,按学校的来
DNS
8.8.8.8
应用后如果还是连不上网
尝试关闭,再打开
如果是自己的电脑无需以上操作操作
然后在界面中输入Pwd@123.com登入
右键登入后的界面选择打开终端
先尝试输入此指令,看看有没有连上网
[usera@centos79 ~]$ ping www.baidu.com
显示如图,则ping通,表示连上网
Ctrl+c停止运行
保证连上网以后开始以下操作
ftp的搭建操作
[usera@centos79 yum.repos.d]$ sudo -i
[sudo] usera 的密码: // 输入的密码不显示 Pwd@123.com//粘贴时不能ctrl+v,要鼠标右键粘贴
[root@centos79 ~] mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup//备份
[root@centos79yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo//使用阿里云镜像站
[root@centos79 ~]# yum install -y vsftpd
如果不行 rm -f /var/run/yum.pid
[root@centos79 ~]# yum install -y vsftpd//如果没问题则不需要重新下一次
[root@centos79 ~]# systemctl start vsftpd
[root@centos79 ~]# systemctl status vsftpd//检查//如果有active(running)绿色则启动成功
[root@centos79 ~]# firewall-config // 打开防火墙配置项
打钩,勾选ftp
[root@centos79 ~]# cd /var/ftp//cd进入文件位置
[root@centos79 ftp]# ls
pub
[root@centos79 ftp]# mkdir new //mkdir创建一个新的文件
[root@centos79 ftp]# ls
new pub
到此为止,windows可以访问linux中的ftp服务器了。
[root@centos79 ftp]# cd new
[root@centos79 new]# ls
[root@centos79 new]# echo 123 > a.txt
[root@centos79 new]# cat a.txt
123
[root@centos79 new]#
在window中可以下载文件a.txt了
但是不能上传文件。
[root@centos79new]# cd /etc/vsftpd
[root@centos79vsftpd]# vim vsftpd.conf :set nu 29行 删除一个字符# anon_upload_enable=YES
i插入 shift+: 使用set nu shift+: 29 找到行 yy复制 p粘贴
先按键盘左上角的退出(Esc)键,然后在vim中输入:wq保存退出,如果想不保存退出,需要键入:q!
[root@centos79vsftpd]# systemctl restart vsftpd
[root@centos79vsftpd]# cd /var/ftp
[root@centos79ftp]# ll
[root@centos79ftp]# chmod o+w new //改成可读可写,此时ls检查new文件会有绿色底色
[root@centos79ftp]# ll
[root@centos79ftp]# setenforce 0
[root@centos79 new]# cd /etc/vsftpd
[root@centos79 vsftpd]# ls
[root@centos79 vsftpd]# vim vsftpd.conf
anon_mkdir_write_enable=YES 33
anon_other_write_enable=YES // 自己添加 34
[root@centos79 vsftpd]# systemctl restart vsftpd
anon_umask=022 添加一句,放在哪一行都行
[root@centos79 vsftpd]# systemctl restart vsftpd此电脑中ftp://10.22.126.139进行验证,输入自己虚拟机的ip,new文件里可实现删除复制,移出移入
例如:ftp://10.22.126.139
web的搭建操作
1.1. 安装httpd
[root@centos79 vsftpd]# yum install -y httpd
[root@centos79 vsftpd]# systemctl start httpd
[root@centos79 vsftpd]# systemctl status httpd
[root@centos79 ~]# firewall-config // http打个勾
此时应该可以从windows访问Linux中的web服务器
[root@centos79 ~]# cd /var/www/html
[root@centos79 html]# echo hello! Apache > index.html
//网站上输入ip地址查看,10.22.126.139,输入自己虚拟机的ip
再次从windows访问Linux中的web服务器,看下主页是否发生变化。
1.2. 改配置文件,实现虚拟主机
[root@centos79 ~]# cd /etc/httpd/conf
[root@centos79 conf]# ls
httpd.conf magic
[root@centos79 conf]# cat httpd.conf
[root@centos79 conf]# vim /etc/httpd/conf/httpd.conf // 改配置文件
(:set nu :42)
#Listen 12.34.56.78:80
Listen 80
Listen 8055 //新加一行 42
<VirtualHost 自己虚拟机的ip或者直接*代替:8055> //新加3行 这里用8055端口号
DocumentRoot /var/www/html2
</VirtualHost>
#
# DocumentRoot: The directory out of whichyou will serve your
# documents. By default, all requests aretaken from this directory, but
# symbolic links and aliases may be used topoint to other locations.
#
DocumentRoot /var/www/html
(:wq)//保存退出
[root@centos79 conf]# systemctl restart httpd
[root@centos79 conf]#
[root@centos79 conf]# firewall-config //处理8055端口,新加一个端口号,tcp协议
[root@centos79 conf]# cd /var/www
[root@centos79 www]# mkdir html2
[root@centos79 www]# ls
cgi-bin html html2
[root@centos79 www]# cd html2
[root@centos79 html2]# echo This ismy second website > index.html
[root@centos79 html2]# ls
index.html
[root@centos79 html2]#
2. 修改ftp的配置文件,将默认路径更改到http服务的默认目录
[root@centos79 html2]# cd /etc/vsftpd
[root@centos79 vsftpd]# vim vsftpd.conf
添加一行(放哪里都可以,可以放在25行): anon_root=/var/www
[root@centos79 vsftpd]# systemctl restart vsftpd
[root@centos79vsftpd]# cd /var/www
[root@centos79 www]#ll
总用量 0
drwxr-xr-x. 2 rootroot 6 3月 24 22:58 cgi-bin
drwxr-xr-x. 2 rootroot 24 5月 25 16:55 html
drwxr-xr-x. 2 rootroot 24 5月 25 17:01 html2
[root@centos79 www]#chmod o+w ./html2
[root@centos79 www]#
浏览器中输入10.22.126.139:8055//使用自己虚拟机的ip加端口号
查看第二个网页
第一个网页输入例如10.22.126.139
第二个网页输入例如10.22.126.139:8055