实验6网络服务器的基本配置.docx

上传人:b****7 文档编号:10480269 上传时间:2023-02-13 格式:DOCX 页数:19 大小:381.29KB
下载 相关 举报
实验6网络服务器的基本配置.docx_第1页
第1页 / 共19页
实验6网络服务器的基本配置.docx_第2页
第2页 / 共19页
实验6网络服务器的基本配置.docx_第3页
第3页 / 共19页
实验6网络服务器的基本配置.docx_第4页
第4页 / 共19页
实验6网络服务器的基本配置.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

实验6网络服务器的基本配置.docx

《实验6网络服务器的基本配置.docx》由会员分享,可在线阅读,更多相关《实验6网络服务器的基本配置.docx(19页珍藏版)》请在冰豆网上搜索。

实验6网络服务器的基本配置.docx

实验6网络服务器的基本配置

实验六网络服务器的基本配置

一.  实验目的:

1.掌握service、chkconfig命令的使用方法;

2.掌握linux防火墙的开启和关闭的方法;

3.掌握selinux的开启和关闭的方法;

4.掌握Apache服务器的基本配置和搭建方法;

二.  实验环境:

Red Hat Enterprise Linux 6以上

三.   实验内容:

1.service、chkconfig命令的使用方法;

2.linux防火墙的开启和关闭的方法;

3.selinux的开启和关闭的方法;

4.Apache服务器的基本配置和搭建方法;

四、实验练习:

1、service、chkconfig命令的使用方法

1.service命令

格式:

service服务名start|stop|restart|status

功能:

启用、停止、重启指定的服务,或查看指定服务的状态。

service命令本身是一个shell脚本,它在/etc/init.d/目录下查找指定的服务脚本,然后调用服务脚本完成任务。

如果你的执行命令为servicemysqldstop,那么就相当于执行了/etc/init.d/mysqldstop

这个命令不是在所有的linux发行版本中都有。

[root@localhost~]#servicehttpdstatus

httpd已停

[root@localhost~]#servicehttpdstart

正在启动httpd:

httpd:

Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,usinglocalhost.localdomainforServerName

[确定]

[root@localhost~]#servicehttpdstatus

httpd(pid2660)正在运行...

[root@localhost~]#servicehttpdrestart

停止httpd:

[确定]

正在启动httpd:

httpd:

Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,usinglocalhost.localdomainforServerName

[确定]

2.chkconfig命令

格式:

chkconfig[选项][服务名][on|off]

功能:

设置服务开机自动启用,用于查看、设置服务的运行级别。

注:

chkconfig命令必须重启后才会生效。

[root@localhost~]#cat/etc/inittab

#inittabisonlyusedbyupstartforthedefaultrunlevel.

#

……

#Defaultrunlevel.Therunlevelsusedare:

#0-halt(DoNOTsetinitdefaulttothis)

#1-Singleusermode

#2-Multiuser,withoutNFS(Thesameas3,ifyoudonothavenetworking)

#3-Fullmultiusermode

#4-unused

#5-X11

#6-reboot(DoNOTsetinitdefaulttothis)

#

id:

5:

initdefault:

#查看开机是否自动启用httpd服务:

[root@localhost~]#chkconfig--listhttpd

httpd0:

关闭1:

关闭2:

关闭3:

关闭4:

关闭5:

关闭6:

关闭

#设置开机自动启用httpd服务:

[root@localhost~]#chkconfighttpdon

[root@localhost~]#chkconfig--listhttpd

httpd0:

关闭1:

关闭2:

启用3:

启用4:

启用5:

启用6:

关闭

#设置运行级别为2时开机不自动启用httpd服务:

[root@localhost~]#chkconfig--level2httpdoff

[root@localhost~]#chkconfig--listhttpd

httpd0:

关闭1:

关闭2:

关闭3:

启用4:

启用5:

启用6:

关闭

3.linux防火墙的开启与关闭

[root@localhost~]#serviceiptablesstatus

