Linux下基于用户的虚拟主机的设计与实现简易web服务器的搭建_课程设计_第1页
Linux下基于用户的虚拟主机的设计与实现简易web服务器的搭建_课程设计_第2页
Linux下基于用户的虚拟主机的设计与实现简易web服务器的搭建_课程设计_第3页
Linux下基于用户的虚拟主机的设计与实现简易web服务器的搭建_课程设计_第4页
Linux下基于用户的虚拟主机的设计与实现简易web服务器的搭建_课程设计_第5页
免费预览已结束,剩余14页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、枣庄学院信息科学与工程学院课程设计任务书题目:Linux下基于用户地虚拟主机地设计与实现简易web效劳器地搭建学号:姓名:专业:计算机网络技术课程:LINUX操作系统指导教师:职称:教师完成时间:2021年11月-2021年12月枣庄学院信息科学与工程学院制:设计目标与要求:1、 为了使每个学生有一个展示自我地平台,学校在web效劳器上开通注册通道,学生可以在网站上注册个人账户,在注册地过程中,可以检测用户名是否已存在.如果存在,那么不能注册.用户注册成功后,系统会自动为此用户创立一个系统用户账户,账户名和密码为用户注册时填写地用户名和密码2、 为了使有限地资源能够充分地利用,学校规定为每个用

2、户分配50M地空间.用户可以使用此用户名和密码通过ssh远程连接进行文件地上传和下载,将个人主页上传到用户自己地web目录,以供互联网用户访问.3、 为了将来系统治理员排错方便,每次建立新用户必须产生一个日志记录4、 所有新用户地web空间必须单独放置在一个专用磁盘空间中即使用Vmware新添加一块磁盘5、 所有新建用户地个人WEB空间每隔一周自动备份,以备不测之需.、实现过程1、配置虚拟机地网络#ifconfigeth028netmaskup#vi/resolv添力:searchlocaldomain,nameserver192.168.92

3、.2#routeadd_net/0gw#pingbaidu可以连接2、安装相关套件11安装apacheroot01oca1hostI#rpm-qa!grepdsystem-config-d--1.e15d-Z,2.3-43.e15.centos如果不显示那么表示没安装进行下边地动作即可安装成功:ErootOlocaDiostyum-yinst&lllittpd.(2)安装php(rootlocaIhostlitrpm-qa!grepphpphp-mysql-5.1.6-Z7.e15plip-common-5.1.6-27,e)5plip

4、-c1i-5,1,6-Z7.e15php-5.1.6-Z7.e15php-ldap-5.1.6-27,c15php-pdo-5.1.6-2?.el5如果不显示那么表示没安装进行下边地动作即可安装成功:rootslocaIhostyum-yinsta11php安装mysqlrootlocaLhostlitrpm-qa»grepmysqlplip-mysql-5+1.6-Z7,e15mysq1-5.8<77-4.e15_5.4mysq1-server-5.0.77-4.e1S_5.4如果不显示那么表示没安装进行下边地动作即可安装成功:ootlocaIhostlityum-yinst

5、a11nysq14、设置磁盘配额与挂载:1、关闭虚拟机,在VMware中添加一块硬盘.点击“VMT“Settings“Add一HardDisk,根据提示向导添加硬盘2、启动虚拟机,在linux系统下使用fdiskT命令查看/dev/sdb是否添加成功,root!?localliostJ#fdis(-iisk/deu/sda:10.7GE,10737418Z40bytes155heads,63sectors/track,1305cy1inders51Z=8225ZB0bytesDeviceBootdev/sdal*deusdaZStart14End131305Blocks104391103779

6、90Id838eSystehiLinuxLinuxLUMJnits-cy1indersof1G665*Diskzdev/sdb:214?MB,2147483648hytes七55heads.63sectors/track>261cylindersJnits=cylindersof16g65*512=82Z5280bytesis*zdeu/sdbdoesn'tcontainavalidpartitiontabie如果成功,那么使用fdisk/dev/sdb命令来为sdb硬盘创立分区.n-p-1-回车-回车-p-wConnm<ind(mforheIp):pDisk/dev/sd

7、b:2147MB,2147483648bytesZ55headst83sectors/track,Z61cylindersnits=cy1indersof16865*51Z-GZZ5ZB8bytesDeuiceBootStart/dev/sdbl1/dev/sdb2201,16zBlocks160646B+489982+SystemExtendedLimixCommand(mforhep:uTheparti11ontablehasbeenaItered?Callingiact1C)tore-readpartitiontabie.SCSIdevicesdb:419430451Z-bytehdur

