2016.7.6作业


2016.7.5作业


修改默认启动级别

方法1:使用软连接实现

man--ln(1p)
man--ln

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

systemctl status

Table 18.2 Systemd Status Overview

Status Description
Loaded The unit file has been processed and the unit is active.
Active(running) Running with one or more active processes.
Active(exited) Successfully completed a one-time configuration.
Active(waiting) Running and waiting for an event.
Inactive Not running.
Enabled Will be started at boot time.
Disabled Will not be started at boot time.
Static This unit can not be enabled but may be started by another unit automatically.


Table 18.3 Systemctl Unit Overview Commands

Command Description
systemctl --type=service Shows only service units
systemctl list-units --type=service Shows all active service units (same result as the previous command)
systemctl list-units --type=service --all Shows inactive service units as well as active service units
systemctl --failed --type=service Shows all services that have failed
systemctl status -l your.service Shows detailed status information about services

Isolating Targets

As already discussed, on systemd machines there are a couple of targets. You also
know that a target is a collection of units. Some of those targets have a special role
because they can be isolated. By isolating a target, you start that target with all of its
dependencies. Not all targets can be isolated, but only targets that have the isolate
option enabled. We’ll explore the systemctl isolate command in a while. Before
doing that, let’s take a look at the default targets on your computer.

To get a list of all targets currently loaded, type systemctl --type=target . You’ll see
a list of all the targets currently active. If your server is running a graphical environ-
ment, this will include all the dependencies required to install the graphical.target
also. However, this list does not show all the targets, but only the active targets.
Type systemctl --type=target --all for an overview of all targets that exist on your
computer. You’ll now see inactive targets also.

Of the targets on your system, a few have an important role because they can be
started (isolated) to determine the state your server starts in. These are also the tar-
gets that can be set as the default target. These targets also roughly correspond to
run levels as they were used on earlier versions of RHEL. These are the following
targets:

■ poweroff.target - runlevel 0
■ rescue.target - runlevel 1
■ multi-user.target - runlevel 3
■ graphical.target - runlevel 5
■ reboot.target - runlevel 6

If you look at the contents of each of these targets, you’ll also see that they contain
the AllowIsolate=yes line. That means that you can switch the current state of your
computer to either one of these targets using the systemctl isolate command. Exer-
cise 18.2 shows you how to do this.

切换运行级别

方法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 ""