表格:

filter

ChainINPUT(policyACCEPT)

numtargetprotoptsourcedestination

1ACCEPTall--0.0.0.0/00.0.0.0/0stateRELATED,ESTABLISHED

2ACCEPTicmp--0.0.0.0/00.0.0.0/0

3ACCEPTall--0.0.0.0/00.0.0.0/0

4ACCEPTtcp--0.0.0.0/00.0.0.0/0stateNEWtcpdpt:

22

5REJECTall--0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibited

ChainFORWARD(policyACCEPT)

numtargetprotoptsourcedestination

1REJECTall--0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibited

ChainOUTPUT(policyACCEPT)

numtargetprotoptsourcedestination

[root@localhost~]#/etc/init.d/iptablesstatus

……

[root@localhost~]#serviceip6tablesstatus

表格:

filter

ChainINPUT(policyACCEPT)

numtargetprotoptsourcedestination

1ACCEPTall:

:

/0:

:

/0stateRELATED,ESTABLISHED

2ACCEPTicmpv6:

:

/0:

:

/0

3ACCEPTall:

:

/0:

:

/0

4ACCEPTtcp:

:

/0:

:

/0stateNEWtcpdpt:

22

5REJECTall:

:

/0:

:

/0reject-withicmp6-adm-prohibited

ChainFORWARD(policyACCEPT)

numtargetprotoptsourcedestination

1REJECTall:

:

/0:

:

/0reject-withicmp6-adm-prohibited

ChainOUTPUT(policyACCEPT)

numtargetprotoptsourcedestination

[root@localhost~]#chkconfig--listiptables

iptables0:

关闭1:

关闭2:

启用3:

启用4:

启用5:

启用6:

关闭

[root@localhost~]#serviceiptablesstop

iptables:

将链设置为政策ACCEPT:

filter[确定]

iptables:

清除防火墙规则:

[确定]

iptables:

正在卸载模块:

[确定]

[root@localhost~]#serviceiptablesstatus

iptables:

未运行防火墙。

[root@localhost~]#serviceiptablesstart

iptables:

应用防火墙规则:

[确定]

[root@localhost~]#serviceiptablesstatus

……

[root@localhost~]#chkconfig--listiptables

iptables0:

关闭1:

关闭2:

启用3:

启用4:

启用5:

启用6:

关闭

[root@localhost~]#chkconfig--level2345iptablesoff

[root@localhost~]#chkconfig--listiptables

iptables0:

关闭1:

关闭2:

关闭3:

关闭4:

关闭5:

关闭6:

关闭

[root@localhost~]#chkconfig--listip6tables

ip6tables0:

关闭1:

关闭2:

启用3:

启用4:

启用5:

启用6:

关闭

[root@localhost~]#chkconfig--level2345ip6tablesoff

[root@localhost~]#chkconfig--listip6tables

ip6tables0:

关闭1:

关闭2:

关闭3:

关闭4:

关闭5:

关闭6:

关闭

图形界面下linux防火墙开启和关闭的方法

[root@localhost~]#system-config-firewall

4.selinux的开启和关闭

安全增强型Linux(Security-EnhancedLinux)简称SELinux,它是一个Linux内核模块,也是Linux的一个安全子系统。

SELinux有三种工作模式,分别是:

enforcing:

强制模式。

违反SELinux规则的行为将被阻止并记录到日志中。

permissive:

宽容模式。

违反SELinux规则的行为只会记录到日志中。

一般为调试用。

disabled:

关闭SELinux。

SELinux工作模式可以在/etc/selinux/config中设定。

如果想从disabled切换到enforcing或者permissive的话,需要重启系统。

反过来也一样。

enforcing和permissive模式可以通过setenforce1|0命令快速切换。

1表示启用(enforcing),0表示告警,不启用(permissive)

[root@localhost~]#vim/etc/selinux/config

#ThisfilecontrolsthestateofSELinuxonthesystem.