8、sectors(Z14?MB)sdb:(Jrit七Protectisoffsdb:cacliedataunauailablesdb:assumingdriuecache:writethroughSCSIdevicesdb:419430451Z-bytefidwrsectors(2147MB)sdb:WriteProtectisoffsdb:cachedataunavailablesdb:assumingdrivecache:writethroughSyncinqdisks.3、为/dev/sdb2分区创立文件系统:mkfs.ext3/dev/sdb2LrootGuiuui-J#mkfs.ext

9、3zdev/sdbZmkeZfs1.39(29-May-20a6)Filesystemlabel=OStype:LinuxBlocksize=10Z4(log=0)Frdgmentsize=1024(log=0)122338inodesi489980blocksZ4499blocksC5b00z)reservedforthesuperuserFirstdatablock-1Haximumfilesystemb1ocks-6763315Z68blockgroups8192blockspergroup,8192frag-mentspergroupZ048inodespergroupSuperblo

10、ckbackupsstopedonb1acks:8193,24577.10961*57345,737Z9,Z04801,2Z1185,101489Writinginodetables:doneCreatingJourna1(819Zblocks):doneUritingsuperblocksandfilesystemaccountinginfarmation-doneThisf1lesysteMul11beautomaticallychecJcedevery2Smountsor18日days>whichevercomesfirstUsetune2fs-cor-itooverride4、为

11、了使用/dev/sdb1分区,将其挂载到/home目录下面:mount/dev/sdb2/homerootOc1ient"1.cd/homeErootOc1ienthoimett11total12drwx-'-Zrootroot12288Mov23191145、在开机时自动挂载/dev/sdb2,将其记录假设/etc/fstab中./deu/UoLGroup0B/LogrUol00,ext3defau1ts11LABEL=/boot/bootext3defdu1ts1Ztmpfszdev/shmtMpfsdefau1ts6edeupts/deu/ptsdevptsgiilMS

12、,nKde=62日0esysfszsyssysfsdefauIts0proczprocprocclefauIts0/deu/UoLGroupBB/LogUoieisuapsuapdefau1ts190/dey/sdbZa_1Z/horneext3defauItsusrquota,grpquot6、使用mount-oremount/home重新力口载/home分区.LrootP1ocalliostJ#mount-oremount/home7、使用mount查看分区情况./dev/sdb1on/hometypeext3(rw,usrquota,grpquota)8、重新启动电脑rootslocal

13、host#sync;sync;sync;reboot9、创立磁盘配额quotacheck-avugrootc1lentIttquotacheck-avug10、开启quotarootc1lentquotaon-auurootc1ient1itmkdirusrquotarootc1lentitmkdirrpquota11、设置模版配额用户用于新加用户地配额限制rootuwuJttuseraddtestErootQuwu"J#echo07ZlwyzJ'*!passwd一一stdintest'hangingpasswordforusertest.jassud:allaiLt

14、heiitica.tiomtokensupdated,successfu1ly.root9uiuu*Jttedquota-utest_独苗飘题blockssofthard漩嬷softhard-1加vsdbl100025600512000Q如(5)、个人空间页面地设计和注册页面地设置!首先设置虚拟主机:rootPloca1hostttvizetc/d/confzd+conf做如下几行地设置:翻开虚拟主机VMameUirtuaIHost*:80NameUirtualHost19Z.168.92,128:80创立虚拟主机对应ip以及域名,其中shenqing为域名申请页面wethnicity为一个个

15、人域名UirtualHost192.168.9Z.128:80>DocumeintRoot/home/wethifiicity/pub1ic_htm1ServerHameuuu,wanyancomErrorLcglogs/dummy-host.ex社mple-error_logCustomLoglogs/dummy-host.exainple-access_logcommon/UirtualHost>UirtilflilHost192.168.9Z.1Z8:80>I>ocumentRoot/var/www/html/useraddSeruerNameuiuiu.shen

16、qing.cumErrorLoglogs/dummy-li口3七'error_1ogCustomLoalogs/dumr«y-host.exainple»com-access_logcommom/UlrtualHost>First:设置注册页面创立文件夹rooty1oca1host#mkdir-p/var/www/htin1/useradd进入到该目录先ErootlocaIhost1#cd/uar/uMw/htmlzuseradd编辑注册页面Iro口locaIh口后土useraddlttviindex,php代码如下:<!DOCTYPEhtmlPUBLI

17、C"-/W3C/DTDXHTML1.0Transitional/ZEN""://TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="://1999/xhtml"><head><meta-equiv="Content-Type"content="text/html.charset=utf-8"/><title>UserRegister</title></

18、head><bodystyle="font-size:28px."><formaction="./index.php"method="post"name="info"><tablewidth="640"border="15"align="center"bgcolor="#3399FF"><tr><tdcolspan="2"align="center

19、">NewUser</td></tr><tr><td>Name:</td><td><inputtype="txt"name="user_name"/></td></tr><tr><td>Password:</td><td><inputtype="password"name="user_pwd"/></td></tr&

