Centos7新功能

Centos7 單用戶模式
 
centos7裏再也不有0-6啓動級別,而是4個target
 
graphical.target  多人模式,支持圖形和命令行兩種登陸,對應以前的3,5級別
 
multi-user.target  多人模式,只支持命令行登陸,對應以前的3級別
 
rescue.target   單人模式,對應以前的1級別
 
emergency.target 單人模式,不過系統進入後根目錄是隻讀的
 
 
centos7採用的是grub2,和以前的方式有所不一樣
 
在對應的內核條目上,按下"e",會進入edit模式,搜尋ro那一行,以linux16開頭的,按「end」鍵到最後,輸入rd.break,再按ctrl+x進入
 
進去後從新掛載 /sysroot/,增長寫權限
 
mount -o remount,rw /sysroot/
 
切換到原始系統下
 
chroot /sysroot/
 
passwd
修改密碼輸入新密碼
 
touch /.autorelabel    //這句是爲了selinux生效
 
退出單用戶的方法是
 
先ctrl+d 退出,而後reboot
 
 
 
1.3 centos7救援模式
 
設置光驅啓動
選擇Troubleshooting
選擇Rescure a centos system
選擇continue
chroot /mnt/sysimage
passwd
 
1.4 設置IP
 
網卡名字再也不是eth0、eth1
dhclient先自動獲取ip
沒有 ifconfig命令,要使用 ip add 查看ip
要想繼續使用 ifconfig,須要安裝 net-tools
yum install -y net-tools
編輯配置文件
vi  /etc/sysconfig/network-scripts/ifcfg-eno16777736
裏面配置和centos6同樣
 
 
1.5  設置主機名 && 設置命令自動補全
 
hostname 查看主機名
hostnamectl set-hostname  test1
hostnamectl status //查看主機名狀態
cat /etc/hostname //查看配置文件
centos7支持命令參數補全
安裝 bash-completion
yum install -y bash-completion
source /etc/profile
 
1.6 centos7服務相關
 
centos7 再也不有chkconfig工具了,而是使用systemd
使某服務自啓動 systemctl enable httpd.service
不自啓動 systemctl disable httpd.service
查看服務狀態 systemctl status httpd.service
查看全部服務 systemctl list-units --type=service
啓動服務  systemctl start httpd.service
中止服務 systemctl stop httpd.service
重啓服務 systemctl restart httpd.service
啓動腳本路徑 /usr/lib/systemd/system/
檢查一個服務是否爲開機啓動  systemctl is-enabled httpd
 
 
1.7 centos7 systemd-unit
 
systemd管理服務的機制的特色:
支持服務並列啓動,不用順序啓動,從而開機時間縮短
支持自動檢測服務依賴的服務
Systemd 能夠管理全部系統資源。不一樣的資源統稱爲 Unit(單位)。
Unit 一共分紅12種類型
Service unit:系統服務   Target unit:多個 Unit 構成的一個組
Device Unit:硬件設備  Mount Unit:文件系統的掛載點
Automount Unit:自動掛載點  Path Unit:文件或路徑
Scope Unit:不是由 Systemd 啓動的外部進程
Slice Unit:進程組  Snapshot Unit:Systemd 快照,能夠切回某個快照
Socket Unit:進程間通訊的 socket  Swap Unit:swap 文件
Timer Unit:定時器
 
列出正在運行的 Unit   systemctl list-units
列出全部Unit,包括沒有找到配置文件的或者啓動失敗的
systemctl list-units --all
列出全部沒有運行的 Unit   systemctl list-units --all --state=inactive
列出全部加載失敗的 Unit   systemctl list-units --failed
列出全部正在運行的、類型爲 service 的 Unit
systemctl list-units --type=service
顯示某個 Unit 是否正在運行  systemctl is-active application.service
顯示某個 Unit 是否處於啓動失敗狀態
systemctl is-failed application.service
顯示某個 Unit 服務是否創建了啓動連接
systemctl is-enabled application.service
 
 
1.8 centos7 systemd-target
 
target相似於centos6裏面的啓動級別,但target支持多個target同時啓動。target實際上是多個unit的組合,系統啓動說白了就是啓動多個unit,爲了管理方便,就使用target來管理這些unit。
查看當前系統的全部 Target
systemctl list-unit-files --type=target
查看一個 Target 包含的全部 Unit
systemctl list-dependencies multi-user.target
查看啓動時的默認 Target  systemctl get-default
設置啓動時的默認 Target  systemctl set-default multi-user.target
切換 Target 時,默認不關閉前一個 Target 啓動的進程,
systemctl isolate 命令改變這種行爲,關閉前一個 Target 裏面全部不屬於後一個 Target 的進程
systemctl isolate multi-user.target
 
1.9 centos7 target關聯unit
 
主配置文件 /etc/systemd/system.conf
開機會先加載/etc/systemd/system/default.target
全部的service和target在 /usr/lib/systemd/system/
ls -l /etc/systemd/system/defaut.target 是一個軟鏈接
軟鏈接到了/usr/lib/systemd/system/multi-user.target
它會加載/usr/lib/systemd/system/multi-user.target.wants下面的service
查看一個service屬於哪一個target,須要cat 具體的service文件
cat /usr/lib/systemd/system/sshd.service
看裏面[install]部分
 
 
2.0 centos7 繼續使用centos6的iptables管理機制
 
centos7再也不使用iptables,而是使用firewalld
若不想使用firewalld,繼續使用iptables,能夠停掉firewalld,而且安裝iptables-services包
systemctl stop firewalld
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables
 
 
firewalld 的使用
 
