centos7新系統安裝


一  Centos7開機啟動技術改變

1.1 從Sysvinit技術到Systemd技術
Sysvinit
優點

    Sysvinit運行良好,概念簡單清晰。依賴於shell腳本
缺點: 

    1.並行啟動,開機慢,

    2.容易夯住(如webServer 掛載(/etc/inittab文件下) nfsServer(未啟動),時,webServer會夯住。(如果寫入到/etc/rc.local中,則超時后,退出腳本))
Upstart
過渡技術


Systemd
優點:並行啟動,快


三種啟動技術對比
1.2 並行啟動原理
1.2.1 解決socket 依賴/端口依賴
系統提前創建端口,由systemd系統管家管理(個人理解),服務正常運行至開機啟動后
1.2.2 解決D-Bus
依賴:采用D-Bus作為進程間的通信工具,類似消息隊列,可以緩存信息
6:同步=面對面把事情交代清楚,安全性,穩定性好,速度慢
7:異步=把事情寫在紙上,安全性低,速度快
1.2.3 解決文件系統依賴
autofs機制,需要時掛載

二 網卡名稱
2.1 系統識別硬件的方式
7:通過網卡插槽指定網卡名稱
6:通過識別硬件獲得網卡名稱(且每獲取一次都不同)
注意:如果通過刪除vm 軟件刪除網絡適配置器。可能導致網卡插槽也會被刪除!!
2.2 開機后修改網卡名稱:
1. 進入到網卡配置文件目錄下

1 cd /etc/sysconfig/network-scripts/ && systemctl stop NetworkManager && systemctl disable NetworkManager

2.修改網卡名稱

1 mv ifcfg-ens33 ifcfg-eth0 #我的網卡原名稱為ens33

3.修改網卡設備及名稱

1 TYPE=Ethernet
2 …………
3 NAME=eth0 #原為ense33 已改成eth0
4 DEVICE=eth0 #原為ense33 已改成eth0
5 ONBOOT=yes
6 IPADDR=10.0.0.200
7 PREFIX=24
8 GATEWAY=10.0.0.254
9 DNS1=223.5.5.5

 

4.修改grub配置文件

/etc/default/grub

1 GRUB_TIMEOUT=5
2 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
3 GRUB_DEFAULT=saved
4 GRUB_DISABLE_SUBMENU=true
5 GRUB_TERMINAL_OUTPUT="console"
6 GRUB_CMDLINE_LINUX="rhgb net.ifnames=0 biosdevname=0 quiet" #net.ifnames=0 biosdevname=0 為新增內容,其他不做修改 7 GRUB_DISABLE_RECOVERY="true"

 


5.生成grub配置文件,命令

1 grub2-mkconfig -o /boot/grub2/grub.cfg #執行命令
2 Generating grub configuration file ... #以下為命令執行結果
3 Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
4 Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
5 Found linux image: /boot/vmlinuz-0-rescue-6fb9d1e602e84f5eacbc9ea411c00d80
6 Found initrd image: /boot/initramfs-0-rescue-6fb9d1e602e84f5eacbc9ea411c00d80.img
7 done

 

6.重啟,查看

1 reboot 
2 ip a s eth0
3 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 #可以直接查看網卡信息
4 link/ether 00:0c:29:49:5d:cb brd ff:ff:ff:ff:ff:ff
5 inet 10.0.0.200/24 brd 10.0.0.255 scope global eth0
6 valid_lft forever preferred_lft forever
7 inet6 fe80::20c:29ff:fe49:5dcb/64 scope link 
8 valid_lft forever preferred_lft forever

 

2.3 安裝系統時修改網絡配置項

1 ####
2 ####安裝系統時修改網卡名稱為eth0的方法!! 安裝系統時修改網卡名稱為eth0的方法!! 安裝系統時修改網卡名稱為eth0的方法 !!
3. ### 按tab鍵后 添加如下內容 net.ifnames=0 biosdeveth0=0
3 ####

 

第3章 文件系統
7:默認為xfs 專為大數據,大文件設計
6:默認為ext4
7在安裝是/boot分區選擇1G,7的/boot分區需要更大
第4章 yum源優化
4.1 添加epel源

1 curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

4.2 更新其他軟件

 

