1. 程式人生 > 實用技巧 >Centos 7修改防火牆、時間與網路時間同步、解壓zip包、修改系統時間

Centos 7修改防火牆、時間與網路時間同步、解壓zip包、修改系統時間

一、防火牆的開啟、關閉、禁用命令

(1)設定開機啟用防火牆:systemctl enable firewalld.service 使用此命令需要重啟後才會生效。

(2)設定開機禁用防火牆:systemctl disable firewalld.service使用此命令需要重啟後才會生效。

(3)啟動防火牆:systemctl start firewalld

(4)關閉防火牆:systemctl stop firewalld

(5)檢查防火牆狀態:systemctl status firewalld

二.時間與網路時間同步

(1)安裝ntpdate工具

[root@slave1 ~]# yum -y install ntp ntpdate

安裝成功!

(2)設定系統時間與網路時間同步

[root@slave1 ~]# ntpdate0.asia.pool.ntp.org

這裡主要就是通過時間伺服器對系統時間進行同步,所以0.asia.pool.ntp.org並不是固定的,大家可以選擇time.nist.gov、time.nuri.net、0.asia.pool.ntp.org、1.asia.pool.ntp.org、2.asia.pool.ntp.org、3.asia.pool.ntp.org中任意一個,只要保證可用就OK。

執行完畢後使用 # date 檢視時間是否同步成功

(3)將系統時間寫入硬體時間

[root@slave1 ~]# hwclock --systohc

這裡是為了防止系統重啟後時間被還原,因此需要寫到硬體裝置中去.

三.解壓zip包

(1)安裝支援ZIP的工具 yum install -y unzip zip

(2)解壓zip檔案 unzip 檔名.zip

例如:壓縮一個zip檔案

 zip 檔名.zip 資料夾名稱或檔名稱

四.修改系統時間

(1)檢視當前的系統時間:

[root@bogon vagrant]# date
Tue Jun 25 12:12:23 UTC 2019

(2) 檢視當前時區

[vagrant@bogon ~]$ timedatectl status
Local time: Tue 2019-06-25 20:29:47 CST

Universal time: Tue 2019-06-25 12:29:47 UTC
RTC time: Tue 2019-06-25 12:29:50
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: n/a

Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.

(3)修改時間

[root@bogon vagrant]# date -s "2019-06-25 20:13:00"
Tue Jun 25 20:13:00 UTC 2019

(4)修改時區為上海

[root@bogon vagrant]# timedatectl set-timezone Asia/Shanghai

(5) 檢視硬體時間

[root@bogon vagrant]# hwclock --show
Tue 25 Jun 2019 08:13:56 PM CST -0.891529 seconds

(6) 同步系統時間和硬體時間

[root@bogon vagrant]# hwclock --hctosys

(7) 本地時間寫入硬體時間

[root@bogon vagrant]# timedatectl set-local-rtc 1
[root@bogon vagrant]# date
Tue Jun 25 20:14:35 CST 2019

(8)重啟系統 [root@bogon vagrant]# reboot