新聞中心
Centos7新功能
Centos7 單用戶模式

centos7里不再有0-6啟動級別,而是4個target
graphical.target 多人模式,支持圖形和命令行兩種登錄,對應(yīng)之前的3,5級別
multi-user.target 多人模式,只支持命令行登錄,對應(yīng)之前的3級別
rescue.target 單人模式,對應(yīng)之前的1級別
emergency.target 單人模式,不過系統(tǒng)進入后根目錄是只讀的
centos7采用的是grub2,和之前的方式有所不同
在對應(yīng)的內(nèi)核條目上,按下"e",會進入edit模式,搜尋ro那一行,以linux16開頭的,按“end”鍵到最后,輸入rd.break,再按ctrl+x進入
進去后重新掛載 /sysroot/,增加寫權(quán)限
mount -o remount,rw /sysroot/
切換到原始系統(tǒng)下
chroot /sysroot/
passwd
修改密碼輸入新密碼
touch /.autorelabel //這句是為了selinux生效
退出單用戶的方法是
先ctrl+d 退出,然后reboot
1.3 centos7救援模式
設(shè)置光驅(qū)啟動
選擇Troubleshooting
選擇Rescure a centos system
選擇continue
chroot /mnt/sysimage
passwd
1.4 設(shè)置IP
網(wǎng)卡名字不再是eth0、eth2
dhclient先自動獲取ip
沒有 ifconfig命令,要使用 ip add 查看ip
要想繼續(xù)使用 ifconfig,需要安裝 net-tools
yum install -y net-tools
編輯配置文件
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
里面配置和centos6一樣
1.5 設(shè)置主機名 && 設(shè)置命令自動補全
hostname 查看主機名
hostnamectl set-hostname test1
hostnamectl status //查看主機名狀態(tài)
cat /etc/hostname //查看配置文件
centos7支持命令參數(shù)補全
安裝 bash-completion
yum install -y bash-completion
source /etc/profile
1.6 centos7服務(wù)相關(guān)
centos7 不再有chkconfig工具了,而是使用systemd
使某服務(wù)自啟動 systemctl enable httpd.service
不自啟動 systemctl disable httpd.service
查看服務(wù)狀態(tài) systemctl status httpd.service
查看所有服務(wù) systemctl list-units --type=service
啟動服務(wù) systemctl start httpd.service
停止服務(wù) systemctl stop httpd.service
重啟服務(wù) systemctl restart httpd.service
啟動腳本路徑 /usr/lib/systemd/system/
檢查一個服務(wù)是否為開機啟動 systemctl is-enabled httpd
1.7 centos7 systemd-unit
systemd管理服務(wù)的機制的特點:
支持服務(wù)并列啟動,不用順序啟動,從而開機時間縮短
支持自動檢測服務(wù)依賴的服務(wù)
Systemd 可以管理所有系統(tǒng)資源。不同的資源統(tǒng)稱為 Unit(單位)。
Unit 一共分成12種類型
Service unit:系統(tǒng)服務(wù) Target unit:多個 Unit 構(gòu)成的一個組
Device Unit:硬件設(shè)備 Mount Unit:文件系統(tǒng)的掛載點
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 是否處于啟動失敗狀態(tài)
systemctl is-failed application.service
顯示某個 Unit 服務(wù)是否建立了啟動鏈接
systemctl is-enabled application.service
1.8 centos7 systemd-target
target類似于centos6里面的啟動級別,但target支持多個target同時啟動。target其實是多個unit的組合,系統(tǒng)啟動說白了就是啟動多個unit,為了管理方便,就使用target來管理這些unit。
查看當(dāng)前系統(tǒng)的所有 Target
systemctl list-unit-files --type=target
查看一個 Target 包含的所有 Unit
systemctl list-dependencies multi-user.target
查看啟動時的默認 Target systemctl get-default
設(shè)置啟動時的默認 Target systemctl set-default multi-user.target
切換 Target 時,默認不關(guān)閉前一個 Target 啟動的進程,
systemctl isolate 命令改變這種行為,關(guān)閉前一個 Target 里面所有不屬于后一個 Target 的進程
systemctl isolate multi-user.target
1.9 centos7 target關(guān)聯(lián)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 繼續(xù)使用centos6的iptables管理機制
centos7不再使用iptables,而是使用firewalld
若不想使用firewalld,繼續(xù)使用iptables,可以停掉firewalld,并且安裝iptables-services包
systemctl stop firewalld
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables
firewalld 的使用
centos6上使用的靜態(tài)防火墻,規(guī)則保存在/etc/sysconfig/iptalbes, 更新規(guī)則,需要重新加載或者重啟iptables服務(wù),相當(dāng)于是把之前的規(guī)則全部清空,再把配置文件里面的規(guī)則加載。
而centos7使用了動態(tài)防火墻,即firewalld,這種防火墻方案不再像之前,更改了規(guī)則不需要重新加載配置。
無論是firewalld還是之前的iptables服務(wù),底層都是使用iptables工具來配置規(guī)則的。
fiewalld有zone和service的概念
每一個zone里面的iptables規(guī)則不一樣,默認有9個zone。
centos7的默認zone是public
使用命令 firewall-cmd --get-zones 獲取所有的zone
使用命令 firewall-cmd --get-default-zone 獲取默認的zone
2.1 centos7 firewalld的zone
drop(丟棄) 任何接收的網(wǎng)絡(luò)數(shù)據(jù)包都被丟棄,沒有任何回復(fù)。僅能有發(fā)送出去的網(wǎng)絡(luò)連接。
block(限制)任何接收的網(wǎng)絡(luò)連接都被 IPv4 的 icmp-host-prohibited 信息和 IPv6 的 icmp6-adm-prohibited 信息所拒絕。
public(公共)在公共區(qū)域內(nèi)使用,不能相信網(wǎng)絡(luò)內(nèi)的其他計算機不會對您的計算機造成危害,只能接收經(jīng)過選取的連接。
external(外部)特別是為路由器啟用了偽裝功能的外部網(wǎng)。您不能信任來自網(wǎng)絡(luò)的其他計算,不能相信它們不會對您的計算機造成危害,只能接收經(jīng)過選擇的連接。
dmz(非軍事區(qū))用于您的非軍事區(qū)內(nèi)的電腦,此區(qū)域內(nèi)可公開訪問,可以有限地進入您的內(nèi)部網(wǎng)絡(luò),僅僅接收經(jīng)過選擇的連接。
work(工作)用于工作區(qū)。您可以基本相信網(wǎng)絡(luò)內(nèi)的其他電腦不會危害您的電腦。僅僅接收經(jīng)過選擇的連接。
home(家庭)用于家庭網(wǎng)絡(luò)。您可以基本信任網(wǎng)絡(luò)內(nèi)的其他計算機不會危害您的計算機。僅僅接收經(jīng)過選擇的連接。
internal(內(nèi)部) 用于內(nèi)部網(wǎng)絡(luò)。您可以基本上信任網(wǎng)絡(luò)內(nèi)的其他計算機不會威脅您的計算機。僅僅接受經(jīng)過選擇的連接。
trusted(信任)可接受所有的網(wǎng)絡(luò)連接。
指定其中一個區(qū)域為默認區(qū)域是可行的。當(dāng)接口連接加入了 NetworkManager,它們就被分配為默認區(qū)域。安裝時,firewalld 里的默認區(qū)域被設(shè)定為公共區(qū)>域。
2.2 centos7 firewalld的zone相關(guān)命令
設(shè)置默認的zone firewalld-cmd --set-default-zone=work
查看指定網(wǎng)卡所在的zone
firewall-cmd --get-zone-of-interface=eno16777736
給指定的網(wǎng)卡設(shè)置zone firewall-cmd --zone=public --add-interface=lo
針對網(wǎng)卡更改zone firewall-cmd --zone=dmz --change-interface=lo
也可以針對網(wǎng)卡刪除zone
firewall-cmd --zone=dmz --remove-interface=lo
查看所有網(wǎng)卡所在的zone firewall-cmd --get-active-zones
2.3 centos7 firewalld service操作
在 /usr/lib/firewalld/services/ 目錄中,還保存了另外一類配置文件,每個文件對應(yīng)一項具體的網(wǎng)絡(luò)服務(wù),如 ssh 服務(wù)等
與之對應(yīng)的配置文件中記錄了各項服務(wù)所使用的 tcp/udp 端口,在最新版本的 firewalld 中默認已經(jīng)定義了 70+ 種服務(wù)供我們使用
zone就是調(diào)用了不同的service而實現(xiàn)了不同的效果
列出所有的service: firewall-cmd --get-services
列出當(dāng)前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 增加規(guī)則
假設(shè)自定義的 ssh 端口號為 12222,使用下面的命令來添加新端口的防火墻規(guī)則
firewall-cmd --add-port=12222/tcp --permanent
如果需要使規(guī)則保存到 zone 配置文件,則需要加參數(shù) --permanent
防火墻配置文件也可以手動修改,修改后記得重載,重新加載的命令是
firewall-cmd --reload 這種情況下重新加載防火墻并不會中斷用戶連接,也可以徹底加載,這時候會中斷用戶連接,也會丟棄狀態(tài)信息
firewall-cmd --complete-reload
還可以添加一個端口范圍
firewall-cmd --add-port=2000-4000/tcp
針對某個zone添加端口
firewall-cmd --permanent --zone=home --add-port=443/tcp
啟用端口轉(zhuǎn)發(fā),例如把22端口轉(zhuǎn)發(fā)到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
系統(tǒng)使用的是/etc/firewalld下面的配置文件
在/etc/firewalld/zones下面只有一個public.xml,如果給另外一個zone做一些改動,并永久保存,那么會自動生成對應(yīng)的配置文件
比如,給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,所以要編輯這個,增加一行
firewall-cmd --reload //重新加載
網(wǎng)頁名稱:Centos7新功能-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://www.dlmjj.cn/article/dgdpcs.html


咨詢
建站咨詢