20、gt;<tr><tdcolspan="2"align="center"><inputname="submit"type="submit"value="Submit"/><inputname="reset"type="reset"value="Reset"/></td></tr></table></form><?php$user=$_PO

21、ST"user_name".$password=$_POST"user_pwd".if($_POST'submit')检验用户名密码是否为空,假设存在空值,弹出警告if(strlen($user)=0|strlen($password)=0)echo("<scripttype='text/javascript'>alert('UserNameorpasswordcannotbenull!').</script>").如果用户名密码不为空,继续执行,判断/etc/p

22、asswd与newUserList文件中是否存在此用户名else执行脚本check.sh,并把用户名传值过去$userCheck="bash./check.sh$user".$result=exec($userCheck).if($result="000")返回值为000,表示用户已经存在,弹出警告用户已存在echo("<scripttype='text/javascript'>alert('UserNameisexist!Pleaseanotherone').</script>"

23、;).else没有返回值,说明没有重复地用户名,可以注册$file=fopen("./newUserList",'a+').翻开newUserList,并把用户名及密码写入中间以“:隔开fwrite($file,$user.":".$password."n").fclose($file).写入成功后,提示用户名与密码echo"Userregistersuccess!Pleaseremeberyourusername:".$user.echo<br/>".echo"an

24、dpassword:".$password.".Youcanuseitin3minutes.".echo<br/>".echo"<ahref='index.php'>Back</a>".?></body></html>编辑限制地shell文件:User_add.sh限制用户地建立rootsloca1hostuseradd1itvlcheck.sh代码如下:#!/bin/bash#filename:check# 获取/etc/passwd文件中地用户名,赋

25、予变量user_existforuser_existin'cut-f1-d:/etc/passwd'do# 将index.php文件中传过来地用户名与系统存在地用户名比照,假设存在同名,打印出000# 并退出比照,假设没有配地那么继续循环user="$1"if"$user"="$user_exist".thenecho"000"exitfidone# 假设index.Php文件中传过来地用户名与系统用户名没有匹配地,那么通过相同地方式与# 当前目录下地newUserList文件中地用户名相匹配for

26、user_exist1in'cut-f1-d:./newUserList'do#echo$user_exist1user="$1"if"$user"="$user_exist1".thenecho"000"exitfidonecheck.sh:检验用户存在与否Lroott?locaIhnstueradd1itviuseraddTsh代码如下:#!/bin/bash#name:user_add.sh#获取/etc/passwd文件中地用户名,赋予变量newuserfornewuserin'cu

27、t-f1-d:/var/www/html/useradd/newUserList'do#通过循环地方式添加用户名,使其属于组netusers,并在其用户目录下创立#文件夹public_html,为用户分配空间,并修改用户目录地权限useradd-gnetusers$newuseredquota-ptest-u$newuser/进行磁盘配额mkdir/home/$newuser/public_htmlquota-uvs$newuser/显示用户地空间配额chmod755/home/$newuserdone#使用chpasswd命令,批量为新添加地用户创立密码chpasswd</va

28、r/www/html/useradd/newUserList#清空newUserList文件>/var/www/html/useradd/newUserList为shell文件添加执行权限:root!?localhostuseradd141chmod755check.shrootO1ocaIhostuseradd14tchmod75suseradd.、设置cronrootloclhostJitui/etc/crontabSHELL-/bin/bash3ATH=/sbini/bini/usr/sbin:/usr/bin1AILT0=rootIUHE=/Xrun'part:£

29、;31*MW#rootrun-partszetc/cron.hourly3Z4圣*rootrun-partszetc/cron.daily“4««0rootrunpartszetc/cron.ueekly4241w»rootrun-partszetc/cron.monthly*弁»*root/uar/www/litml/useradd/user_add+sh(6)、测试注册首先设置测试主机ip与域名地对应rootslocalhostIttuizetc/hoststtDonotremovethefollouiing1inejorvariousprogram

30、sttthatrequirenetworkfunctionalityui11fail.127.0,0,11ocaIhostTlocaIdomainloca1best:1localhot6,locaIdcmain61aca1hcst6M192.16H.9Z.IZOmaster,wethnicityttl9Z.168.32.134cIient.uethnicity192.168.9241Z192.168.9Z4128ljmm.shenqing注册:在浏览器中车入地址:/28/useradd,在用户注册页面输入用户名及密码,假设用户名及密码有一项为空,那么弹出窗口提示输入地信

31、息不全;假设输入root或ethnicity等系统中已存在地用户,会弹出窗口显示用户名不可用;输入系统不存在地用户名wanyan,系统提示用户可以使用,提示3分钟后可用.IIE侬|.*':n«p:/y*wwshenqingccm/indexpnp:相rittp/vMw5heDingcomflndexphp您能让Rrefmt汜住此密的吗Userregistersuccess!J1easeremeberyourusernamenvanyanandpassword:721wyzJtYoucanuseitin3minutes.BaekSecond:ssh地操作(1)、开启sshd效劳