#SELINUX=cantakeoneofthesethreevalues:

#enforcing-SELinuxsecuritypolicyisenforced.

#permissive-SELinuxprintswarningsinsteadofenforcing.

#disabled-NoSELinuxpolicyisloaded.

SELINUX=enforcing

#SELINUXTYPE=cantakeoneofthesetwovalues:

#targeted-Targetedprocessesareprotected,

#mls-MultiLevelSecurityprotection.

SELINUXTYPE=targeted

[root@localhost~]#setenforce0

[root@localhost~]#getenforce

Permissive

[root@localhost~]#setenforce1

[root@localhost~]#getenforce

Enforcing

5.Apache(Web)服务器配置

1)安装并启动Apache

检测与安装Apache:

rpm–qa|grephttpd

若未检测到软件包,则需要使用yum进行安装:

yum–yinstallhttpd

默认情况下是安装的。

[root@localhost~]#rpm-qa|grephttpd

httpd-tools-2.2.15-29.el6_4.i686

httpd-2.2.15-29.el6_4.i686

[root@localhost~]#servicehttpdstatus

httpd已停

[root@localhost~]#servicehttpdstart

正在启动httpd:

httpd:

Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,usinglocalhost.localdomainforServerName

[确定]

[root@localhost~]#servicehttpdstatus

httpd(pid4304)正在运行...

[root@localhost~]#cat/etc/httpd/conf/httpd.conf|less

……

2)打开浏览器

在虚拟机或者宿主机均可(将虚拟机的防火墙关闭),在浏览器的地址栏输入:

127.0.0.1(或者localhost,192.168.124.11),可以看到Apache(Web)服务器中默认站点的默认页面。

3)创建自己的页面

进入/var/www/html文件夹,用vim创建html文件

[root@localhosthttpd]#vim/var/www/html/index.html

thisisatesthtmlpage!

otherpage

[root@localhosthttpd]#vim/var/www/html/other.html

thisistheotherhtmlpage!

4)移动other.html到pic目录

[root@localhosthttpd]#cd/var/www/html

[root@localhosthtml]#ls

index.htmlother.html

[root@localhosthtml]#mkdirpic

[root@localhosthtml]#mvother.htmlpic

[root@localhosthtml]#ls

index.htmlpic

[root@localhosthtml]#cdpic

[root@localhostpic]#ls

other.html

[root@localhostpic]#cd..

[root@localhosthtml]#vimindex.html

thisisatesthtmlpage!

otherpage

可以查看网页源代码,查看other.html的路径已改变

6.NFS服务器的配置

1)NFS概述

NFS网络文件系统NetworkFileSystem,是文件共享的一种网络协议,NFS服务有服务器和客户机两种角色。

NFS客户端通过挂载NFS文件系统的方式访问NFS服务器中输出的共享目录,此服务只针对于Linux操作系统。

RPC主程序:

rpcbind

NFS被视为一个RPC(RomoteProcedureCall,远程过程调用)服务,在CentOS5.x以前这个软件称为portmap,在CentOS6.x之后才称为rpcbind的!

NFS主程序:

nfs-utils

提供rpc.nfsd及rpc.mountd两个NFSdaemons,相关documents,说明文件、执行文件等。

配置文件:

/etc/exports

2)查看或安装nfs相关包

[root@localhost~]#rpm-qa|grepnfs

nfs-utils-lib-1.1.5-6.el6.i686

nfs-utils-1.2.3-39.el6.i686

nfs4-acl-tools-0.3.3-6.el6.i686

[root@localhost~]#rpm-qa|greprpc

libtirpc-0.2.1-6.el6_4.i686

xmlrpc-c-client-1.16.24-1210.1840.el6.i686

xmlrpc-c-1.16.24-1210.1840.el6.i686

rpcbind-0.2.0-11.el6.i686

#未安装时使用yum进行安装

[root@localhost~]#yuminstall-ynfs-utils

