启动NFS时,要先启动RPC

 

 

安装:

 

        服务器:nfs-utils

 

                portmap 

 

                安装方法:yum install nfs*

 

                          yum install portmap*

 

                验证:        yum list | grep nfs

 

                        yum list | grep portmap

 

                或:        rpm -qa | grep nfs

 

                        rpm -qa | grep portmap

 

 

        客户端:        portmap

 

        

 

涉及的服务:

 

        nfs

 

        portmap

 

 

NFS服务器配置:

 

        vim /etc/exports

 

        配置文件共两段:

 

                /nfs/           *(ro)

 

                /soft/          *(ro)

 

              共享的目录     开放的用户及权限(实际权限与本地权限有关)

 

 

        客户端的表示:

 

                *                        所有主机

 

                10.1.1.0/24                特定网段

 

                10.1.1.100                        特定IP

 

                *.uplooking.com        特定的域

 

 

        权限表示:

 

                ro                只读

 

                rw                读写

 

                root_squash        把root帐号映射成匿名帐号

 

                no_root_squash  不把root帐号映射成匿名帐号

 

                all_squash        把所有用户映身成匿名帐号

 

                anonuid=xxx        指定匿名账号的uid

 

                anongid=xxx        指定匿名帐号的gid

 

                sync                实时同步数据到磁盘

 

                async                异步数据存放

 

                secure                限制客户端只能从小于1024的TCP/IP

 

                                端口连服务器

 

                insecure        允许大于1024端口连服务器

 

                subtree_check        若输出目录是一个子目录,则NFS服务器检查

 

                                其父目录权限

 

                no_subtree_check

 

 

开机启动

 

        查看是否开机自动启动

 

          chkconfig --list | grep nfs

 

          chkconfig --list | grep portmap

 

 

        设置开机启动

 

          chkconfig --level 35 nfs on

 

          chkconfig --level 35 portmap on

 

        禁止开机启动

 

          chkconfig --level 345 portmap off

 

          chkconfig --level 35 nfs off

 

 

手动启动:

 

        启动:service portmap start

 

        停止:service portmap stop

 

        重启:service portmap restart

 

 

        启动:service nfs start

 

        停止:service nfs stop

 

        重启:service nfs restart

 

 

 

        配好后,启动portmap,nfs服务

 

                service portmap start(restart)

 

                service nfs start

 

 

 

相关操作命令:

 

    1、showmount        查看NFS服务器的共享情况

 

        语法:        showmount [选项]  NFS服务器名或IP        

 

                -a        查看NFS服务器的所有客户连接信息

 

                -d        显示NFS服务器中已被挂载的目录

 

                -e        查看NFS服务器所有的共享目录

 

 

    2、mount                挂载

 

         mount -t nfs 10.1.1.1:/share/rhel_source /mnt        

 

         将NFS服务器上共享的文件挂载到本地

 

 

    3、exportfs        维护NFS服务器的共享目录

 

        -a        输出在/etc/exports中所有设置的目录

 

        -v        在屏幕上显示

 

        -r        重新读取/etc/exports,并使设置生效,不重启nfs服务

 

        -u        停止共享

 

 

    4、如何将一个NFS服务的共享目录开机挂载

 

        将portmap设置为开机启动

 

        编/etc/fstab,添加

 

        10.1.1.1:/share/rhel_source   /mnt  nfs  defaults   0 0

 

 

    5、rpcinfo         查看rpc服务的注册状态

 

        -p                显示所有端口与程序

 

 

常见问题:

 

        1、portmap 没有启动

 

        2、注意防火墙

 

           service iptables status(看防火墙状态)

 

           service iptables stop (停用防火墙)

 

 

 

samba(用于linux、windows之间的文件共享)

 

有两个守护进程:smbd、nmbd

 

 

安装:yum install samba

 

 

        samba-client.i386        客户端包

 

        samba-common.i386        公共包

 

        samba.i386                服务器端

 

        samba-swat.i386        

 

        system-config-samba

 

 

配置samba服务器

 

        vim /etc/samba/smb.conf

 

                 security = user/share  共享方式share可匿名访问

 

          添加共享目录

 

                [mysamba]

 

                   comment = linux samba server

 

                  path = /share/smb  共享路径

 

                   browseable = yes  是否可浏览               

 

                   public = yes        是否匿名访问

 

                  writeable = yes   是否可写

 

 

        再启动服务:

 

                service smb start

 

 

        测试配置文件是否有语法错误:

 

                testparm

 

 

        如果采用的是security = user这种模式,则需要

 

        1、为smb建linux用户                 useradd samba

 

        2、将此用户加到samba服务器中         smbpasswd -a samba

 

 

