linux作業系統基本操作4
-
small stips
日誌的類別 後面日至的級別
.
debug日誌,服務量大,級別低,顯示資訊多
傳送端
一個艾特@代表udp協議
兩個@代表tcp協議
接收端
同意接收
防火牆關閉
改完配置檔案重其服務 -
系統的日誌管理
2.1 rsyslog的管理
/var/log/messages ##服務資訊日誌 /var/log/secure ##系統登入日誌 /var/log/cron ##定時任務日誌 /var/log/maillog ##郵件日誌 /var/log/boot.log ##系統啟動日誌 什麼型別的日誌.什麼級別的日誌 /var/log/file ##日誌採集規則
2.2 日誌型別分為:
auth ##pam產生的日誌
authjpriv ##ssh,ftp等登入資訊的驗證資訊
cron ##時間任務相關
kern ##核心
lpr ##列印
mail ##郵件
mark(syslog)-rsyslog ##服務內部的資訊,時間標識
news ##新聞組
user ##使用者程式產生的相關資訊
uucp ##unix to unix copy,unix主機之間相關的通訊
local 1-7 ##自定義的日至裝置
2.3 日誌級別分為
debug ##有調式資訊的,日誌資訊最多 info ##一般資訊的日誌,最常用 notice ##最具有重要性的普通條件的資訊 warning ##警告級別 err ##錯誤級別,阻止某個功能或者模組不能著呢廣場工作的資訊 crit ##嚴重級別,阻止整個系統或者整個軟體不能正常工作的資訊 alert ##需要立刻修改的資訊 emerg ##核心崩潰等嚴重資訊 none ##什麼都不記錄 ##注意:從上到下,級別從低到高,記錄的資訊越來越少
2.4 日誌遠端同步
在日誌傳送方:
vim /etc/rsyslog.conf
*.* @172.25.254.102 ##"@"表示udp協議傳送,“"@@"表示tcp協議傳送
systemctl restart rsyslog
在日誌接收方:
vim .etc.rsyslog.conf
15 SModLoad imudp ##開啟接受模組
16 SUDPServerRun 514 ##開啟接收埠
systemctle restart rsyslog systemctle stop firewalld ##關閉防火牆 systemctle disable firsyslog ##設定防火牆開機不啟動
測試:
在日誌傳送和接受方都清空日誌
> /var/log/messages
在日誌傳送方
logger test
在傳送方和接收方都可以檢視到日誌
cat /var/log/messages
2.5 日誌採集格式的設定
當前採集日誌的格式: 主機名:使用者
vim /etc/rsyslog.conf
$template LOGFMT, "%timegenerated% %FROMHOST0-IP% %syslogtag% %msg%\n"
%timegenerated% ##顯示日誌時間
%FROMHOST-IP% ##顯示主機IP
%syslogtag% ##日誌記錄目標
%msg% ##日誌內容
*.* /var/log/westos;LOGFMT
在日誌傳送方:
logger test1
在日誌接收方:
cat /var/log/westos
- 時間同步(NTP)服務
服務名稱
chronyd
##在服務端
編輯vim /etc/chrony.conf
22 allow 172.25.254.0/24 ##允許那些客戶端來同步本紀時間
33 local stratum 10 ##本紀不同步任何主機的寺建,本紀作為時間源
systemctl restart chronyd
##在客戶端
vim /etcchrony.conf
server 172.25.254.100 iburst ##本機立即同步202這臺主機的時間
systemctl restart chronyd
##測試:
##客戶端
[[email protected] ~]# chronyc sources -v
210 Number of sources = 1
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample
#===============================================================================
^* 172.25.254.202 10 6 377 5 -8217ns[ -58us] +/- 113us
-
timedatectl 命令
timedatectl 檢視當前的時區和時間資訊 timedatectl ##管理系統時間 timedatectl set-time ##設定當前時間 timedatectl set-timezone ##設定當前時區 timedatectl set-local-rtc 0|1##設定是否使用utc時間 timedatectl list-timezones ##檢視支援的所有時區 timedatectl set-time "2018-10-19 12:00"
5. journalctl命令
5.1journalctl ##日誌檢視工具
-n 3 ##檢視最近3條日誌
-p err ##檢視錯誤日誌
-o verbose ##檢視日誌的詳細參考
--since ##檢視從什麼時間開始的日誌
--until ##檢視到什麼時間為止的日誌
journalctl --since "2018-10-13 12:00" --until "2018-10-13 12:01"
5.2 如何使用systemd-journal儲存系統日誌
mkdir /var/log/journal
chgrp systemd-journal /var/log/journal
chmod g+s /var/log/journal
ps aux | grep systemd-journal
killall -1 systemd-journal
ls /var/log/journal
946cb0e817ea4adb916183df8c4fc817
6.linux下的網路配置
6.1 什麼是IP adress
internet protocol adress ##網路協議地址
ipv4 internet protocol version 4
1.2x32
ip是由32個01組成
1111110.1111110.1111110.1111110=254.254.254.254
6.2 子網掩碼
用來劃分網路區域 (netmask)
子網掩碼非0位對應的ip上的數字表示這個ip 的網路位
子網掩碼0對應的數字是ip的主機位
網路所謂表示網路區域
主機位表示網路區域內的某主機
255.255.255.0 前三位網路位,最後一位主機位
6.3 ip通訊判定
網路位一致,主機位不一致的兩個ip可以直接通訊
172.25.254.1/24 24=255.255.255.0
172.25.254.2/24 ----------小區域找大區域不一定
172.25.0.1/16 ----------從大的區域去找小的區域能找到
用命令更改的只是臨時更改
6.4 網路設定工具
ping ##檢測網路是否通暢
ifconfig ##檢視或這頂網路藉口
ifconfig device ip/24 ##設定ip
ifconfig device down ##關閉介面
ifconfig device up ##開啟介面
ip addr show
6.5 圖形方式設定ip
圖形方式設定:
1.nm-connection editor
2.nmtui
圖形介面和非圖形介面
6.6 用命令的方式設定網路
nmcli ##NetworkManager必須開啟
nmcli device show eth0 ##檢視網絡卡資訊
nmcli device status eth0 ##檢視網絡卡服務介面資訊
nmcli device connect eth0 ##啟用eth0網絡卡
nmcli device disconnect eth0 ##關閉eth0網絡卡
nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection delete westos
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.202/24
nmcli connection modify westos ipv4.method.atuo
nmcli connection modify westos ipv4.method.manual
nmcli connection modify westos ipv4.address.172.25.254.150/24
非圖形介面
nmcli
裝置名稱和連結名稱
connection 後面接連結名稱
device 後面節裝置
6.7 管理網路配置檔案
PREFIX 子網掩碼
網路配置目錄
/etc/sysconfig/network-scripts/
網路配置檔案的命令規則
ifcfg-xxx
DEVICE=xxx ##裝置名稱
ONBOOT=yes ##網路服務開啟時自動啟用網絡卡
BOOTPROTO=dhcp|static|none ##裝置工作方式
IPADDR= 172.25.254.202 ##IP地址
PREFIX=24 ##子網掩碼
NETMASK=255.255.255.0 ##子網掩碼
NAME=dalianmao ##介面名稱(可有可無)
示例:
靜態網路配置檔案:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.202
PREFIX=24
NAME=dalianmao
systemctil restart network
一塊網絡卡上配置多個IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.202
PREFIX=24
NAME=dalianmao
IPADDR=172.25.2.202
PREFIX=24
systemctl restart network
ip addr show eth0
7.8 lo迴環介面
7.9 閘道器
#1.把真實主機變成路由器
firewall-cmd --list-all
firewall-cmd --list-all
firewall-cmd --list-all
firewall-cmd --list-all
masquerade:yes <---表示地址偽裝功能開啟,物理機變成路由器
2.設定虛擬機器閘道器
vim /etc/sysconf/network ##全域性閘道器。針對所有沒有設定閘道器的網絡卡生效
vim /etc/sysconf/network。scripts/ifcfg-eth0 ##當網絡卡中設定的IP有多個時。指定對於哪個IP生效
GATEWAY=172.25.254.111 ##當網絡卡中只設定了一個IP時
[[email protected] ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 "172.25.254.2" 0.0.0.0 UG 1024 0 0 eth0
172.25.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.25.254.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
虛擬機器上鍊接ip
#############10.設定dns####
dns= domin name system
vim /etc/hosts ##本地解析檔案
ip 域名
61.135.169.125 www.baoidu.com
vim /etc/resolv.conf ##dns指向檔案
nameserver 114.114.114.114 ##當需要某個份額域名的IP地址時去問114.114.114.114
vim /etc/sysconfig/network-scripts/ifcfg-xxx
DNS1=114.114.114.114
注意:
當網路工作模式位dhcp時
系統會自動獲取ip閘道器dns
/etc/resolv.conf會被獲得到的資訊修改
如果不需要獲得dns資訊
在網絡卡配置檔案中加入
PEERDNS=no
#####11.設定解析的優先順序
系統預設:
/etc/hosts > /etc/resolv.conf
vim /etc/nsswitch
39 hosts: files dns ##/etc/hosts優先
vim /etc/nsswitch.conf
39 hosts: dns files ##/etc/resolv/conf dns指向優先
#####重啟物理機網路虛擬機器掉線
方法 1.命令方式,在物理機重操作
brctl show
brctl addif br0 vnet0
brctl addif br0 vnet1 ##新增虛擬機器裝置
方法 2.
虛擬機器poweroff ,再開啟
dhcp
第一步,安裝軟體
改本地解析,254改稱250
####12.dhcp服務配置##
tip: 做這個實驗,拔掉網線
1.在服務端:
yum install dhcp
cp /user/share/doc/dhcp*/dhcpd.conf.
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
# option definitions common to all supported networks...
option domain-name "westos.com";
option domain-name-servers 172.25.254.250;
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
# This is a very basic subnet declaration.
subnet 172.25.254.0 netmask 255.255.255.0 {
range 172.25.254.150 172.25.254.200;
option routers 172.25.254.250;
}
systemctl start dhcpd
可以在服務端和客戶端看到ip分配的記錄
服務端:/var/lib/dhcpd/dhcpd.leases
客戶端:/var/log/messages
測試:再網路工作模式是dhcp的主機中重其網路,可以看到ip 閘道器 dns全部獲取成功