文章目录
1.什么是日志?
电脑的日志相当于我们平常写的日记,日志里面记录的是服务器的状态。
日志的存在可以使管理员提前知道服务器的各种状态,如果服务器出现什么问题可以提前处理。
那么问题来了,公司的服务器很多,难道管理员一个一个查看服务器的状态吗?实际上并不是这样的,为了提高工作效率,我们可以把所有服务器的日志集中在一起管理,放在一台主机上管理,将其他服务器的日志都传到这台管理日志的主机上,这样就方便多了。
2.搭建实验环境
我们需要两台服务器:
- 一台作为管理日志服务器。server,设定IP:123.0.0.1/24
- 一台作为客户端被管理。client,设定IP:123.0.0.2/24
服务端:
[root@server ~]# ip a
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:05:0a brd ff:ff:ff:ff:ff:ff
inet 123.0.0.1/24 brd 123.0.0.255 scope global eth0
# ip设定成功
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:50a/64 scope link
valid_lft forever preferred_lft forever
客户端:
[root@client ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 123.0.0.2 netmask 255.255.255.0 broadcast 123.0.0.255
# ip设定成功
inet6 fe80::5054:ff:fe00:50b prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:05:0b txqueuelen 1000 (Ethernet)
RX packets 131 bytes 17998 (17.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 200 bytes 24159 (23.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
接下来两台服务器添加解析:
首先在服务器端设定:
[root@server ~]# vim /etc/hosts # 编辑解析文件
[root@server ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
123.0.0.1 server.example.com # 写入自己的域名与IP
123.0.0.2 client.example.com # 写入客户的域名与IP
[root@server ~]# scp /etc/hosts root@123.0.0.2:/etc/ # 将此文件远程发送给client用户
root@123.0.0.2's password:
hosts 100% 217 0.2KB/s 00:00
[root@server ~]# ping client.example.com # 现在就可以解析域名了
PING client.example.com (123.0.0.2) 56(84) bytes of data.
64 bytes from client.example.com (123.0.0.2): icmp_seq=1 ttl=64 time=0.209 ms
64 bytes from client.example.com (123.0.0.2): icmp_seq=2 ttl=64 time=0.418 ms
^C
--- client.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.209/0.313/0.418/0.105 ms
直接在客户端进行测试:
[root@client ~]# ping server.example.com # 客户端也可以解析服务器域名
PING server.example.com (123.0.0.1