客户端使用:

 

   share方式:

 

        smbclient -L //10.1.1.125  查看共享

 

        mount -t cifs //10.1.1.125/mysamba /mnt2

 

   user方式:

 

        smbclient -L //10.1.1.125 -U samba  查看

 

        smbclient //10.1.1.125/soft -U samba  登录,象FTP那样使用

 

        mount -t cifs -o username=samba //10.1.1.125/soft /mnt2

 

 

练习:

 

        1、在/建share目录,将其共享出去,让10.1.1.x1只读,

 

          10.1.1.X2能读写(X1,X2为自已指定的IP)

 

        

 

        2、搭建一个nfs服务器

 

           /share/music  10.1.1.0/24网段下所有人都可只读访问,把管

 

                            理员映射成匿名用户

 

           /share/ftp           10.1.1.X可进行读写,其它用户只读,并把所有

 

                            用户映射成匿名用户

 

           /share/www           所有人只读,所有用户映射成uid=501,gid=501

 

 

        3、用share和user方式,搭建一个samba服务器

 

        

 

vsftp

 

 

  ftp有两种工作模式:主动模式(port模式)和被动模式(pasv模式)

 

    主动模式下:服务器使用20(数据端口)、21(控制端口)端口

 

    被动模式下:服务器使用21(控制端口)、和一个随机端口(数据端口)。

 

 

安装:

 

    需要的软件包:vsftpd

 

    安装:yum install vsftpd

 

 

配置服务器:

 

    vim /etc/vsftpd/vsftpd.conf

 

        anonymous_enable=YES                是否允许匿名登录

 

        anon_root=/ftp                匿名登录后的FTP根目录,

 

                                        没设置时/var/ftp

 

        local_enable=YES                是否允许本地用户登录

 

        local_root=/ftp                本地用户登录后的FTP根目录

 

                                        没设置时在自己的家目录

 

        write_enable=YES                是否允许本地用户可写

 

        chroot_local_user=YES        是否将用户锁定在ftp家目录中

 

 

        anon_upload_enable=YES        是否允许匿名上传

 

        anon_mkdir_write_enable=YES        是否允许创建目录

 

        anon_other_write_enable=YES        是否允许其它的写(删除)

 

        anon_umask=022                上传的权限掩码(777或666来减)

 

        anon_max_rate=30000                限速,单位Byte/s

 

 

        local_umask=022                本地用户上传的权限排码

 

        local_max_rate=60000                本地用户限速

 

 

        max_clients=3                        客户端的最大连接数

 

        max_per_ip=2                        每个IP的最大连接数

 

 

        pasv_enable=YES                支持被动模式

 

        pasv_max_port=10240                被动模式的可用的最大端口号

 

        pasv_min_port=1024                被动模式的可用的最小端口号

 

 

访问控制:

 

        /etc/vsftpd/ftpusers                此文件中的所有用户不能登录FTP

 

        /etc/vsftpd/user_list        此文件与下面设置有关

 

 

        userlist_enable=YES                是否启用user_list

 

        userlist_deny=YES                为YES时,不允许user_list中的用

 

                                        户登录ftp,为NO时,只允许

 

                                        user_list中的用户登录

 

 

会话设置:

 

        idle_session_timeout=600        空闲会话超时

 

        data_connection_timeout=600        数据传输超时

 

 

 

启动服务器:

 

        service vsftpd start

 

 

 

apache        

 

    需要安装的包:httpd、httpd-devel、httpd-manual

 

    安装:yum install httpd*

 

 

服务器配置:

 

     vim /etc/httpd/conf/httpd.conf

 

 

        Listen 80        监听端口

 

        User apache        运行的身份(用户)

 

        Group apache        运行的身份(组)

 

        ServerAdmin root@localhost                管理员邮箱

 

        ServerName www.example.com:80</a>        服务器默认绑定的域名

 

        DocumentRoot "/var/www/html"        网站页面存放路径

 

        DirectoryIndex aa.html index.html         定义网站首页

 

 

 

去掉apache自己的测试页:

 

        方法一:将/etc/httpd/conf.d/welcome.conf 改后辍名

 

        方法一:将/var/www/error/noindex.html        改名

 

                                

 

 

服务器做多个网站(虚拟主机)

 

方案一:基于IP

 

    1、添加一个IP

 

        ifconfig eth0:0 192.168.1.125 netmask 255.255.255.0

 

    2、vim /etc/httpd/conf/httpd.conf

 

 

        NameVirtualHost 10.1.1.125:80

 

        NameVirtualHost 192.168.1.125:80

 

 

        <VirtualHost 10.1.1.125:80>

 

            DocumentRoot /www/163

 

            ServerName www.163.com</a>

 

            ErrorLog logs/163.com-error_log

 

            CustomLog logs/163.com-access_log common

 

        

 

        <VirtualHost 192.168.1.125:80>

 

            DocumentRoot /www/sina

 

            ServerName www.sina.com</a>

 

            ErrorLog logs/sina.com-error_log

 

            CustomLog logs/sina.com-access_log common

 

        

 

 

        确保DocumentRoot及其下面的文档存在

 

    3、重启服务

 

    4、访问

 

        http://10.1.1.125</a>    --->163.com

 

        http://192.168.1.125</a> --->sina.com

 

 

