1. small stips
*日志的类别 后面*日至的级别
.
debug日志,服务量大,级别低,显示信息多
发送端
一个艾特@代表udp协议
两个@代表tcp协议
接收端
同意接收
防火墙关闭
改完配置文件重其服务
2. 系统的日志管理
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
3. 时间同步(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
##测试:
##客户端
[root@client ~]# 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
4. 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.1 journalctl ##日志查看工具
-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
6.8 lo回环接口
6.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时
[root@server ~]# 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
6.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
6.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全部获取成功