远程日志管理

远程日志管理

部署服务器

1.获取网卡ip地址

a、首先在虚拟机里添加一块网卡

远程日志管理

     设置为桥接模式

远程日志管理

b、[root@Centos_05 ~]# dhclient -d eth1 //获取网卡IP

远程日志管理
这里用作service端,这里作区分用

2.关闭防火墙及selinux

[root@Centos_05 ~]# /etc/init.d/iptables stop                 //关闭防火墙
[root@Centos_05 ~]# setenforce 0                                //临时允许selinux

远程日志管理
3.开启rsyslog服务的514号端口

[root@Centos_05 ~]# vim /etc/rsyslog.conf              //编辑配置文件

远程日志管理
开启514端口,esc:set nu 查看行数,将13、14、17、18行#删除保存

4.编写配置文件

[root@Centos_05 ~]# grep :fromhost -r /usr/share/doc/rsyslog*   //过滤出rsyslog

远程日志管理
:这里过滤是方便我们后续编辑文件,直接用这个模板

[root@Centos_05 ~]# vim /etc/rsyslog.d/remote.conf          //编辑配置文件

远程日志管理

**注**:这里的IP是客户端IP地址,如果需要多台,可以直接在里面添加IP地址及日志存储位置

[root@Centos_05 ~]# /etc/init.d/rsyslog restart              //启动服务   

远程日志管理

[root@Centos_05 ~]# netstat -utpln | grep 514               //查看514端口状态

远程日志管理

部署客户端

1.添加网卡,获取IP同上边服务端一样

远程日志管理
这里做client端,ip:192.168.0.104

2.关闭防火墙及selinux

[root@Centos_06 ~]# /etc/init.d/iptables stop                 //关闭防火墙
[root@Centos_06 ~]# setenforce 0                                //临时允许selinux

远程日志管理

3.编辑配置文件

[root@Centos_06 ~]# vim /etc/rsyslog.conf                        //编辑配置文件

远程日志管理
esc:set nu 79行添加服务端IP以及选择协议(o)
4.启动服务

[root@Centos_06 ~]# /etc/init.d/rsyslog restart

远程日志管理

验证:

[root@Centos_06 ~]# logger 456                                     //立即生成动态日志

远程日志管理

[root@Centos_05 ~]# tail -f /var/log/remote-1.log          //查看动态日志

远程日志管理

验证完毕,成功


扩展

可以添加多个客户端,需要在服务端内的 /etc/rsyslog.d/remote.conf  添加客户端IP地址以及日志的存放位置
客户端的/etc/rsyslog.conf   内的第79行,添加服务端IP以及选择的协议

猜你喜欢

转载自blog.51cto.com/14013609/2298994