32、(port:22)并且查看CrootlocaIhost14servicesshdstartLrootElocalhostInnetstdt-tulnpigrep:ZZtcpEN0e2S21,hpi口di27.e.e.i:zzea0r0,0.0:*LISTtcpEMQ&Z5Z6/python1Z7.B.8.1:22070.06.B:*LISTtcpEN0e254/sshd:::Z2:::注LIST(2)、用户wanyan登录测试EieEltView地ndcw日目口Q且船舄已帆益白嚓好/IQuidkConnect_|ProfilesSSHSecureShell3.2,9Copyriglit

33、(c)2000-2003(Build283)Shellisancn-commeEcial炉etwion.35HCoomunicationaSecurityCorp-:j/ww.3sh*com/Tillscopyot55HSecureThisversionConnecttoReBDteKostHostHamg:UserName:FortAnthrtticationNotconiLi&eted-pressEnterorSpacet&<80x24药厂.713回区国28-default-SSHSecureShellFileEditViewWindowHel

34、p口昌已患跑)地3粒口号w/IQuickConnect_jProfilesSSHSecureShell3.2.9(Build283)Copyright(c)2000-2003SSHComunicAddProfilej|ProfileNameAddtoProfilesThiscopyofSSHSecureShellisanon-commercialversion.ThisversiondoesnotincludePKIandPKCS#11functionalicy.wanyan61ocalhost-$|Connectedto28|SSM2"aesl28-cbc-

35、"s|80x24|/(3)、实现文件上传(上传至/home/newuser/public_html:个人空间局部)Si28-default-SSHSecureFileTransfer能?疆舞Qk?FileEditViewOperationWindowHelp周|鼬亳为白嗨5优口,3连重Transfer|QueueSourceFileSourceDirectoryDestinationDire.SizeStatusSpeedTime文文文文文方方方方夹夹夹统统统统统提便提建件用件系系系系系快快快快文哀文夹方方文iiUE'R舞徒3文快块HF31718649

36、865T429249,我的文档工我的电脑2网上邻居E回收站InfernetExplorer_|FoxitReader国丽我0VMwar«VTorkstation飞信201.Jc%个工具课程设讨n新建文件夹Km-TC腾讯TM2W9二西单女孩漂端胸,叫3<3.<.>Cqiaiectedto192.168,92,126-/hSSH2-aeslEB-cbchuacnmdS-i2items(0Bytes)直接上传即可这时public_html下有主页index.html翻开为:fOtherLinux2.6.xkernel才MoziHi2汴口蜩辑在)先哲N)历史柠筌回Tft(T

37、)帮助回:/wwwwanyancom/险时间最多,阉Centos£3Support,hellowethnicity!'!三:备份策略1、个人空间地备份、编辑shellpootlocaIhostlitcd/tmpErootPlocaIhosttmpJUvibf14sh#*/bin/bashtar-zcMf-/home/wanyan;tar-zxvf-/tmp_(2)、修改权限rootlocaIhostimpitchmod755bf.sh(3)、实现每十分钟备份一次Lroot(?locaIhost141ui/etc/crontabSHELL二八in/bdshPATH=/sbin:

38、/bin:/usr/sbin:zusrzbinMAILTOirootHOME二,Itrun-parts31«*«root0Z4«*root224*6root4241*«root*/3«»*rootrun-partsrun-partsrun-partsrun-parts/etc/cron.hourlyzetc/cron.daily/etc/cron.weekly/etc/cron.monthlyzvar/uiww/htm1/useradd/useradd.sh*/10*root/tmp/bf.sli_添加多人空间备份只需修改bf.sh即

39、可2、建立新用户产生一个日志记录(在用户目录下生成):每次添加一个用户即在用户地主目录下产生一个名为:newUserList地文件来记录此用户地用户名和密码,只有本用户和治理员可以查看,做到备份地效果(1)、编辑/var/www/html/useradd/newUserListrootuu)uvi/var/www/html/iiiseradd/uiser_add.sh*1!/bin/bashttname:user._add.shfornewuser1n1cut-f1-d:/var/uww/html/useradd/ncwUserL1stdouseraddSeuuseredquota-ptest-u$neuuserquota-uusSnewuser_mkdir/home/$neuuser/pub1ic_htmlcp/var/wwui/html/useradd/neuUserList/home/Snewuser/setquota$newuser51Z0018240000/liomechmod7s5/home/SnewuserechoSoewuserdonechpasswd<Zvar/www/html/useradd/newUserListttpuiconvttrmneuUserList-ftttouctinewUserListttch

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论