2016.7.6作业-- 提交版


修改默认启动级别

方法1:使用软连接实现

ln [-fs] source_file target_file

默认级别转换为3(文本模式)

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

或者默认级别转换为5(图形模式)

ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

重启:

reboot

实施过程

  • 设置字符终端为默认启动
    [root@localhost Desktop]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
    [root@localhost Desktop]# ls -ld /etc/systemd/system/default.target
    lrwxrwxrwx. 1 root root 37 Jul  6 10:13 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
    [root@localhost Desktop]#
    
  • 截图

  • 设置图形界面为默认启动
[root@localhost Desktop]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
[root@localhost Desktop]# ls -ld /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 36 Jul  6 10:16 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target
[root@localhost Desktop]# reboot
  • 截图

方法2:使用systemctl实现

systemctl set-default multi-user.target

用这个systemctl命令来查看默认目标

systemctl get-default

实施过程

设置默认为字符启动

  • 代码
[root@localhost Desktop]# systemctl get-default
graphical.target
[root@localhost Desktop]# systemctl set-default multi-user.target 
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@localhost Desktop]# vi /etc/systemd/system/default.target

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Multi-User System      
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
~                                                                                                                                                                                               
...//中间省略                                                                                                                                                                                                             
~                                                                                                                                                                                                                  
"/etc/systemd/system/default.target" 14L, 492C  
[root@localhost Desktop]# ls -ld /etc/systemd/system/default.target  
lrwxrwxrwx. 1 root root 41 Jul  6 10:23 /etc/systemd/system/default.target ->     /usr/lib/systemd/system/multi-user.target  
[root@localhost Desktop]#
  • 截图

设置默认图形界面启动

  • 代码
[root@localhost Desktop]# systemctl get-default 
multi-user.target
[root@localhost Desktop]# systemctl set-default graphical.target 
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@localhost Desktop]# ls -ld /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 40 Jul  6 10:30 /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
[root@localhost Desktop]# systemctl get-default 
graphical.target
[root@localhost Desktop]# vi /etc/systemd/system/default.target
[root@localhost Desktop]# 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes
~                                                                                                                                                                                                                  
~                                                                                               
...//中间省略                                                                                                                                                                                                                  
~                                                                                                                                                                                                                  
~                                                                                                                                                                                                                  
"/etc/systemd/system/default.target" 15L, 558C

切换运行级别

方法1:

切换到:运行级3

multi-user.target

使用multi-user来实现

systemctl isolate multi-user.target
runlevel3.target

使用runlevel3来实现

systemctl isolate runlevel3.target

切换到:运行级5

graphical.target
systemctl isolate graphical.target
runleve5.target
systemctl isolate runleve5.target

方法2:

init  [0123456]

查看当前运行的级别

runlevel  //仍然可用

修改主机名

 set-hostname NAME
           Set the system hostname to NAME. By default, this will alter the pretty, the static, and
           the transient hostname alike; however, if one or more of --static, --transient, --pretty
           are used, only the selected hostnames are changed. If the pretty hostname is being set,
           and static or transient are being set as well, the specified hostname will be simplified
           in regards to the character set used before the latter are updated. This is done by
           replacing spaces with "-" and removing special characters. This ensures that the pretty
           and the static hostname are always closely related while still following the validity
           rules of the specific name. This simplification of the hostname string is not done if only
           the transient and/or static host names are set, and the pretty host name is left
           untouched.

           Pass the empty string "" as the hostname to reset the selected hostnames to their default
           (usually "localhost").v

man--hostnamectl

方法:1

修改/etc/hostname文件设置主机名

vi /etc/hostname
[root@localhost Desktop]# vi /etc/hostname
PERMA.com
~                                                                                                                                                                                                                  
~                                                                                                                                                                                                                  
~                                                                                                                                                                                                                                                                                                         
~                                                                                                                                                                                                                  
~                                                                                                                                                                                                                  
~                                                                                                                                                                                                                  
:wq
[root@localhost Desktop]# hostname
PERMA.com
[root@localhost Desktop]# bash
[root@PERMA Desktop]#
  • 截图

方法:2

  • 执行hostnamectl命令

  • 使用hostnamectl命令

hostnamectl set-hostname name
  • 再通过hostname或者hostnamectl status命令查看更改是否生效。
hostname
hostnamectl

实验过程

[root@localhost ~]# hostnamectl set-hostname jason
[root@localhost ~]# hostname
jason
[root@localhost ~]# hostnamectl status
   Static hostname: jason
         Icon name: computer-vm
           Chassis: vm
        Machine ID: a42ac6777ec748f0b06e7e547d738304
           Boot ID: 9fe0db599d7c45e38b8660633e35091e
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
[root@localhost ~]#

方法:3

执行nmtui命令

进入NetworkManager TUI主界面


选择设置主机名


输入主机名

按ok退出
确定并退出
[root@PERMA Desktop]# hostname
bourn
[root@PERMA Desktop]# bash
[root@bourn Desktop]#

方法:4

man--nmcli

执行nmcli命令

查看主机名

nmcli general hostname

设置主机名

nmcli general hostname my-server

执行systemctl restart systemd-hostnamed使修改生效


systemctl restart systemd-hostnamed

设置tcp/ip信息

[root@jason Desktop]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=18a130f9-c170-4d78-a03a-57761761a369
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.1.123

~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                                                                                                                         
~                                                                                                                                           
"/etc/sysconfig/network-scripts/ifcfg-eno16777736" 18L, 312C
[root@jason Desktop]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=18a130f9-c170-4d78-a03a-57761761a369
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.1.123

~                                                                                                                                           
~                                                                                                                                                                                                                                                                                    
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
"/etc/sysconfig/network-scripts/ifcfg-eno16777736" 18L, 310C
  • 截图

)


results matching ""

    No results matching ""