yum install -y vim wget bash-completion tree lrzsz nmap nc htop pssh sshpass net-tools setuptool 
#shell快捷幫助 #其他常用軟件 

 

 


五、 網絡命令
7主推:ip ss
5.1 安裝6系統的命令包

1 ifconfig 
2 yum install -y net-tools
3 setup 
4 yum install -y setuptool #廢棄命令 nmtui代替 所以,我沒有安裝以上這些命令


5.2 主機名修改
6中主機名位置為 /etc/sysconfig/network (當時就覺得,怪異)
7中主機名位置為 /etc/hostname (這我就喜歡了)
7中修改主機名稱方式與6中相同 (不做贅述)
7與6不同的地方

 1 1.    [root@centos7 ~]# hostnamectl set-hostname centos8 #修改主機名稱, 
 2 2.    [root@centos7 ~]# logout
 3 3.    Connection closing...Socket close.
 4 4.    
 5 5.    Connection closed by foreign host.
 6 6.    
 7 7.    Disconnected from remote host(10.0.0.200:22) at 15:27:15.
 8 8.    
 9 9.    Type `help' to learn how to use Xshell prompt.
10 10.    [c:\~]$ ssh 10.0.0.200
11 11.    
12 12.    
13 13.    Connecting to 10.0.0.200:22...
14 14.    Connection established.
15 15.    To escape to local shell, press 'Ctrl+Alt+]'.
16 16.    
17 17.    Last login: Mon Nov 13 00:26:02 2017 from 10.0.0.1
18 18.    [root@centos8 ~]# hostname
19 19.    centos8
20 20.    [root@centos8 ~]# cat /etc/hostname #配置文件也被修改了
21 21.    centos8
22 22.    友情提示:hostnamectl 會將所有字母轉換為小寫。

 


六、兼容/etc/rc.local

1 1.    # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
2 2.    # that this script will be executed during boot.
3 3.    
4 4.    touch /var/lock/subsys/local

 


5. 不過在最新的系統中,官方好像還是沒有給到軟鏈接原文件的執行權限。(官方,你好 :)

 

1 [root@CentOS7 ~]# ll /etc/rc.local 
2 lrwxrwxrwx. 1 root root 13 Nov 13 11:17 /etc/rc.local -> rc.d/rc.local
3 [root@CentOS7 ~]# ll /etc/rc.d/rc.local 
4 -rw-r--r--. 1 root root 473 Aug  5 14:38 /etc/rc.d/rc.local

 

 

 

3. #注意,官方還說,不建議使用shell腳本管理系統的服務 (。。。。。。)

七 行級別Runlevel

 1 6中運行級別文件在 /etc/inittab文件中
 2 7中運行級別文件是一個軟鏈接
 3 1.    [root@centos7 system]# ll runlevel*.target #下面的軟鏈接,是各種啟動方式的軟鏈接
 4 2.    lrwxrwxrwx. 1 root root 15 Nov 12 06:30 runlevel0.target -> poweroff.target
 5 3.    lrwxrwxrwx. 1 root root 13 Nov 12 06:30 runlevel1.target -> rescue.target
 6 4.    lrwxrwxrwx. 1 root root 17 Nov 12 06:30 runlevel2.target -> multi-user.target
 7 5.    lrwxrwxrwx. 1 root root 17 Nov 12 06:30 runlevel3.target -> multi-user.target
 8 6.    lrwxrwxrwx. 1 root root 17 Nov 12 06:30 runlevel4.target -> multi-user.target
 9 7.    lrwxrwxrwx. 1 root root 16 Nov 12 06:30 runlevel5.target -> graphical.target
10 8.    lrwxrwxrwx. 1 root root 13 Nov 12 06:30 runlevel6.target -> reboot.target
11 9.    [root@centos7 system]# ll default.target #這個default是一個軟鏈接,它指向上面那個文件,就會以那種方式啟動
12 10.    lrwxrwxrwx. 1 root root 16 Nov 12 06:30 default.target -> graphical.target
13 1.    [root@centos7 system]# systemctl get-default #顯示系統配置文件中的運行級別
14 2.    poweroff.target
15 3.    [root@centos7 system]# systemctl set-default runlevel3.target #指定配置文件運行級別
16 4.    Removed symlink /etc/systemd/system/default.target.
17 5.    Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
18 6.    [root@centos7 system]# systemctl get-default #獲取配置文件運行級別
19 7.    multi-user.target

 


八 ystemd一統天下
所有可用的單元文件存放在/usr/lib/systemd/system/ 和 /etc/systemd/system/ 目錄中(后者優先級更高)
注意:目錄真長,多記,多練
Systemd命令
添加圖片
九 啟動時間優化

 1 1.    [root@centos7 system]# systemd-analyze 
 2 2.    Startup finished in 420ms (kernel)(內核加載時間) + 1.463s (initrd) (初始化進程時間) + 3.953s (userspace) (用戶加載進程)= 5.837s
 3 1.    [root@centos7 system]# systemd-analyze blame #顯示每個程序加載消耗時間
 4 2.    811ms firewalld.service
 5 3.    767ms dev-sda2.device
 6 4.    547ms boot.mount
 7 5.    445ms postfix.service
 8 6.    397ms NetworkManager-wait-online.service
 9 7.    247ms abrt-ccpp.service
10 8.    194ms network.service
11 9.    .......
12 1.    [root@centos7 ~]# systemd-analyze plot >boottime.svg #將開機時間生成svg文件,在瀏覽器中打開,如下圖
13 2.    [root@centos7 ~]# sz boottime.svg
14 
15 
16 在第2s后,系統開始並行啟動大部分程序

 

拾 關閉系統服務

 1 1.    關閉防火牆
 2 1.    [root@centos7 ~]# systemctl status firewalld.service 
 3 2.    ● firewalld.service - firewalld - dynamic firewall daemon
 4 3.       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
 5 4.       Active: active (running) since Sun 2017-11-12 23:51:07 CST; 1h 43min ago
 6 5.         Docs: man:firewalld(1)
 7 6.     Main PID: 807 (firewalld)
 8 7.       CGroup: /system.slice/firewalld.service
 9 8.               └─807 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
10 9.    
11 10.    Nov 12 23:51:06 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
12 11.    Nov 12 23:51:07 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
13 12.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'beyond-scope' is not supported by the ke...pv6.
14 13.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP t...ime.
15 14.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'failed-policy' is not supported by the k...pv6.
16 15.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP ...ime.
17 16.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'reject-route' is not supported by the ke...pv6.
18 17.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP t...ime.
19 18.    Hint: Some lines were ellipsized, use -l to show in full.
20 19.    [root@centos7 ~]# systemctl is- firewalld.service 
21 20.    is-active is-enabled is-failed is-system-running 
22 21.    [root@centos7 ~]# systemctl is-enabled firewalld.service 
23 22.    enabled
24 23.    [root@centos7 ~]# systemctl is-active firewalld.service 
25 24.    active
26 25.    [root@centos7 ~]# systemctl is-failed firewalld.service 
27 26.    active
28 1.    [root@centos7 ~]# systemctl stop firewalld.service #關閉防火牆(7中默認是沒有使用iptables的,所以,可以yum install -y iptables.service)
29 2.    [root@centos7 ~]# systemctl sta firewalld.service 
30 3.    start status 
31 4.    [root@centos7 ~]# systemctl status firewalld.service 
32 5.    ● firewalld.service - firewalld - dynamic firewall daemon
33 6.       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
34 7.       Active: inactive (dead) since Mon 2017-11-13 01:40:19 CST; 9s ago
35 8.         Docs: man:firewalld(1)
36 9.     Main PID: 807 (code=exited, status=0/SUCCESS)
37 10.    
38 11.    Nov 12 23:51:06 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
39 12.    Nov 12 23:51:07 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
40 13.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'beyond-scope' is not supported by the ke...pv6.
41 14.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP t...ime.
42 15.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'failed-policy' is not supported by the k...pv6.
43 16.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP ...ime.
44 17.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: ICMP type 'reject-route' is not supported by the ke...pv6.
45 18.    Nov 12 23:51:08 localhost.localdomain firewalld[807]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP t...ime.
46 19.    Nov 13 01:40:19 centos7 systemd[1]: Stopping firewalld - dynamic firewall daemon...
47 20.    Nov 13 01:40:19 centos7 systemd[1]: Stopped firewalld - dynamic firewall daemon.
48 21.    Hint: Some lines were ellipsized, use -l to show in full.
49 1.    [root@centos7 ~]# systemctl disable firewalld.service  (開機不啟動防火牆)
50 2.    Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
51 3.    Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
52 4.    [root@centos7 ~]# poweroff 

 

  

2.關閉SELinux
同6
十一 systemd

  1 systemd提供更優秀的框架以表示系統服務間的依賴關系
  2 
  3 實現系統初始化時服務的並行啟動,同時達到降低Shell的系統開銷的效果
  4 
  5 systemd的目標是:盡可能啟動更少進程;盡可能將更多進程並行啟動。
  6 
  7 systemd盡可能減少對shell腳本的依賴。
  8 
  9 開機服務管理
 10 
 11 systemd添加新的unit(daemon)
 12 
 13 也就是采用systemd來管理,/sbin/chkconfig --add foo相當
 14 
 15 把新生成的foo.service 放到/usr/lib/systemd/system/下面,然后采用load命令導入
 16 
 17 systemctl load foo.service
 18 
 19 刪除unit(daemon)
 20 
 21 刪除一個unit沒有相應的命令,通常的做法是停掉daemon,然后刪除相應的配置文件。
 22 
 23 開機啟動unit
 24 
 25 systemctl enable postfix.service
 26 
 27 增加由/usr/lib/systemd/system/到/etc/systemd/system/multi-user.target.wants/下的軟鏈接
 28 
 29 ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'
 30 
 31 開機不啟動unit
 32 
 33 systemctl disable httpd.service
 34 
 35 刪除/etc/systemd/system/multi-user.target.wants下的軟鏈接
 36 
 37 查看開機是否啟動
 38 
 39 systemctl is-enabled .service #查詢服務是否開機啟動
 40 
 41 systemd查看開機自啟動的程序
 42 
 43 相當於chkconfig --list
 44 
 45 ls /etc/systemd/system/multi-user.target.wants/
 46 
 47 查看systemd單元加載及活動情況
 48 
 49 systemctl
 50 
 51  
 52 
 53 顯示啟動失敗的單元
 54 
 55 systemctl --failed
 56 
 57 查看systemd管理的所有單元
 58 
 59 systemctl list-unit-files
 60 
 61  
 62 
 63 服務管理
 64 
 65 =================================================
 66 
 67 啟動服務
 68 
 69 systemctl start httpd.service
 70 
 71 關閉服務
 72 
 73 systemctl stop httpd.service
 74 
 75 重啟服務
 76 
 77 systemctl restart httpd.service
 78 
 79 重新加載
 80 
 81 systemctl reload httpd.service
 82 
 83 查看狀態
 84 
 85 systemctl status httpd.service
 86 
 87 包括啟動狀態、啟動時間、主進程及相關進程、相關日志
 88 
 89  
 90 
 91 運行級別
 92 
 93 systemd用target替代了runlevel的概念,多個的 'target' 可以同時激活
 94 
 95 systemd不使用/etc/inittab,如何查看系統默認的運行級別
 96 
 97 ll /etc/systemd/system/default.target
 98 
 99 查看這個軟鏈接真正指向的文件
100 
101  
102 
103 如何查看系統的當前運行級別
104 
105 runlevel依然可用
106 
107 systemd的方法是:systemctl list-units --type=target
108 
109  
110 
111 改變當前target,重啟無效
112 
113 systemctl isolate graphical.target
114 
115  
116 
117 修改默認運行級別
118 
119 1.首先刪除已經存在的符號鏈接
120 
121 rm /etc/systemd/system/default.target
122 
123 2.默認級別轉換為3(文本模式)
124 
125 systemctl enable multi-user.target
126 
127 相當於ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
128 
129 3.重啟
130 
131 reboot
132 
133  
134 
135 運行級別如下:
136 
137 runlevel0.target -> poweroff.target
138 
139 runlevel1.target -> rescue.target
140 
141 runlevel2.target -> multi-user.target
142 
143 runlevel3.target -> multi-user.target
144 
145 runlevel4.target -> multi-user.target
146 
147 runlevel5.target -> graphical.target
148 
149 runlevel6.target -> reboot.target

 安裝常用工具

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y vim wget bash-completion tree lrzsz nmap nc htop pssh sshpass

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM