1.系统的日志管理
1.日志的远程同步
在日志的发送方:
[root@server ~]# vim /etc/rsyslog.conf
*.* @172.25.70.150
##@表示upd协议发送,@@表示tcp协议发送
[root@server ~]# systemctl restart rsyslog
在日志的接收方:
15 $ModLoad imudp ##开启接收模块
16 $UDPServerRun 514 ##开启接收端口
[root@client ~]# systemctl restart rsyslog
[root@client ~]# systemctl stop firewalld ##关闭防火墙
[root@client ~]# systemctl disable firewalld ##设定防火墙开机不启动
测试:在日志的发送方和接收方都清空日志
> /var/log/messages
在日志发送方
logger test
在发送方和接收方都可以查看到日志
cat /var/log/messages
2.rsyslog的管理
/var/log/messages ##服务信息日志
/var/log/secure ##系统登陆日志
/var/log/cron ##定时任务日志
/var/log/maillong ##邮件日志
/var/log/boot.log ##系统启动日志
/var/log/boot.log什么类型的日志,什么级别的日志
1)日志的类型分为:
auth ##pam产生的日志
authpriv ##ssh,ftp等登陆信息的验证信息
cron ##时间任务相关
kern ##内核
lpr ##打印
mail ##邮件
mark(syslog)-rsyslog ##服务内部的信息,时间标识
news ##新闻组
user ##用户程序产生的相关信息
uucp ##unix to unix copy,unix主机之间相关的通讯
local 1~7 ##自定义的日志设备
2)日志的级别分为
debug ##有调式信息的,日志信息最多
info ##一般信息的日志,最常用
notice ##最具有重要性的普通条件信息
warning ##警告级别
err ##错误级别,阻止某个功能或模块不能正常工作的信息
crit ##严重级别,阻止整个系统或整个软件不能正常工作的信息
alert ##需要立刻修改的信息
emerg ##内核崩溃等严重信息
none ##什么都不记录
3.日志采集格式的设定
[root@client ~]# vim /etc/rsyslog.conf
$templaet LOGFMT,"%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"
%timegenerated% ##显示日志时间
%FROMHOST-IP% ##显示主机IP
%syslogtag% ##日志记录目标
%msg%" ##日志内容
*.* /var/log/westos;LOGFMT
在日志发送方:
[root@server var]# logger test
在日志接收方:
[root@client ~]# cat /var/log/westos
Oct 16 10:19:22 127.0.0.1 rc.local: /etc/rc.d/rc.local: line 18: /dev/tcp/content.example.com/80: Network is unreachable
4.journalctl命令
1)journalctl ##日志查看工具
journalctl -n 3 ##查看最近3条日志
journalctl -p err ##查看错误日志
journalctl -o verbose ##查看日志的详细参数
journalctl --since ##查看从什么时间开始的日志
journalctl --until ##查看到什么时间为止的日志
[root@client ~]# journalctl --since "2018-10-18 5:44" --until "2018-10-18 5:45"
-- Logs begin at Thu 2018-10-18 05:44:59 EDT, end at Thu 2018-10-18 06:16:19 EDT. --
Oct 18 05:44:59 localhost systemd-journal[84]: Runtime journal is using 8.0M (max 92.0M, l
Oct 18 05:44:59 localhost systemd-journal[84]: Runtime journal is using 8.0M (max 92.0M, l
Oct 18 05:44:59 localhost kernel: Initializing cgroup subsys cpuset
Oct 18 05:44:59 localhost kernel: Initializing cgroup subsys cpu
Oct 18 05:44:59 localhost kernel: Initializing cgroup subsys cpuacct
2)如何使用systemd-journal保存系统日志
[root@client ~]# mkdir /var/log/journal
[root@client ~]# chgrp systemd-journal /var/log/journal
[root@client ~]# chmod g+s /var/log/journal
[root@client ~]# ps aux | grep systemd-journal
root 360 0.0 0.1 42992 3168 ? Ss 05:45 0:00 /usr/lib/systemd/systemd-journald
root 30382 0.0 0.0 112644 940 pts/1 R+ 06:20 0:00 grep --color=auto systemd-journal
[root@client ~]# killall -1 systemd-journald
[root@client ~]# ls /var/log/journal
946cb0e817ea4adb916183df8c4fc817
2.时间同步服务
1.服务名称:chronyd
在服务端:
vim /etc/chrony.conf
22 allow 172.25.70.0/24
##允许哪些客户端来同步本机时间
29 local stratum 10
##本机不同不任何主机的时间,本纪作为时间源
[root@client ~]# systemctl restart chronyd
在客户端
[root@server ~]# vim /etc/chrony.conf
server 172.25.70.11 iburst
##本机立即同步11这台主机的时间
[root@station ~]# 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.70.250 10 6 7 31 -1120ns[ +72ms] +/- 81us
2.timedatectl命令
timedatectl ##管理系统时间
timedatectl set-time ##设定当前时间
timedatectl set-timezone ##设定当前时区
timedatectl set-local-rtc 0|1 ##设定是否使用utc时间
timedatectl list-timezones ##查看支持的所有时区
[root@client ~]# timedatectl set-time "2018-12-12 12:12:12"
[root@client ~]# date
Wed Dec 12 12:12:13 EST 2018
3.linux下的网络配置
1.什么是IP address
internet protocol address ##网络协议地址
ipv4 internet protocol version 4 ##互联网协议第四版
1.2x32
ip是由32个01组成
11111110.11111110.11111110.11111110=254.254.254.254
2.子网掩码
用来划分网络区域
子网掩码非0的位对应的ip上的数字表示这个ip的网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域内的某台主机
3.ip通信判定
网络位一致,主机位不一致的2个ip可以直接通讯
172.25.254.1/24 ##24=255.255.255.0
172.25.254.2/24
172.25.0.1/24
4.网络设定工具
ping ##检测网络是否通畅
ifconfig ##查看或设定网络接口
ifconfig device ip/24 设定ip
ifconfig device down ##关闭接口
ifconfig device up ##开启接口
ip addr show ##查看ip地址
[root@client ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.70.22 netmask 255.255.255.0 broadcast 172.25.70.255
inet6 fe80::5054:ff:fe00:460a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:46:0a txqueuelen 1000 (Ethernet)
RX packets 4767 bytes 400316 (390.9 KiB)
RX errors 0 dropped 1925 overruns 0 frame 0
TX packets 2139 bytes 806049 (787.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 73 bytes 10302 (10.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 73 bytes 10302 (10.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@client ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:46:0a brd ff:ff:ff:ff:ff:ff
inet 172.25.70.22/24 brd 172.25.70.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:460a/64 scope link
valid_lft forever preferred_lft forever
5.图形方式设定ip
1.nm-connection-editor
2.nmtui
6.命令方式设定网络
nmcli ##Networnager必须开启
nmcli device show eth0 ##查看网卡信息
[root@client ~]# nmcli device show eth0
GENERAL.DEVICE: eth0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 52:54:00:00:46:0A
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: eth0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: ip = 172.25.70.22/24, gw = 0.0.0.0
IP6.ADDRESS[1]: ip = fe80::5054:ff:fe00:460a/64, gw = ::
nmcli device status eth0 ##查看网卡服务接口信息
[root@client ~]# nmcli device status eth0
Unknown parameter: eth0
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected eth0
lo loopback unmanaged --
nmcli devicedisconnect eth0 ##启用eth0网卡
nmcli device connect eth0 ##关闭eth0网卡
nmcli connection show ##查看网络
nmcli connection down westos ##关闭westos网络
nmcli connection up westos ##打开westos网络
nmcli connection delete westos ##删除westos网络
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.70.33/24 ##添加网络
[root@client ~]# nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.70.33/24
Connection 'westos' (f5dc20e1-5e17-4474-8de6-051deffa19f1) successfully added.
nmcli connection modify westos ipv4.method auto ##改变ip获取方式为自动
[root@client ~]# nmcli connection modify westos ipv4.method auto
nmcli connection modify westos ipv4.method manual ##改变ip获取方式为手动
[root@client ~]# nmcli connection modify westos ipv4.method manual
nmcli connection modify westos ipv4.addresses 172.25.254.44/24 ##更改westos网络
[root@client ~]# nmcli connection modify westos ipv4.addresses 172.25.254.44/24
7.管理网络配置
网络配置目录
/etc/sysconfig/network-scripts/
网络配置文件的命令规则
ifcfg-xxx
DEVICE=xxx ##设备名称
ONBOOT=yes ##网络服务开启时自动激活网卡
BOOTPROTO=dhcp|static|none ##设备工作方式
IPADDR= ##IP地址
PREFIX=24 ##子网掩码
NETMASK=255.255.255.0 ##子网掩码
NAME= ##接口名称(可有可无)
示例:
静态网络配置文件:
[root@client ~]# vim /etc/sysconfig/network-scripts/ifcfg-westos
EVICE=eth0 ##设备名称
ONBOOT=yes ##网络服务开启时自动激活网卡
BOOTPROT0=none ##设备工作方式
IPADDR0=172.25.70.33 ##IP地址
PREFIX=24 ##子网掩码
NAME=westos
[root@client ~]# systemctl restart network
一块网卡上配置多个IP
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.25.70.33
PREFIX0=24
NAME=westos
IPADDR1=172.25.70.44
PRETIX1=24
[root@client ~]# systemctl restart network
[root@client ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:46:0a brd ff:ff:ff:ff:ff:ff
inet 172.25.70.22/24 brd 172.25.70.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:460a/64 scope link
valid_lft forever preferred_lft forever
8.网关
把真实主机变成路由器
[root@foundation70 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: br0 enp3s0 wlp2s0
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
[root@foundation70 ~]# firewall-cmd --permanent --add-masquerade
success
[root@foundation70 ~]# firewall-cmd --reload
success
[root@foundation70 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: br0 enp3s0 wlp2s0
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: yes
forward-ports:sourceports:
icmp-blocks:
rich rules:
masquerade: yes ##表示地址伪装功能开启,物理机变成路由器
2.设定虚拟机网关
vim /etc/sysconfig/network ##全局网关,针对所有没有设定网关的网卡生效
GATEWAY=172.25.70.250
vim /etc/sysconfig/network-scripts/ifcig-eth0
GATEWAY0=172.25.70.250##当网卡中设定的IP有多个时,指定对于哪个IP生效
GATEWAY=172.25.70.250##当网卡中设定的IP有多个时,指定对于哪个IP生效
[root@server network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.70.250 0.0.0.0 UG 1024 0 0 eth0
172.25.70.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
9.设定dns
dns=domain name system
root@server ~]# vim /etc/hosts
##本地解析文件
61.135.169.121 www.baidu.com
[root@server ~]# vim /etc/resolv.conf
nameserver 114.114.114.114
[root@foundation70 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114
注意:
当网络工作模式为dhcp时,系统会自动获得ip网关。/etc/resolv.conf会被获得到的信息修改。弱国不需要获得dns信息,在网卡配置文件中加入PEERDNS=no
10.设定解析的优先级
系统默认:
/etc/hosts > /etcresolv.conf
[root@server ~]# vim /etc/nsswitch.conf
39 hosts: files dns
##/etc/hosts优先
39 hosts: dns files
##/etc/resolv.conf dns指向优先