方案二:基于端口

 

    1、vim /etc/httpd/conf/httpd.conf

 

 

        Listen 80

 

        Listen 81                -->添加滥听的端口

 

        Listen 82

 

 

        NameVirtualHost 10.1.1.125:80

 

        NameVirtualHost 10.1.1.125:81

 

 

        <VirtualHost 10.1.1.125:80>

 

            DocumentRoot /www/163

 

            ServerName www.163.com</a>

 

            ErrorLog logs/163.com-error_log

 

            CustomLog logs/163.com-access_log common

 

        

 

        <VirtualHost 10.1.1.125:81>

 

            DocumentRoot /www/sina

 

            ServerName www.sina.com</a>

 

            ErrorLog logs/sina.com-error_log

 

            CustomLog logs/sina.com-access_log common

 

        

 

 

方案三:基于域名

 

    1、vim /etc/httpd/conf/httpd.conf

 

 

        NameVirtualHost *:80

 

 

        <VirtualHost *:80>

 

            DocumentRoot /www/163

 

            ServerName www.163.com</a>

 

            ErrorLog logs/163.com-error_log

 

            CustomLog logs/163.com-access_log common

 

        

 

 

        <VirtualHost *:80>

 

            DocumentRoot /www/sina

 

            ServerName www.sina.com</a>

 

            ErrorLog logs/sina.com-error_log

 

            CustomLog logs/sina.com-access_log common

 

        

 

 

    2、vim /etc/hosts

 

                10.1.1.125     www.163.com</a>       163.com

 

                10.1.1.125     www.sina.com</a>      sina.com

 

 

 

 

 

        

 

练习:1、做一个能让匿名用户上传下载的FTP站点,限制最大下载速度为50K,

 

              最大用户连接数为5个,上传后的文件权限为644。

 

 

      2、架设一FTP服务器,关闭被动模式的连接,只允许mary和ftp两个用户

 

        连接,空闲会话时间120秒。

 

 

      3、搭建三个网站,用基于IP、基于端口、基于域名三种方式分别实现。

 

shell编程

 

        

 

shell:是一个命令解释器,侦听用户指令、启动这些命令所指定的进程,

 

        并将结果返回给用户(交互式shell)

 

 

        同时shell也是一种程序设计语言,它有变量、关键字,各种控制语句

 

        有自己的语法结构,利用它可以编写功能很强、代码简短的程

 

        序(shell脚本)

 

 

        shell很多,cat /etc/shells查看当前支持的shell

 

        echo $SHELL        查看当前使用的shell

 

        

 

bash的初始化过程:

 

        用户登录linux时,会依次执行以几个文件:

 

        /etc/profile --> ~/.bash_profile --> ~/.bashrc  

 

        --> /etc/bashrc

 

        

 

 

        其中/etc/profile 会调用/etc/profile.d下的所有.sh

 

 

~/.bash_logout        退出时会执行的

 

 

~/.bash_history        记录了用户最近执行的命令

 

 

关于历史记录的操作:

 

        history        显示历史记录

 

        ! !                执行上一个命令

 

        !n                执行第n号的历史记录

 

        !-n                执行历史中倒数的第n条命令

 

        !command        执行历史记录中最后一个command

 

 

与history有关的变量

 

        HISTFILE        历史记录文件

 

        HISTFILESIZE        历史记录文件中保存的历史记录数

 

        HISTSIZE        退出时写到HISTFILE中最大记录数

 

 

如何不写历史记录?

 

        

 

 

一次执行多条命令:

 

    1、无条件执行

 

        将所有命令写在一行上,用;将要执行的命令分开

 

        用()括起来时,会在子shell中执行,执行完时子shell会关闭掉

 

        父shell不受影响。

 

 

    2、有条件执行

 

        后一条的执行受前一条的影响

 

        && 逻辑与,第一个执行成功时,才执行第二个

 

        | |  逻辑或,第一个执行不成功时,才执行第二个

 

 

重定向:>

 

        0 正常的输入

 

        1 正常的输出

 

        2 错误输出

 

                

 

返回值:

 

        linux每个进程执行完退出后,都会返回一些信息给父进程,叫返回状态,

 

        用整数表示,范围一在0-255之间。0表示执行成功,非0的话,就表示有

 

        某种形式的错误。

 

 

        如何查看返回值状态?

 

        返回值的保存有一个变量 ?,用于保存上次执行的返回值。

 

        通过 echo $? 可查看上次执行成功与否