centos6上使用的靜態防火牆,規則保存在/etc/sysconfig/iptalbes, 更新規則,須要從新加載或者重啓iptables服務,至關因而把以前的規則所有清空,再把配置文件裏面的規則加載。
而centos7使用了動態防火牆,即firewalld,這種防火牆方案再也不像以前,更改了規則不須要從新加載配置。
不管是firewalld仍是以前的iptables服務,底層都是使用iptables工具來配置規則的。
fiewalld有zone和service的概念
每個zone裏面的iptables規則不同,默認有9個zone。
centos7的默認zone是public
使用命令  firewall-cmd --get-zones 獲取全部的zone
使用命令  firewall-cmd --get-default-zone  獲取默認的zone
 
2.1 centos7 firewalld的zone
 
drop(丟棄) 任何接收的網絡數據包都被丟棄,沒有任何回覆。僅能有發送出去的網絡鏈接。
block(限制)任何接收的網絡鏈接都被 IPv4 的 icmp-host-prohibited 信息和 IPv6 的 icmp6-adm-prohibited 信息所拒絕。
public(公共)在公共區域內使用,不能相信網絡內的其餘計算機不會對您的計算機形成危害,只能接收通過選取的鏈接。
external(外部)特別是爲路由器啓用了假裝功能的外部網。您不能信任來自網絡的其餘計算,不能相信它們不會對您的計算機形成危害,只能接收通過選擇的鏈接。
dmz(非軍事區)用於您的非軍事區內的電腦,此區域內可公開訪問,能夠有限地進入您的內部網絡,僅僅接收通過選擇的鏈接。
work(工做)用於工做區。您能夠基本相信網絡內的其餘電腦不會危害您的電腦。僅僅接收通過選擇的鏈接。
home(家庭)用於家庭網絡。您能夠基本信任網絡內的其餘計算機不會危害您的計算機。僅僅接收通過選擇的鏈接。
internal(內部) 用於內部網絡。您能夠基本上信任網絡內的其餘計算機不會威脅您的計算機。僅僅接受通過選擇的鏈接。
trusted(信任)可接受全部的網絡鏈接。
指定其中一個區域爲默認區域是可行的。當接口鏈接加入了 NetworkManager,它們就被分配爲默認區域。安裝時,firewalld 裏的默認區域被設定爲公共區>域。
 
2.2 centos7 firewalld的zone相關命令
 
設置默認的zone  firewalld-cmd --set-default-zone=work
查看指定網卡所在的zone
firewall-cmd --get-zone-of-interface=eno16777736
給指定的網卡設置zone  firewall-cmd --zone=public --add-interface=lo
針對網卡更改zone  firewall-cmd --zone=dmz --change-interface=lo
也能夠針對網卡刪除zone
firewall-cmd --zone=dmz  --remove-interface=lo
查看全部網卡所在的zone  firewall-cmd --get-active-zones
 
 
2.3 centos7 firewalld service操做
 
在 /usr/lib/firewalld/services/ 目錄中,還保存了另一類配置文件,每一個文件對應一項具體的網絡服務,如 ssh 服務等
與之對應的配置文件中記錄了各項服務所使用的 tcp/udp 端口,在最新版本的 firewalld 中默認已經定義了 70+ 種服務供咱們使用
zone就是調用了不一樣的service而實現了不一樣的效果
列出全部的service: firewall-cmd --get-services
列出當前zone下加載的service:  firewall-cmd --list-services
查看某個zone下面的service:firewall-cmd --zone=public --list-services
給一個zone下面添加一個service:
firewall-cmd --zone=public --add-service=http
這個改動不會保存到配置文件裏,要想保存到配置文件中,須要加上--permanent
firewall-cmd --zone=public --add-service=http  –-permanent
既然能夠增長,一樣也能夠刪除
firewall-cmd --zone=public --remove-service=http --permanent
 
2.4 centos7 firewalld 增長規則
 
假設自定義的 ssh 端口號爲 12222,使用下面的命令來添加新端口的防火牆規則
firewall-cmd --add-port=12222/tcp --permanent
若是須要使規則保存到 zone 配置文件,則須要加參數 --permanent
防火牆配置文件也能夠手動修改,修改後記得重載,從新加載的命令是
firewall-cmd --reload  這種狀況下從新加載防火牆並不會中斷用戶鏈接,也能夠完全加載,這時候會中斷用戶鏈接,也會丟棄狀態信息
firewall-cmd --complete-reload
還能夠添加一個端口範圍
firewall-cmd --add-port=2000-4000/tcp
針對某個zone添加端口
firewall-cmd --permanent --zone=home --add-port=443/tcp
啓用端口轉發,例如把22端口轉發到127.0.0.2
firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2
 
 
 
2.5 centos7 firewalld 更改配置文件
 
兩個路徑/etc/firewalld/和/usr/lib/firewalld
系統使用的是/etc/firewalld下面的配置文件
在/etc/firewalld/zones下面只有一個public.xml,若是給另一個zone作一些改動,並永久保存,那麼會自動生成對應的配置文件
好比,給work zone增長一個端口
firewall-cmd --permanent --zone=work --add-port=1000/tcp
此時就會生成一個work.xml配置文件
需求: 修改ftp的端口,默認ftp端口是21,須要改成1121
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/
vi /etc/firewalld/services/ftp.xml   //把21改成1121
vi /etc/firewalld/zones/work.xml  //work爲默認zone,因此要編輯這個,增長一行 <service name="ftp"/>
firewall-cmd --reload  //從新加載
相關文章
相關標籤/搜索