zoukankan      html  css  js  c++  java
  • 64个命令,每天一个linux命令目录, shutdown,tee,rcp,

    每天一个linux命令目录

      开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每天一个linux命令。学习的主要参考资料为:

      1.《鸟哥的linux私房菜》

      2.http://codingstandards.iteye.com/blog/786653

      3.linux命令五分钟系列 

      4.其他互联网资料,google,baidu等搜索引擎

         11. 每天一个linux命令(11):nl命令

         12. 每天一个linux命令(12):more命令

         13. 每天一个linux命令(13):less 命令

         14. 每天一个linux命令(14):head 命令

         15. 每天一个linux命令(15):tail 命令

     二. 文件查找命令

          16. 每天一个linux命令(16):which命令

      17. 每天一个linux命令(17):whereis 命令

      18. 每天一个linux命令(18):locate 命令

      19. 每天一个linux命令(19):find 命令概览

      20. 每天一个linux命令(20):find命令之exec

        21. 每天一个linux命令(21):find命令之xargs

      22. 每天一个linux命令(22):find 命令的参数详解

    三. 文件和目录属性

      23. 每天一个linux命令(23):Linux 目录结构

        24. 每天一个linux命令(24):Linux文件类型与扩展名

        25. 每天一个linux命令(25):linux文件属性详解

    五. linux文件权限设置

      27. 每天一个linux命令(27):linux chmod命令

      29. 每天一个linux命令(29):chgrp命令

      30. 每天一个linux命令(30): chown命令

      31. 每天一个linux命令(31): /etc/group文件详解

    六.磁盘存储相关

      33. 每天一个linux命令(33):df 命令

      34. 每天一个linux命令(34):du 命令

    七.性能监控和优化命令:

      44.每天一个linux命令(44):top命令

      45.每天一个linux命令(45):free 命令

      46.每天一个linux命令(46):vmstat命令

      47.每天一个linux命令(47):iostat命令

      51.每天一个linux命令(51):lsof命令

     八. 网络命令:

      52.每天一个linux命令(52):ifconfig命令 

      53.每天一个linux命令(53):route命令

      54.每天一个linux命令(54):ping命令

      55.每天一个linux命令(55):traceroute命令

      56.每天一个linux命令(56):netstat命令

      57.每天一个linux命令(57):ss命令

      58.每天一个linux命令(58):telnet命令

      59.每天一个linux命令(59):rcp命令

      60.每天一个linux命令(60):scp命令

    其他命令:

      35.每天一个linux命令(35):ln 命令

      36.每天一个linux命令(36):diff 命令

      37.每天一个linux命令(37):date命令

      38.每天一个linux命令(38):cal 命令

      39.每天一个linux命令(39):grep 命令

      40.每天一个linux命令(40):wc命令

      41.每天一个linux命令(41):ps命令

      48.每天一个linux命令(48):watch命令

      49.每天一个linux命令(49):at命令

      50.每天一个linux命令(50):crontab命令

    每天一个Linux命令(64)shutdown命令

        shutdown以一种安全的方式关闭系统。

        (1)用法:

        用法:  shutdown [参数] [时间] 

        (2)功能:

        功能:  系统关机命令,shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作,所有登陆用户都可以看到关机信息提示。

        原理:  shutdown通过通知init进程,要求它改换运行级别来实现。运行级别0用来关闭系统,运行级别6用来重启系统,运行级别1用来使系统进入执行系统管理任务状态,如果没有给出 -h 或 -r 标志时,这是 shutdown 命令的默认工作状态。

        (3)选项参数:

          1) -h          将系统关机

          2) -r         shutdown之后重新启动

          3) -k        只是送出信息给所有用户,但不会实际关机

          4) -f         重启时跳过磁盘检测

       5) -F          重启时强制磁盘检测。

          6) -c          取消运行中的 shutdown 进程。不可能为此选项指定 time 参数,但你可以在命令行输入一条解释消息来向所有用户说明。

                      (一般的shutdown指令可以用按“+”号来进行中断) 

        (4)实例:

          1)在特定的时间执行关机命令:

    shutdown -h now         //立即关机
    shutdown -h 12:00      //在12:00关机

          2)指定5分钟后关机,同时送出警告信息给登入用户

    复制代码
    root@Unbuntu:/home/sunjimeng# shutdown +5 "This System will be shutdown in 5 minute!"
    
    来自sunjimeng@Unbuntu的广播信息
        (/dev/pts/6) 于 10:38 ...
    
    The system is going down for maintenance in 5 minutes!   //系统提醒
    This System will be shutdown in 5 minute!          //用户自定义提醒
    复制代码

          3)取消关机命令

    shutdown -c

          4)在特定时间执行关机重启命令,并取消

    复制代码
    [sunmeng@localhost ~]$ su root            //必须是root用户
    密码:
    [root@localhost sunmeng]# shutdown -r +3 "3分钟后关机重启"
    Shutdown scheduled for 三 2016-06-29 19:47:26 PDT, use 'shutdown -c' to cancel.
    [root@localhost sunmeng]# 
    Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:26 PDT):
    
    3分钟后关机重启
    The system is going down for reboot at Wed 2016-06-29 19:47:26 PDT!
    [root@localhost sunmeng]# shutdown -c
    
    Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:50 PDT):
    
    The system shutdown has been cancelled at Wed 2016-06-29 19:45:50 PDT!
    复制代码

          5)shutdown -k并不会真正关机,仅仅是给各登录的用户发送提醒

    复制代码
    [root@localhost sunmeng]# shutdown -k "Warning:Maybe the system will be shutdown."
    Failed to parse time specification: Warning:Maybe the system will be shutdown.
    [root@localhost sunmeng]# shutdown -k 5 "Warning:Maybe the system will be shutdown."
    Shutdown scheduled for 三 2016-06-29 19:53:56 PDT, use 'shutdown -c' to cancel.
    [root@localhost sunmeng]# 
    Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:48:56 PDT):
    
    Warning:Maybe the system will be shutdown.
    The system is going down for power-off at Wed 2016-06-29 19:53:56 PDT!
    复制代码

          6)快速或慢速重启(Unbuntu有-f或-F参数,CentOS没有)

    shutdown -f  [time]         //快速重启,忽略磁盘检查
    shutdown -F  [time]         //强制磁盘检查

          (5)其他:

          1)永久更改系统时间:

    //date命令只能暂时更改系统时间,关机重启后时间又会回到之前,所以需要将时间写入bios
    [root@localhost sunmeng]# date -s "2016-06-30 11:05:10"
     2016年 06月 30日 星期四 11:04:30 PDT
    [root@localhost sunmeng]# clock -w

          2)显示机器的处理器架构:

    [root@localhost sunmeng]# arch
    x86_64

          3)其他关机命令:

    init 0             //关机
    init 6            //关机重启    
    reboot            //关机重启

          4)clock与date命令:

    复制代码
    //只有超级用户才能设置硬件时钟。
    [sunmeng@localhost ~]$ su root                                  
    密码:
    [root@localhost sunmeng]# clock --set --date="05/04/2013 14:30:01"        //设置硬件时间为2013年
    [root@localhost sunmeng]# clock
    2013年05月04日 星期六 14时30分12秒  -0.388214 秒
    [root@localhost sunmeng]# date                              //此时硬件时间为2013,系统时间为2016
    2016年 06月 29日 星期三 20:20:36 PDT
    [root@localhost sunmeng]# clock -s                           //根据硬件时间设置系统时间
    [root@localhost sunmeng]# date
    2013年 05月 04日 星期六 14:31:04 PDT
    [root@localhost sunmeng]# clock
    2013年05月04日 星期六 14时31分09秒  -0.101952 秒                    //系统时间和硬件时间都为2013年
    [root@localhost sunmeng]# date -s "2016-06-30 11:22:10"                //设置系统时间为2016年
    2016年 06月 30日 星期四 11:22:10 PDT
    [root@localhost sunmeng]# clock                            //系统时间为2016年,硬件时间为2013
    2013年05月04日 星期六 14时32分13秒  -0.559223 秒
    [root@localhost sunmeng]# clock -w                           //根据系统时间设置硬件时间
    [root@localhost sunmeng]# date
    2016年 06月 30日 星期四 11:22:51 PDT
    [root@localhost sunmeng]# clock
    2016年06月30日 星期四 11时22分56秒  -0.968643 秒
    复制代码

          5)显示本机shell的信息,也可以更改shell

    复制代码
    [sunmeng@localhost ~]$ chsh -l
    /bin/sh
    /bin/bash
    /sbin/nologin
    /usr/bin/sh
    /usr/bin/bash
    /usr/sbin/nologin
    /bin/tcsh
    /bin/csh
    [sunmeng@localhost ~]$ chsh -v
    chsh,来自 util-linux 2.23.2
    复制代码

        每天一个Linux命令的最后一篇,以后还会详细介绍Linux系统的其他相关知识。

    每天一个linux命令(62):tee命令

    转载 2013年12月06日 16:45:54

    在执行Linux命令时,我们可以把输出重定向到文件中,比如 ls >a.txt,这时我们就不能看到输出了,如果我们既想把输出保存到文件中,又想在屏幕上看到输出内容,就可以使用tee命令了。tee命令读取标准输入,把这些内容同时输出到标准输出和(多个)文件中(read from standard input and write to standard output and files. Copy standard input to each FILE, and also to standard output. If a FILE is -, copy again to standard output.)。在info tee中说道:tee命令可以重定向标准输出到多个文件(`tee': Redirect output to multiple files. The `tee' command copies standard input to standard output and also to any files given as arguments.  This is useful when you want not only to send some data down a pipe, but also to save a copy.)。要注意的是:在使用管道线时,前一个命令的标准错误输出不会被tee读取。

    常用参数

    格式:tee

    只输出到标准输出,因为没有指定文件嘛。

    格式:tee file

    输出到标准输出的同时,保存到文件file中。如果文件不存在,则创建;如果已经存在,则覆盖之。(If a file being written to does not already exist, it is created. If a file being written to already exists, the data it previously
    contained is overwritten unless the `-a' option is used.)

    格式:tee -a file

    输出到标准输出的同时,追加到文件file中。如果文件不存在,则创建;如果已经存在,就在末尾追加内容,而不是覆盖。

    格式:tee -

    输出到标准输出两次。(A FILE of `-' causes `tee' to send another copy of input to standard output, but this is typically not that useful as the copies are interleaved.)

    格式:tee file1 file2 -

    输出到标准输出两次,同时保存到file1和file2中。

    使用示例

    示例一 tee命令与重定向的对比

    [root@web ~]# seq 5 >1.txt 
    [root@web ~]# cat 1.txt 
    1
    2
    3
    4
    5
    [root@web ~]# cat 1.txt >2.txt 
    [root@web ~]# cat 1.txt | tee 3.txt 
    1
    2
    3
    4
    5
    [root@web ~]# cat 2.txt 
    1
    2
    3
    4
    5
    [root@web ~]# cat 3.txt 
    1
    2
    3
    4
    5
    [root@web ~]# cat 1.txt >>2.txt 
    [root@web ~]# cat 1.txt | tee -a 3.txt 
    1
    2
    3
    4
    5
    [root@web ~]# cat 2.txt 
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5
    [root@web ~]# cat 3.txt 
    1
    2
    3
    4
    5
    1
    2
    3
    4
    5
    [root@web ~]#

    示例二 使用tee命令重复输出字符串

    [root@web ~]# echo 12345 | tee 
    12345

    [root@web ~]# echo 12345 | tee - 
    12345
    12345
    [root@web ~]# echo 12345 | tee - - 
    12345
    12345
    12345
    [root@web ~]# echo 12345 | tee - - - 
    12345
    12345
    12345
    12345
    [root@web ~]# echo 12345 | tee - - - - 
    12345
    12345
    12345
    12345
    12345
    [root@web ~]#

    [root@web ~]# echo -n 12345 | tee

    12345[root@web ~]# echo -n 12345 | tee - 
    1234512345[root@web ~]# echo -n 12345 | tee - - 
    123451234512345[root@web ~]# echo -n 12345 | tee - - - 
    12345123451234512345[root@web ~]# echo -n 12345 | tee - - - - 
    1234512345123451234512345[root@web ~]#

    示例三 使用tee命令把标准错误输出也保存到文件

    [root@web ~]# ls "*" 
    ls: *: 没有那个文件或目录
    [root@web ~]# ls "*" | tee - 
    ls: *: 没有那个文件或目录
    [root@web ~]# ls "*" | tee ls.txt 
    ls: *: 没有那个文件或目录
    [root@web ~]# cat ls.txt 
    [root@web ~]# ls "*" 2>&1 | tee ls.txt 
    ls: *: 没有那个文件或目录
    [root@web ~]# cat ls.txt 
    ls: *: 没有那个文件或目录
    [root@web ~]#

     
     
     
     

     rcp代表"remote file copy"(远程文件拷贝)。

        (1)用法:

        用法:  rcp [参数] [源文件] [目标文件]

        (2)功能:

        功能:  rcp命令用于在计算机之间拷贝文件。

        rcp命令使在两台Linux主机之间的文件复制操作更简单。通过适当的配置,在两台Linux主机之间复制文件而无需输入密码,就像本地文件复制一样简单。

        rcp命令有两种格式。第一种格式用于文件到文件的拷贝;第二种格式用于把文件或目录拷贝到另一个目录中。

        配置rcp命令的使用环境:

        1)如果系统中有 /etc/hosts 文件,系统管理员应确保该文件内包含要与之进行通信的远程主机的项:

    [root@localhost etc]# cat hosts                                    //hosts文件的内容
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    [root@localhost etc]# 

          介绍/etc/hosts:

          hosts文件是Linux主机名和ip配置文件,The static table lookup for host name(主机名查询静态表)。可以介绍本机或其他主机的主机名和IP地址。不同的Linux版本,其配置文件名可能不一样,比如Debian的对应文件时/etc/hostname。

          hosts配置文件对于在网络中作为服务器的Linux主机拥有极大作用。它记载了本地主机或远程主机的IP地址、域名和主机名的对应关系。因此我们可以通过输入域名或主机名访问IP,而不必输入难记的数字IP地址。而主机名多用来区分在同一局域网下的不同主机。

          host文件每一行的意思是:第一部分:网络IP地址;第二部分:主机名或域名;第三部分:主机名的别名。当然每行也可以是两部分,即主机IP地址和主机名。

      主机名(hostname)和域名(domain)的区别:
      主机名通常在局域网内使用,通过hosts文件,主机名就被解析到对应IP;
      域名通常在INTERNET上使用,但如果本机不想使用internet上的域名解析,这时就可以更改hosts文件,加入自己的域名解析。

          hosts文件可以解决的问题:

          1.远程登录linux主机过慢:有时候客户端想要远程登录一台linux主机,但每次登录输入密码后都会等很长一段时间才会进入,这是因为linux主机在返回信息时需要解析IP,如果在linux主机的hosts文件事先就加入客户端的IP地址,这时再从客户端远程登录linux就会很快。

          2.双机互联:当两台主机只是双机互连时,这时两台主机都需要设置自己的ip,同时在对方的hosts文件里加入自己的ip和主机名。

          主机名修改工具hostname的使用:

          hostname命令用于显示和设置系统的主机名称。环境变量HOSTNAME也保存了当前的主机名。在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名。如果需要永久修改主机名,需要同时修改/etc/hosts和/etc/sysconfig/network的相关内容。

    复制代码
    hostname---show or set the system's host name
    [root@localhost etc]# hostname                              //显示主机名
    localhost.localdomain
    [root@localhost etc]# hostname -a                //显示所有hosts配置信息
    localhost.localdomain localhost4 localhost4.localdomain4 localhost.localdomain localhost6 localhost6.localdomain6
    [root@localhost etc]# hostname -i                //显示已配置的IP地址
    ::1 127.0.0.1
    [root@localhost etc]# hostname sunmeng
    [root@localhost etc]# hostname
    sunmeng                               
    复制代码

        2)修改两台Linux主机的hosts文件:(host文件里的内容就相当于一个用户DNS服务器,将主机名解释为对应IP地址)

          在这里我实现的是CentOS7.0与Unbuntu14.04之间的连接,它们的信息如下:

    Unbuntu:
    IP地址:192.168.0.11     //用ifconfig命令获得
    主机名:Unbuntu          //用hostname主机名修改工具获得
    CentOS:
    IP地址:192.168.0.15
    主机名:CentOS

          在两者的hosts文件中加上对方的信息:

    复制代码
    Unbuntu:
    root@SJM:/home/sunjimeng#cat /etc/hosts
    127.0.0.1        localhost
    127.0.1.1        SJM
    192.168.0.15  CentOS
    #The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters CentOS: [root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.11 Unbuntu
    复制代码

        3)在root用户的根目录下创建.rhosts文件,加入远端主机的主机名和要连接的用户名:

          .rhosts 文件是 /etc/hosts.equiv 文件的用户等效文件。此文件包含主机-用户组合列表,而不包含一般意义的主机。如果此文件中列出了主机-用户组合,则指定用户将被授予从指定主机登录而不必提供口令的权限。

          在.rhosts文件和hosts.equiv文件中,真正起作用的是后者。但在不同系统中,都写上终归不会错。

    复制代码
    Unbuntu:     //配置允许CentOS上的用户root和sunmeng免密码登录
    root@Unbuntu:/home/sunjimeng# cat /etc/hosts.equiv
    # /etc/hosts.equiv: list  of  hosts  and  users  that are granted "trusted" r
    #            command access to your system 
    CentOS      sunmeng
    CentOS      root
    root@Unbuntu:/home/sunjimeng# cat /root/.rhosts
    CentOS      sunmeng
    CentOS      root
    
    CentOS:    //配置允许Unbuntu上的用户root和sunjimeng免密码登录
    [root@CentOS sunmeng]# cat /root/.rhosts
    Unbuntu  sunjimeng
    Unbuntu  root
    [root@CentOS sunmeng]# cat /etc/hosts.equiv
    Unbuntu  sunjimeng
    Unbuntu  root                //需要注意的一点是:从CentOS主机上登录Unbuntu,不能直接用Unbuntu的root登录。而从Unbuntu上均可。(Unbuntu不允许远端用户直接获得root权限,应该先登录用户,再用su命令)
    复制代码

          而且.rhosts文件得权限最好进行如下配置:(.rhosts 文件存在严重的安全问题。任何用户都可以创建 .rhosts 文件,从而可以在系统管理员不知情时对其选择的任何人授予访问权限。)

    root@Unbuntu:/home/sunjimeng# ls -l /root/.rhosts
    -rw-r--r-- 1 root root 37  6月 24 12:48 /root/.rhosts
    root@Unbuntu:/home/sunjimeng# chmod 600 $HOME/.rhosts
    root@Unbuntu:/home/sunjimeng# ls -l /root/.rhosts
    -rw------- 1 root root 37  6月 24 12:48 /root/.rhosts

        4)启动rsh服务(rcp命令的实现实际上是系统调用rsh服务实现的)

          CentOS:

          1.检查系统是否安装rsh和rsh-server软件包:

    CentOS                        //已经安装好,如果没有安装,使用yum install rsh和yum install rsh-server安装
    [root@localhost sunmeng]# rpm -aq |grep "rsh"
    rsh-0.17-76.el7_1.1.x86_64
    rsh-server-0.17-76.el7_1.1.x86_64

          2.检查系统是否安装xinetd守护进程:

    [root@localhost xinetd.d]# rpm -qa |grep xinetd
    xinetd-2.3.15-12.el7.x86_64

          xinetd的配置文件:xinetd.conf:

    复制代码
    [root@localhost etc]# cat xinetd.conf
    #
    # This is the master xinetd configuration file. Settings in the
    # default section will be inherited by all service configurations
    # unless explicitly overridden in the service configuration. See
    # xinetd.conf in the man pages for a more detailed explanation of
    # these attributes.
    
    defaults
    {
    # The next two items are intended to be a quick access place to
    # temporarily enable or disable services.
    #
    #    enabled        =
    #    disabled    =
    
    # Define general logging characteristics.
        log_type    = SYSLOG daemon info 
        log_on_failure    = HOST
        log_on_success    = PID HOST DURATION EXIT
    
    # Define access restriction defaults
    #
    #    no_access    =
    #    only_from    =
    #    max_load    = 0
        cps        = 50 10
        instances    = 50
        per_source    = 10
    
    # Address and networking defaults
    #
    #    bind        =
    #    mdns        = yes
        v6only        = no
    
    # setup environmental attributes
    #
    #    passenv        =
        groups        = yes
        umask        = 002
    
    # Generally, banners are not used. This sets up their global defaults
    #
    #    banner        =
    #    banner_fail    =
    #    banner_success    =
    }
    
    includedir /etc/xinetd.d          //这里说明xinetd启动时将/etc/xinetd.d文件夹下的文件包含进来
     
    复制代码

          3.在/etc/xinetd.d目录下查找是否有rsh和rlogin,如果没有按照下面文件得内容创建一份,注意红色的部分为no。

    复制代码
    [root@localhost xinetd.d]# cat rlogin
    #default:on
    # description: rlogind is the server for the rlogin(1) program. The server  
    # provides a remote login facility with authentication based on  
    # privileged port numbers from trusted hosts.  
    service login  
    {
    disable = no socket_type = stream wait = no user = root log_on_success += USERID log_on_failure += USERID server = /usr/sbin/in.rlogind
    } [root@localhost xinetd.d]# cat rsh #default:on # description: The rshd server is the server for the rcmd(3) routine and, # consequently, for the rsh(1) program. The server provides # remote execution facilities with authentication based on # privileged port numbers from trusted hosts. service shell { disable = no socket_type = stream wait = no user = root log_on_success += USERID log_on_failure += USERID server = /usr/sbin/in.rshd }
    复制代码

          然后最好用service xinetd restart命令重启一下守护进程。

          4.编辑/etc/securetty,确保存在rexec、rsh、rlogin三行

    复制代码
    [root@localhost etc]# cat /etc/securetty
    console
    vc/1
    vc/2
    vc/3
    vc/4
    vc/5
    vc/6
    vc/7
    vc/8
    vc/9
    vc/10
    vc/11
    tty1
    tty2
    tty3
    tty4
    tty5
    tty6
    tty7
    tty8
    tty9
    tty10
    tty11
    ttyS0
    ttysclp0
    sclp_line0
    3270/tty1
    hvc0
    hvc1
    hvc2
    hvc3
    hvc4
    hvc5
    hvc6
    hvc7
    hvsi0
    hvsi1
    hvsi2
    xvc0
    rexec                       //如果没有自己添加
    rsh
    rlogin
    复制代码

          5.此时用setup命令查看系统服务,已经包含了rsh和rlogin,并且默认启动:(之前是没有的)

          Ubuntu:

          1.安装rsh-client和rsh-server软件包:

    复制代码
    root@Unbuntu:/home/sunjimeng# apt-get install rsh        //在Unbuntu的软件包库中没有rsh软件。
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    E: 未发现软件包 rsh
    root@Unbuntu:/home/sunjimeng# apt-get install rsh-client    //rsh-client相当于CentOS(Red Hat系列)的rsh
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    rsh-client 已经是最新的版本了。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 588 个软件包未被升级。
    root@Unbuntu:/home/sunjimeng# apt-get install rsh-server
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    rsh-server 已经是最新的版本了。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 588 个软件包未被升级。
    复制代码

          2.安装守护进程xinetd:

    root@Unbuntu:/home/sunjimeng# apt-get install xinetd
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    xinetd 已经是最新的版本了。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 588 个软件包未被升级。

          Unbuntu的xinetd守护进程的配置文件xinetd.conf:

    复制代码
    root@Unbuntu:/etc# cat xinetd.conf
    # Simple configuration file for xinetd
    #
    # Some defaults, and include /etc/xinetd.d/
    
    defaults
    {
    
    # Please note that you need a log_type line to be able to use log_on_success
    # and log_on_failure. The default is the following :
    # log_type = SYSLOG daemon info
    
    }
    
    includedir /etc/xinetd.d              //也要求包含/etc/xinetd.d目录下的文件
    复制代码

          3.在/etc/init.d文件夹下新建rsh、rlogin和rexec文件:(如果之前没配置)

    复制代码
    root@Unbuntu:/etc/xinetd.d# cat rsh
    # default: on
    # descrīption: The rshd server is the server for the rcmd(3) routine and, 
    #       consequently, for the rsh(1) program.  The server provides 
    #       remote execution facilities with authentication based on 
    #       privileged port numbers from trusted hosts.
    service shell
    {
            disable = no
            socket_type             = stream
            wait                    = no
            user                    = root
            log_on_success          += USERID
            log_on_failure          += USERID
            server                  = /usr/sbin/in.rshd
    }
    root@Unbuntu:/etc/xinetd.d# cat rlogin
    #####################################################
    #default:on
    # descrīption: rlogind is the server for the rlogin(1) program.  The server 
    #       provides a remote login facility with authentication based on 
    #       privileged port numbers from trusted hosts.
    service login
    {
            disable = no
            socket_type             = stream
            wait                    = no
            user                    = root
            log_on_success          += USERID
            log_on_failure          += USERID
            server                  = /usr/sbin/in.rlogind
    }
    root@Unbuntu:/etc/xinetd.d# cat rexec
    #default:off
    # descrīption: Rexecd is the server for the rexec(3) routine. The server 
    # provides remote execution facilities with authentication based 
    # on user names and passwords.
    service exec
    {
    disable = no
    socket_type = stream
    wait = no
    user = root
    log_on_success += USERID
    log_on_failure += USERID
    server = /usr/sbin/in.rexecd
    }
    复制代码

          4.重启xinetd服务:

    root@Unbuntu:/etc# /etc/init.d/xinetd restart
     * Stopping internet superserver xinetd                                  [ OK ] 
     * Starting internet superserver xinetd                                  [ OK ]

        5)rsh服务的简单测试:(实现用CentOS登录Unbuntu列出Unbuntu的home目录和Unbuntu登录CentOS列出CentOS的home目录)

    复制代码
    CentOS的home目录:
    [root@localhost home]# ll
    total 4
    drwx------. 14 sunmeng sunmeng 4096 Jun 28 01:47 sunmeng
    Unbuntu的home目录:
    sunjimeng@Unbuntu:/home$ ll
    总用量 12
    drwxr-xr-x  3 root      root      4096  6月 24 13:36 ./
    drwxr-xr-x 23 root      root      4096  6月 24 10:37 ../
    drwxr-xr-x 20 sunjimeng sunjimeng 4096  6月 28 14:54 sunjimeng/
    复制代码
    复制代码
    CentOS登录Unbuntu:
    [root@localhost home]# rsh Unbuntu      //等价于rsh 192.168.0.11 Password: Login incorrect Unbuntu login: sunjimeng Password: Last login: Tue Jun 28 18:09:24 CST 2016 from CentOS on pts/4 Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/ sunjimeng@Unbuntu:~$ ls -l /home 总用量 4 drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 28 14:54 sunjimeng

    Unbuntu登录CentOS: sunjimeng@Unbuntu:/home$ rsh CentOS    //等价于rsh 192.168.0.15 Password: Password: Login incorrect CentOS login: sunmeng Password: Last failed login: Tue Jun 28 03:26:40 PDT 2016 from Unbuntu on pts/2 There was 1 failed login attempt since the last successful login. Last login: Tue Jun 28 01:27:45 from ::ffff:192.168.0.18 [sunmeng@CentOS ~]$ ls /home sunmeng
    复制代码

          远程登录时可能会出现下面的问题:

    sunjimeng@Unbuntu:~$ rsh CentOS
    CentOS: No route to host

         有两种原因:1.远程机没有安装并启动rsh-server服务;2.防火墙阻止了本地机对远程机rsh服务端口(无论是rsh还是rlogin都是513端口) 。

         对于第二个问题:你可以选择关闭远程机防火墙,也可以让防火墙开启tcp连接的513端口,对外部所有IP开放访问。(同时,你还可以修改rsh和rlogin的端口,不用513号端口)

         在CentOS中使用iptables命令操作防火墙,也可以用图形界面,类似telnet命令中开放23号端口的那样。

         在Unbuntu中使用了iptables的升级命令ufw命令操作防火墙。

    root@Unbuntu:/home/sunjimeng# ufw status    //显示防火墙状态
    状态:不活动
    root@Unbuntu:/home/sunjimeng# ufw allow 513    //开放513号端口
    防火墙规则已更新
    规则已更新(v6)
    root@Unbuntu:/home/sunjimeng# ufw disable      //关闭防火墙

        (3)选项参数:

          1) -r           递归地把源目录中的所有内容拷贝到目的目录中。要使用这个选项,目的必须是一个目录。

          2) -p            试图保留源文件的修改时间和模式,忽略umask。

          3) -x            为传送的所有数据打开DES加密。 

          4) -D          指定远程服务器的端口号。

          5) -r            递归处理,将指定目录下的文件与子目录一并处理

        (4)实例:

          1)root@Unbuntu:/home/sunjimeng# rsh -l root CentOS          rsh指定用户名登录

    root@Unbuntu:/home/sunjimeng# rsh -l root CentOS
    Password: 
    Last failed login: Tue Jun 28 03:54:33 PDT 2016 from Unbuntu on pts/2
    There were 2 failed login attempts since the last successful login.
    Last login: Tue Jun 28 03:53:19 from Unbuntu
    [root@CentOS ~]# 

            在集群的所有节点都已经配置好了.rhosts和/etc/hosts的信息,并且rsh服务已经打开,防火墙已经关闭。rsh hostname已经通过测试,但是使用rsh hostname  rcmd 来执行命令,未能通过,出现no route to host错误:

    root@Unbuntu:/etc# rsh -l root CentOS ls -l /home/sunmeng            //Unbuntu登录CentOS
    CentOS: No route to host
    [root@localhost sunmeng]# rsh -l sunjimen Unbuntu /bin/ls -l /home        //CentOS登录Unbuntu
    poll: protocol failure in circuit setup

          解决方法:

      1.修改SELinux的配置文件(目的是关闭SELinux):

    复制代码
    [root@localhost selinux]# cd /etc/selinux
    [root@localhost selinux]# ll
    total 12
    -rw-r--r--. 1 root root  547 Jun 21 11:15 config
    -rw-r--r--. 1 root root 2321 Jun  9  2014 semanage.conf
    drwxr-xr-x. 6 root root 4096 Jun 23 01:50 targeted
    [root@localhost selinux]# vi config
    [root@localhost selinux]# cat config
    
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    #SELINUX=enforcing   //oringin version
    SELINUX=disabled     //after modifying
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted 
    复制代码

          修改之后并无明显作用,但最好关闭。

          2.让防火墙开放端口513,514和1021-1023:(直接把两台主机的防火墙都关了也行)

          CentOS:

          Unbuntu:ufw allow 513 514 1021 1022 1023

          原因:(http://goodluck1982.blog.sohu.com/134666734.html)

          直接使用 rsh <host> 命令方式和使用 rsh <host> <cmd> 命令方式,其实本质上是不一样的:前者实质上调用的是 rlogin 程序,而后者才是真正意义上的 remote shell。所以,前者对应的是 rlogin 服务的端口,为 513;后者对应的才是 remote shell 服务的端口 514。

      而使用 rsh <host> <cmd> 命令方式时,具体过程还是有些特殊的:本地机先链接服务端的 514 端口,然后服务端还要以约定好的端口(1021~1023)与客户端相连,所以要顺利执行该命令的话,即要求服务端允许 514 端口链接,还要求本地机允许1021~1023端口的链接,这样就必须正确配置防火墙。

      如果没有在本地机允许1021~1023端口,则会出现如下错误: poll: protocol failure in circuit setup。

          2)以rsh  [host]  [command]的方式登录远程主机并执行命令:

    复制代码
    CentOS登录Unbuntu并执行命令:
    [root@localhost sunmeng]# rsh Unbuntu ls -l /home/sunjimeng
    total 48
    -rw-r--r-- 1 sunjimeng sunjimeng 8980 Jun 24 10:26 examples.desktop
    drwxr-xr-x 2 root      root      4096 Jun 24 12:12 vm
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 28 21:12 下载
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 公共的
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 图片
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 文档
    drwxr-xr-x 4 sunjimeng sunjimeng 4096 Jun 28 14:42 桌面
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 模板
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 视频
    drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 24 10:43 音乐
    Unbuntu登录CentOS并执行命令:
    root@Unbuntu:/home/sunjimeng# rsh CentOS ls -l /home/sunmeng
    total 4
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 23 02:29 Desktop
    drwxr-xr-x. 2 sunmeng sunmeng 4096 Jun 27 20:18 Documents
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Downloads
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Music
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Pictures
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Public
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Templates
    -rw-rw-r--  1 sunmeng sunmeng    0 Jun 28 05:45 text.c
    drwxr-xr-x. 2 sunmeng sunmeng    6 Jun 21 03:31 Videos
    drwxr-xr-x  7 sunmeng sunmeng  155 Jun 28 04:34 桌面
    复制代码

          3)将文件拷贝到远端机,或者把远端机上的文件拷贝到本地

    复制代码
    将Unbuntu的 /home/sunjimeng/下载 目录下的text文件拷贝到CentOS的 /home/sunmeng文件夹下:
    //1.拷贝前的文件信息:
    [root@localhost sunmeng]# ll
    总用量 4
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  23 02:29 Desktop
    drwxr-xr-x. 2 sunmeng sunmeng 4096 6月  27 20:18 Documents
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Downloads
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Music
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Pictures
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Public
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Templates
    -rw-rw-r--  1 sunmeng sunmeng    0 6月  28 05:45 text.c
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Videos
    drwxr-xr-x  7 sunmeng sunmeng  155 6月  28 04:34 桌面
    //2.在Unbuntu终端执行:
    root@Unbuntu:/home/sunjimeng/下载# vi text
    root@Unbuntu:/home/sunjimeng/下载# cat text
    This is from Unbuntu!
    
    root@Unbuntu:/home/sunjimeng/下载# rcp text CentOS:/home/sunmeng
    //3.拷贝后的文件信息
    [root@localhost sunmeng]# ll
    总用量 8
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  23 02:29 Desktop
    drwxr-xr-x. 2 sunmeng sunmeng 4096 6月  27 20:18 Documents
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Downloads
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Music
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Pictures
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Public
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Templates
    -rw-r--r--  1 root    root      23 6月  28 18:33 text
    -rw-rw-r--  1 sunmeng sunmeng    0 6月  28 05:45 text.c
    drwxr-xr-x. 2 sunmeng sunmeng    6 6月  21 03:31 Videos
    drwxr-xr-x  7 sunmeng sunmeng  155 6月  28 04:34 桌面
    [root@localhost sunmeng]# cat text
    This is from Unbuntu!
    
    --------------------------------------------------------------------------------------------------------------------------------- 将CentOS的 /home/sunmeng 下的text.c拷贝到Unbuntu的 /home/sunjimeng/下载: //1.拷贝文件之前: root@Unbuntu:/home/sunjimeng/下载# ll 总用量 12 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 29 09:32 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ -rw-r--r-- 1 root root 23 6月 29 09:32 text //2.在CentOS主机上执行下面的命令: [root@localhost sunmeng]# vi text.c [root@localhost sunmeng]# cat text.c This is form CentOS! [root@localhost sunmeng]# rcp text.c Unbuntu:/home/sunjimeng/下载 //3.拷贝文件之后: root@Unbuntu:/home/sunjimeng/下载# ll 总用量 16 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 29 09:42 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ -rw-r--r-- 1 root root 23 6月 29 09:32 text -rw-r--r-- 1 root root 22 6月 29 09:42 text.c root@Unbuntu:/home/sunjimeng/下载# cat text.c This is form CentOS!
    复制代码

        (5)其他:

        在这个命令学习时遇到的问题:

          1)要实现Unbuntu14.04虚机与win10物理机的数据传输,虚机需要安装VMware Tools工具:

          1.在VMware Workstations的虚拟机菜单下选择安装VMware Tools:

          2.此时虚拟机将默认挂载虚拟CD/DVD驱动器,里面含有VMware Tools的安装包,默认权限是只可读。

          3.把安装包拷贝一份到用户具有读写权限的目录下,用tar命令解压:

    复制代码
    root@SJM:/home/sunjimeng/桌面# tar -ztvf VMwareTools-10.0.0-2977863.tar.gz
    root@SJM:/home/sunjimeng/桌面# ll
    总用量 69864
    drwxr-xr-x  3 sunjimeng sunjimeng     4096  6月 28 09:49 ./
    drwxr-xr-x 19 sunjimeng sunjimeng     4096  6月 28 10:10 ../
    -rw-rw-r--  1 sunjimeng sunjimeng 71524872  8月 12  2015 VMwareTools-10.0.0-2977863.tar.gz
    drwxr-xr-x  9 root      root          4096  8月 12  2015 vmware-tools-distrib/
    复制代码

          4.然后进入解压后自动生成的文件夹,执行安装软件的脚本:

    复制代码
    root@SJM:/home/sunjimeng/桌面# cd vmware-tools-distrib
    root@SJM:/home/sunjimeng/桌面/vmware-tools-distrib# ll
    总用量 524
    drwxr-xr-x  9 root      root        4096  8月 12  2015 ./
    drwxr-xr-x  3 sunjimeng sunjimeng   4096  6月 28 09:49 ../
    drwxr-xr-x  2 root      root        4096  8月 12  2015 bin/
    drwxr-xr-x  5 root      root        4096  8月 12  2015 caf/
    drwxr-xr-x  2 root      root        4096  8月 12  2015 doc/
    drwxr-xr-x  5 root      root        4096  8月 12  2015 etc/
    -rw-r--r--  1 root      root      279342  8月 12  2015 FILES
    -rw-r--r--  1 root      root        2538  8月 12  2015 INSTALL
    drwxr-xr-x  2 root      root        4096  8月 12  2015 installer/
    drwxr-xr-x 15 root      root        4096  8月 12  2015 lib/
    drwxr-xr-x  3 root      root        4096  8月 12  2015 vgauth/
    -rwxr-xr-x  1 root      root         243  8月 12  2015 vmware-install.pl*
    -rwxr-xr-x  1 root      root      205572  8月 12  2015 vmware-install.real.pl*
    root@SJM:/home/sunjimeng/桌面/vmware-tools-distrib# ./vmware-install.pl*      //必须要带./
    复制代码

          接下来就是安装过程。

           5.检查是否启动虚拟机与物理机共享剪贴板:(安装VMware Tools的主要目的)

          如果此时共享剪贴板还不能用,就重启一下虚拟机。

          2)在首次登录Unbuntu的终端时,su切换用户的命令不能使用:

          原因:  Unbuntu刚安装后,不能在terminal中运行su命令,因为root没有默认密码,需要手动设定。

          以安装unbuntu时输入的用户名登陆,该用户在admin组中,有权限给root设定密码。(默认打开终端就已登录)

    root@SJM:/# sudo password [root]     
    sudo:password: command not found   //注意是"passwd"而不是"password"
    root@SJM:/# sudo passwd [root]
    输入新的 UNIX 密码: 
    重新输入新的 UNIX 密码: 
    passwd:已成功更新密码

          3)Unbuntu默认不开启xinetd守护进程:

    apt-get install xinetd    //安装守护进程服务软件
    /etc/init.d/xinetd start  //启动xinetd服务

          4)在Unbuntu中如何查看系统服务:

          在Unbuntu中安装一个工具:sysv-rc-conf:

    root@SJM:/home/sunjimeng/下载# apt-get install sysv-rc-conf
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    sysv-rc-conf 已经是最新的版本了。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 588 个软件包未被升级。
  • 相关阅读:
    Netty学习笔记四:NIO实现群聊
    Netty学习三:NIO
    Netty学习二:IO模型 BIO
    Netty学习一:netty是什么
    idea远程debug
    filter,interceptor,controllerAdvice,aspect,controller执行顺序
    springboot使用多个@RestControllerAdvice时的拦截顺序
    记一次RestControllerAdvice无法拦截Filter内抛出异常
    SpringBoot声明式事务的简单运用
    mybatis plus 和PageHelper依赖冲突
  • 原文地址:https://www.cnblogs.com/timssd/p/8437169.html
Copyright © 2011-2022 走看看