系统版本:

ISO:CentOS-7-x86_64-Everything-1511

(安装时选择的语言是中文版,支持的还不错,看帮助信息很方便)

[zdw@node1 ~]$ cat /etc/redhat-release              #系统最小化安装,以上简称C7.2
CentOS Linux release 7.2.1511 (Core)


查看SSH端口:

[zdw@node1 ~]$ ss -tnl            #查看SSH端口,可以看到是默认的22
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      100        ::1:25                      :::*

wKioL1ecqe3xW7NqAAL4capI9pw100.jpg-wh_50


添加DNS:(IP地址设置略)

注:官方建议在/etc/sysconfig/network下设置DNS

[root@node1 ~]# vi /etc/sysconfig/network       #根据当地运营商,添加填写DNS1、DNS2
# Created by anaconda
DNS1=114.114.114.114                     
DNS2=202.106.0.20

查看IP地址:

描述:由于C7.2是最小化安装,无法使用在C5或C6上常用的ifconfig命令,可以使用ip addr list命令来查看,如果要使用ifocnfig,需要安装net-tools这个工具包。

[zdw@node1 ~]$ ifconfig                        
-bash: ifconfig: 未找到命令
[zdw@node1 ~]$ ip addr list | grep 'inet 10.3'
    inet 10.3.20.71/24 brd 10.3.20.255 scope global eno16777736

wKioL1ecrBjBnc0bAAMqC-XJ32I301.jpg-wh_50

安装net-tools工具包,来使用ifconfig命令

[root@node1 ~]# yum -y install net-tools      #切换到root下,安装工具包
.......
Running transaction
  正在安装    : net-tools-2.0-0.17.20131004git.el7.x86_64                   1/1 
  验证中      : net-tools-2.0-0.17.20131004git.el7.x86_64                   1/1 
已安装:
  net-tools.x86_64 0:2.0-0.17.20131004git.el7

使用ifconfig查看IP

[zdw@node1 ~]$ ifconfig | grep 'inet 10.3'

        inet 10.3.20.71  netmask 255.255.255.0  broadcast 10.3.20.255

wKioL1ecrZix2DEEAAMEkbHqIrY254.jpg-wh_50


防火墙:

查看规则:

[root@node1 ~]# iptables -L -n              #使用此命令查看规则
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           
.................略

清除规则:(只对当前有效)---一般不这么用

[root@node1 ~]# iptables -F

关掉:(只对当前有效)

[root@node1 ~]# systemctl stop firewalld.service
[root@node1 ~]# iptables -L -n                  
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

永久关掉:(这条常用)

[root@node1 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@node1 ~]# systemctl disable firewalld.service
[root@node1 ~]#

Centos 6关掉防火墙:

  ~]#service iptables stop
  ~]#chkconfig iptables off


终端设备:terminal

描述:多任务、多用户

      物理终端,控制台:console

      虚拟终端:6个 tty

                ctrl+alt+F[1-6]

      图形终端:

               CentOS 6:

               CentOS 7:

          在哪个虚拟终端启动,即位于哪个虚拟终端

    串行终端:ttys     

    伪终端:pty


    Linux的哲学思想之一:一切皆文件:

       表现之一:硬件设备也通过文件表示:

          物理终端:/dev/console

          虚拟终端:/dev/tty#[1,6]

          串行终端:/dev/ttyS#

          伪终端:/dev/pts/#

示例:

在SecureCRT上查看,克隆多个会话,tty查看显示的结果,显示是伪终端/dev/pts/0、1、2

[zdw@node1 ~]$ tty

/dev/pts/0

[root@node1 ~]# tty

/dev/pts/1

[root@node1 ~]# tty

/dev/pts/2

wKiom1ecsvHhkjxMAAJsDGa361k195.jpg-wh_50

在VMware上按ctrl+alt+F2,显示为串行终端tty2

wKioL1ecs_XxvEieAAJwk1CSlqM080.jpg-wh_50


查看接口程序:

[root@node1 ~]# echo $SHELL
/bin/bash


启动GUI:(此命令没有实验)

在某一虚拟终端接口运行命令:startx &


Linux命令帮助的获取:

内部命令帮助:

     # help COMMAND

使用type cd得知是内嵌命令,如需获取帮助,使用help cd,就能得到cd大体的使用格式

