linux网络服务

来源:互联网 发布:淘宝权 编辑:程序博客网 时间:2024/04/29 09:59

==================================

apache

涉及的软件包
 httpd
 httpd-devel 
涉及的协议
 http 
 端口 80
服务的工作路径
 /etc/httpd/
配置文件
 /etc/httpd/conf/httpd.conf


Listen 80   <---- 服务启动之后监听哪个端口
 
Include conf.d/*.conf <---包含子配置文件

User apache  <---服务运行的时候的进程身份
Group apache

 
如果启动httpd的时候报错
[root@squid /]# service httpd restart
停止 httpd:                                               [确定]
启动 httpd:httpd: apr_sockaddr_info_get() failed for upl
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [确定]

解决办法:

 1、打开参数
ServerName 10.1.1.21:80

 2、定义一个FQDN主机名,并且修改/etc/hosts
[root@squid /]# hostname squid.upl.com
[root@squid /]# vim /etc/hosts 
10.1.1.21       squid.upl.com


DocumentRoot "/var/www/html"  <---指定默认网站的根目录,存放网页资源的最顶端目录

 

<Directory "/var/www/html">  《---容器标签
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>


第一个例子:

 service httpd restart

 firefox http://10.1.1.21

 发现是一个测试页面

 取消测试页面

 echo "This is home page" > /var/www/html/index.html

 刷新网页就能看到自己的页面

 为甚么?

 默认首页 《---当直接访问某个目录的时候,并没有待具体的文件名的时候,默认读取该目录下的那个文件

 如何指定默认首页?

DirectoryIndex index.html index.html.var  -----------》指定默认首页


实验:
 1、mkdir /var/www/html/bbs

 2、访问 http://ip/bbs  -》 /var/www/html/bbs

你会发现结果是一种目录结构的显示。什么参数导致? ----Indexes
参数 Indexes 当访问某个目录的时候,没有指定目录下的具体文件的时候,而且该目录下没有默认首页的时候,就是以目录结构形式显示。

<Directory "/var/www/html">  《---容器标签
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

 想取消这种目录结构的显示,怎么办?
 1、在每个目录下都添加默认首页

 2、去掉Indexes参数

    Options -Indexes FollowSymLinks


例子2:访问控制


<Directory "/var/www/html">  《---容器标签
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny  《---访问控制参数
    Allow from all   《---访问控制参数
</Directory>


 Order allow,deny  <---先允许,再拒绝,让允许和拒绝发生冲突的时候,deny说了算
 Allow from all 

 


    Order allow,deny 
    Allow from all   <---允许所有人访问
    Deny from 10.1.1.87  <---    禁止10.1.1.87访问


    Order deny,allow   <---先禁止后允许,发生冲突,allow说了算
    Deny from all   <---禁止所有人访问
    Allow from 10.1.1.68  192.168.1.0/255.255.255.0 <---    允许10.1.1.87和 192.168.1.0网段访问


实现 只允许10.1.1.0网段访问我的web,但是10.1.1.68不能访问

 Order allow,deny
 Allow from 10.1.1.0/255.255.255.0
 Deny from 10.1.1.68
  <---当没有出现在allow指定的范围内的IP,这些IP就不能访问

实现 拒绝10.1.1.0网段访问,但10.1.1.68可以访问,其他IP都可以访问

 Order deny,allow
 Deny from 10.1.1.0/255.255.255.0
 Allow from 10.1.1.68

 

=========================================

ftp 服务器的搭建

涉及的软件
 vsftpd

涉及协议
 ftp
 端口 : 21(控制命令的传输端口)   20 (主动模式下普通数据传输端口)

两种工作模式
 主动工作模式:利用21端口进行控制命令传输,服务器主动利用20端口发起传输普通数据的连接。
 被动工作模式:利用21端口进行控制命令传输,客户端主动告诉服务器要打开某个大于1024的随机端口,然后客户端主动的连接服务器该端口,然后开始数据传输。


配置文件
 /etc/vsftpd/vsftpd.conf


例子1:实现匿名登录

安装完软件包,重启就可以实现

[root@squid vsftpd]# ftp 10.1.1.21
Connected to 10.1.1.21.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (10.1.1.21:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (10,1,1,21,72,179)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 May 13  2009 pub
226 Directory send OK.
ftp> pwd
257 "/"   《---登录之后的“/”到底在哪里?
 就在匿名帐号ftp的家目录 /var/ftp

例子2:更改匿名登录的资源路径

第一种办法:
 修改匿名帐号的家目录

第二种办法:
 anon_root=/ftp 

例子3:让匿名帐号可以上传文件
默认是不允许匿名上传文件,只允许下载文件

1、修改配置文件,让匿名可以有写的权限
anon_upload_enable=YES

# service vsftpd restart
2、修改系统资源的权限,让匿名帐号ftp可以有写步骤

 不可以直接对匿名登录的根目录直接赋予777权限(可写权限)
chmod 777 /var/ftp/pub

ftp> put /etc/exports /pub/exports


例子4:匿名下去自己上传文件会失败,原因?怎么解决?

原因:
默认anon_world_readable_only是YES,只允许匿名帐号下载所有人都可以读的文件

解决:
 anon_world_readable_only=NO

例子5:实现普通帐号登录ftp
默认就支持这个功能,并且登录之后所在的路径就是在用户的家目录,登录之后默认就可以上传文件到他的家目录。

ftp> pwd
257 "/home/tom"
ftp> cd /etc/
250 Directory successfully changed.
ftp> pwd
257 "/etc"
ftp>  get /etc/passwd  /tmp/test/mypw
local: /tmp/test/mypw remote: /etc/passwd
227 Entering Passive Mode (10,1,1,21,146,90)
150 Opening BINARY mode data connection for /etc/passwd (1696 bytes).
226 File send OK.
1696 bytes received in 2.3e-05 seconds (7.2e+04 Kbytes/s)

默认情况下,普通帐号登录之后,并没有锁定在资源路径,可以访问该帐号在系统上可以访问访问的所有路径

例子6:锁定普通帐号登录之后的资源路径,让他只能访问他家目录
chroot_local_user=YES