3)在NFS服务器端上创建共享目录/data/nfsdir并设置权限

[root@localhost~]#mkdir-p/data/nfsdir

[root@localhost~]#ll/data

总用量4

drwxr-xr-x.2rootroot40966月509:

06nfsdir

[root@localhost~]#chmod666/data/nfsdir/

[root@localhost~]#ll/data/

总用量4

drw-rw-rw-.2rootroot40966月509:

06nfsdir

4)编辑配置文件/etc/exports

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

/data/nfsdir*(rw,sync,no_root_squash,no_all_squash)

配置文件/etc/exports各字段说明

共享目录被允许的客户端IP(*表示任意IP都可以)

IP后括号里的设置表示对该共享文件的权限

ro只读访问

rw读写访问

sync所有数据在请求时写入共享

all_squash共享文件的UID和GID映射匿名用户anonymous,适合公用目录。

no_all_squash保留共享文件的UID和GID(默认)

root_squashroot用户的所有请求映射成如anonymous用户一样的权限(默认)

no_root_squashroot用户具有根目录的完全管理访问权限

例如:

/data/lys192.168.2.0/24(rw,no_root_squash,no_all_squash,sync)

5)启动nfs服务器

[root@masterhtml]#servicerpcbindstatus

rpcbind(pid1891)正在运行...

[root@masterhtml]#servicenfsstatus

rpc.svcgssd已停

rpc.mountd已停

nfsd已停

rpc.rquotad已停

(先启动rpc服务,再启动nfs服务)

[root@localhost~]#servicerpcbindrestart

停止rpcbind:

[确定]

正在启动rpcbind:

[确定]

[root@localhost~]#servicenfsstart

启动NFS服务:

[确定]

关掉NFS配额:

[确定]

启动NFSmountd:

[确定]

启动NFS守护进程:

[确定]

正在启动RPCidmapd:

[确定]

6)客户端挂载

[root@localhost~]#mount

……

sunrpcon/var/lib/nfs/rpc_pipefstyperpc_pipefs(rw)

nfsdon/proc/fs/nfsdtypenfsd(rw)

[root@localhost~]#ifconfig

eth1Linkencap:

EthernetHWaddr00:

0C:

29:

E2:

DA:

6B

inetaddr:

192.168.124.11Bcast:

192.168.124.255Mask:

255.255.255.0

……

[root@localhost~]#mount-tnfs192.168.124.11:

/data/nfsdir/mnt

[root@localhost~]#mount

……

192.168.124.11:

/data/nfsdiron/mnttypenfs(rw,vers=4,addr=192.168.124.11,clientaddr=192.168.124.11)

[root@localhosthtml]#df-h

FilesystemSizeUsedAvailUse%Mountedon

/dev/sda324G3.1G20G14%/

tmpfs948M228K947M1%/dev/shm

/dev/sda14.0G427M3.4G12%/home

192.168.124.11:

/data/nfsdir24G3.1G20G14%/mnt

7)服务器端在/data/nfsdir创建共享文件

[root@localhost~]#cd/data/nfsdir/

[root@localhostnfsdir]#touchtestnfs

[root@localhostnfsdir]#ls

testnfs

[root@localhostnfsdir]#vimtestnfs

thisisatestnfsfile

8)在客户端的挂载目录查看共享文件

[root@localhostnfsdir]#cd/mnt/

[root@localhostmnt]#ls

testnfs

[root@localhostmnt]#cattestnfs

thisisatestnfsfile

7.FTP服务器的配置

1)vsftp服务概述

FTP服务器(FileTransferProtocolServer)是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务。

FTP是FileTransferProtocol(文件传输协议),是专门用来传输文件的协议。

vsftpd(verysecureFTPdaemon)是一个开源的、免费的FTP服务软件。

vsftpd同时支持匿名用户、本地用户和虚拟用户三类用户账号,使用虚拟用户账号可以提供集中管理的FTP根目

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 化学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1