[root@node1 ~]# type cd                          #得知cd是内嵌命令
cd 是 shell 内嵌
[root@node1 ~]# help cd                          #使用help cd获取帮助
cd: cd [-L|[-P [-e]]] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.
    
    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.
    ........略

help也是内嵌命令,来查看它的帮助

[root@node1 ~]# type help
help 是 shell 内嵌
[root@node1 ~]# help help                         #中括号是可省略的
help: help [-dms] [模式 ...]
    显示内嵌命令的相关信息。
    
    显示内嵌命令的简略信息。如果指定了 PATTERN 模式,
    给出所有匹配 PATTERN 模式的命令的详细帮助,否则打
    印一个帮助主题列表
    
    选项:
      -d        输出每个主题的简短描述
      -m        以伪 man 手册的格式显示使用方法
      -s        为每一个匹配 PATTERN 模式的主题仅显示一个用法
        简介
    
    参数:
      PATTERN   Pattern 模式指定一个帮助主题
    
    退出状态:
    返回成功,除非 PATTERN 模式没有找到或者使用了无效选项。


shell程序搜寻可执行程序文件的路径定义在PATH环境变量中,如下:

[root@note1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

(根据PATH环境变量中设定的目录,自左而右逐个搜索目录下的文件名,如果在第一个里找到,就不会在往下找了)


hash命令(哈希):

  每次运行命令都要找一遍,每个路径下都有很多的命令,这样效率会很低,通常只有第一次运行命令它才会找从左到右找一次,找到会,放到缓存中,这个缓存就是内存中的一段空间(shell搜索到的外部命令的路径结果会缓存至kv(key-value)存储中),这个kv存储可以在hash中查看,如下:

[root@note1 ~]# hash                        #第一次输入,表为空
hash: 哈希表为空
[root@note1 ~]# ls                          #输入ls第一次
anaconda-ks.cfg
[root@note1 ~]# hash                        #hash中,命中(hits)了一次ls命令
命中    命令
   1    /usr/bin/ls                         
[root@note1 ~]# ls                          #输入ls第二次
anaconda-ks.cfg
[root@note1 ~]# hash                        #hash中,命中次数又加了一次,现在数值为2
命中    命令
   2    /usr/bin/ls
[root@note1 /]# cat /etc/fstab              #执行cat命令
[root@note1 /]# hash                        #hash中出现了1次cat
命中    命令
   1    /usr/bin/cat
   2    /usr/bin/ls
[root@note1 /]# type hash
hash 是 shell 内嵌
[root@note1 /]# help hash
hash: hash [-lr] [-p 路径名] [-dt] [名称 ...]
    记住或显示程序位置。
    
    确定并记住每一个给定 NAME 名称的命令的完整路径。如果
    不提供参数,则显示已经记住的命令的信息。
    
    选项:
      -d                忘记每一个已经记住的命令的位置
      -l                以可作为输入重用的格式显示
      -p pathname       使用 pathname 路径作为 NAME 命令的全路径
      -r                忘记所有记住的位置
      -t                打印记住的每一个 NAME 名称的位置,如果指定了多个
                NAME 名称,则每个位置前面会加上相应的 NAME 名称
    
    参数:
      NAME              每个 NAME 名称会在 $PATH 路径变量中被搜索,并
                且添加到记住的命令的列表中。
    
    退出状态:
    返回成功,除非 NAME 命令没有找到或者使用了无效的选项。

如果此时把ls从/bin/ls 移动到 /usr/bin/ls下(此试验换了一台主机名相同的测试机)

[root@note1 ~]# ls                                    #使用ls命令
anaconda-ks.cfg  install.log  install.log.syslog
[root@note1 ~]# hash                                  #hash中ls命中为1
hits    command
   1    /bin/ls
[root@note1 ~]# which ls                              #使用which查找ls所在位置
alias ls='ls --color=auto'
        /bin/ls
[root@note1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@note1 ~]# mv /bin/ls /usr/bin/ls                #把ls放在/usr/bin/下
[root@note1 ~]# ls                                    #再次执行ls,提示找不到目录
-bash: /bin/ls: No such file or directory
[root@note1 ~]# hash -r                               #按照上面的hash帮助,输入-r清除记录
[root@note1 ~]# ls                                    #输入ls,它又开始从左到右,直到找到ls
anaconda-ks.cfg  install.log  install.log.syslog