Centos6.5 搭建 LogAnalyzer4.1.1 - 开源日志服务器(一)

前端之家收集整理的这篇文章主要介绍了Centos6.5 搭建 LogAnalyzer4.1.1 - 开源日志服务器(一)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

LogAnalyzer是一款使用率较高的日志服务器,在遇到非法***或故障排查,当然还有责任划分(公司内互扯的事太多了)的时候尤为显得重要,所以公司内部使用一台日志服务器是一件很有必要的事情。


系统环境

CentOS 6.5 x86_64 版本安装



loganalyzer4.1.1搭建过程:

(在安装loganalyzer最新版本第三步空白过不去,日志说是PHP没有调用到某个函数,好像PHP5.5以后支持了,但安装了5.5以后的版本了还是空白过不去,网上百度了很多没有解决这个问题,loganalyzer4.1.1没有这个问题)

一、安装并设置LAMP环境

1、安装LAMP环境

一、MysqL数据库安装

1. 基础软件包安装

  1. #yuminstallgccmake-y

2. 下载

  1. 进入源码存放目录
  2. #cd/usr/local/src
  3. 下载MysqL安装包
  4. #wgetdownloads.MysqL.com/archives/get/file/MysqL-5.5.40-linux2.6-x86_64.tar.gz

3. 解压安装

  1. 解压
  2. #tar-zxfMysqL-5.5.40-linux2.6-x86_64.tar.gz
  3. 设置安装路径
  4. #mvMysqL-5.5.40-linux2.6-x86_64/usr/local/MysqL

4. 建立MysqL用户

  1. #useradd-s/sbin/nologin-MMysqL

5. 准备数据目录

  1. 进入MysqL安装目录
  2. #cd/usr/local/MysqL
  3. 创建MysqL数据目录
  4. #mkdir-p/var/lib/MysqL
  5. #chown-RMysqL:MysqL/var/lib/MysqL

6. 初始化数据库

  1. #yuminstall-ylibaio(使用最小安装系统需要安装这个包不然会报错)
  2.  
  3. #./scripts/MysqL_install_db--user=MysqL--datadir=/var/lib/MysqL
  4. whenspecifyingMysqLprivileges!InstallingMysqLsystemtables...OK
  5. Fillinghelptables...OK#看到2个OK说明初始化成功

7. 拷贝配置文件

  1. #/bin/cpsupport-files/my-xxxx.cnf/etc/my.cnf

8. 拷贝启动脚本

  1. 拷贝启动脚本
  2. #/bin/cpsupport-files/MysqL.server/etc/init.d/MysqLd
  3. 赋予可执行权限
  4. #chmod755/etc/init.d/MysqLd

9. 修改启动脚本

  1. #vim/etc/init.d/MysqLd
  2. 修改设置内容如下
  3. basedir=/usr/local/MysqL
  4. datadir=/var/lib/MysqL

10. 把MysqL添加到服务

  1. 添加service列表
  2. #chkconfig--addMysqLd
  3. 设置开机启动
  4. #chkconfigMysqLdon

11. 启动MysqL服务

  1. #serviceMysqLdstart
  2. StartingMysqL...SUCCESS!

12. 查看验证MysqL启动进程

  1. #ps-e|grepMysqL1830pts/1
  2. 00:00:00MysqLd_safe2121pts/1
  3. 00:00:00MysqLd

13. 配置MysqL环境变量

MysqL 客户端命令路径加入 PATH 环境变量中去。

  1. 设置PATH环境变量
  2. #echo'exportPATH=$PATH:/usr/local/MysqL/bin'>/etc/profile.d/MysqL.sh
  3. #source/etc/profile.d/MysqL.sh

14. 登录MysqL测试

  1. #MysqL
  2. 默认没有密码
  3. YourMysqLconnectionidis1Serverversion:5.5.40-logMysqLCommunityServer(GPL)
  4. Copyright(c)2000,2014,Oracleand/oritsaffiliates.Allrightsreserved.
  5. ......
  6. MysqL>



二、Apache服务安装

apache可以通过yum的方式来安装,也可以通过源码编译的方式来安装,这里采用编译源码的方式进行安装。

1. 下载解压apache安装包

  1. #cd/usr/local/src
  2. #tar-xfhttpd-2.4.29.tar.bz2

2. 安装必要的库和工具

  1. #yuminstall-ypcrepcre-develaprapr-develzlib-develgccmake
  2.  
  3.  
  4. #wgethttp://archive.apache.org/dist/apr/apr-1.5.0.tar.gz
  5. #wgethttp://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
  6. #tar-xfapr-1.5.0.tar.gz
  7. #tar-xfapr-util-1.5.4.tar.gz
  8. #cdapr-1.5.0
  9. #./configure--prefix=/usr/local/apr/
  10. #make&&makeinstall
  11. #cd
  12. #cdapr-util-1.5.4
  13. #./configure--prefix=/usr/local/apr-util/--with-apr=/usr/local/apr/
  14. #make&&makeinstall
  15. #cd
  16. #wgethttp://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
  17. #tar-xfpcre-8.39.tar.gz
  18. #cdpcre-8.39
  19. #yum-yinstallgccgcc-c++cmake
  20. #./configure--prefix=/usr/local/pcre/
  21. #make&&makeinstall

3. 配置编译参数

  1. #cdhttpd-2.4.29
  2. #./configure--prefix=/usr/local/apache2--with-apr=/usr/local/apr/--with-apr-util=/usr/local/apr-util/--with-pcre=/usr/local/pcre/

4. 编译安装

  1. #make&&makeinstall
  2. #echo$?

5. 配置apache环境变量

  1. #echo'exportPATH=$PATH:/usr/local/apache2/bin'>/etc/profile.d/http.sh
  2. #source/etc/profile.d/http.sh

6. apache的启动和停止

  1. apachectl start # 启动
    apachectl stop # 停止
    apachectl restart # 重启
    apachectl -t # 检查语法
    apachectl -M # 查看加载模块

7. 将apache加入系统服务

  1. #拷贝服务脚本
  2. #cp/usr/local/apache2/bin/apachectl/etc/init.d/httpd
  3. #vim/etc/init.d/httpd
  4. 第一行下边添加2内容
  5. #!/bin/sh
  6. #chkconfig:23456161
  7. #description:Apache
  1. #添加到系统服务并设置开机启动
  2. #chkconfig--addhttpd
  3. #chkconfighttpdon

8. 验证服务是否正常

  1. #servicehttpdstarthttpd:apr_sockaddr_info_get()Failedforvip
  2. #出现警告信息
  3. httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.0.1forServerName

解决警告信息的方法:去掉ServerName www.example.com:80 行的注释#。




三、PHP系统安装

1. 下载解压安装包

  1. #cd
  2. #tar-xfPHP-5.6.33.tar.bz2

2. 下载依赖库和工具

  1. # yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libjpeg-devel
    # yum -y install libpng libpng-devel freetype freetype-devel libmcrypt-devel
    # yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel perl

3. 编译配置安装选项

  1. #cdPHP-5.6.33
  2. #./configure--prefix=/usr/local/PHP--with-apxs2=/usr/local/apache2/bin/apxs--with-config-file-path=/usr/local/PHP/etc\
  3. #--with-MysqL=/usr/local/MysqL--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-freetype-dir--with-iconv-dir--with-zlib-dir\
  4. #--with-bz2--with-openssl--with-mcrypt--enable-soap--enable-gd-native-ttf--enable-mbstring--enable-sockets--enable-exif--disable-ipv6--enable-fpm

5. 拷贝PHP配置文件

  1. #cpPHP.ini-production/usr/local/PHP/etc/PHP.ini

6. 配置PHP环境变量

  1. #echo'exportPATH=$PATH:/usr/local/PHP/bin'>/etc/profile.d/PHP.sh
  2. #source/etc/profile.d/PHP.sh

到此为止,PHP完成基本的编译安装,后续解析PHP还得另外配置。


四、配置支持PHP解析

1. 修改apache配置文件

vi /usr/local/apache2/conf/httpd.conf

  1. <Directory/>
  2. OptionsFollowSymLinks
  3. AllowOverrideNone
  4. Orderdeny,allow
  5. Allowfromall#Deny修改为Allow</Directory>

2. 支持PHP脚本解析

  1. AddTypeapplication/x-compress.Z
  2. AddTypeapplication/x-gzip.gz.tgz
  3. AddTypeapplication/x-httpd-PHP.PHP#添加这1行

3. 添加PHP索引支持

  1. <IfModuledir_module>
  2. DirectoryIndexindex.htmlindex.htmindex.PHP#添加PHP索引
  3. </IfModule>

4. 测试配置语法和重启apache服务

  1. #apachectl-t
  2. SyntaxOK
  3. #servicehttpdrestart

5. 测试PHP解析

编写测试文件:/usr/local/apache2/htdocs/index.PHP

  1. <?PHP
  2. echo"helloPHP!"
  3. ?>

命令行curl测试:

  1. #curllocalhost/index.PHP
  2. helloPHP!

解析 PHP 成功!




2、基础装好了下面就是准备数据

检查并安装服务器端软件

1.检查是否安装rsyslog软件

  1. #rpm-qa|greprsyslog//默认系统都安装了该软件

注: rsyslog-MysqL 为rsyslog 将日志传送到MysqL 数据库的一个模块,这里必须安装


2、配置服务器端

  1. #导入rsyslog-MysqL数据库文件
  2. #cd/usr/share/doc/rsyslog-MysqL-5.8.10/
  3. #MysqL-uroot-p123456<createDB.sql


3、查看做了哪些操作

  1. #MysqL-uroot-p123456
  2. MysqL>showdatabases;

MysqL> use Syslog;

MysqL> show tables;

导入数据库操作创建了Syslog 库并在该库中创建了两张空表SystemEvents 和SystemEventsProperties

1、创建rsyslog 用户MysqL下的相关权限

  1. #MysqL-uroot–p
  2. MysqL>grantallonSyslog.*to'rsyslog'@'localhost'identifiedby'123456';
  3. MysqL>flushprivileges;#刷新权限表
  4. MysqL>exit

2、配置服务端支持rsyslog-MysqL 模块,并开启UDP服务端口获取网内其他LINUX系统日志

  1. #vim/etc/rsyslog.conf
  2. $ModLoadomMysqL
  3. *.*:omMysqL:localhost,Syslog,rsyslog,123456

注:localhost 表示本地主机,Syslog 为数据库名,rsyslog 为数据库用户,123456为该用户密码

3、开启相关日志模块

  1. #vim/etc/rsyslog.conf
  2.  
  3. $ModLoadimmark#immark是模块名,支持日志标记
  4. $ModLoadimudp#imupd是模块名,支持udp协议
  5. $UDPServerRun514#允许514端口接收使用UDP和TCP协议转发过来的日志
  1. 重启rsyslog服务
  2. #servicersyslogrestart



4、配置客户端

  1. a、检查rsyslog是否安装
  2. #rpm-qa|greprsyslog
  3.  
  4.  
  5.  
  6. b、配置rsyslog客户端发送本地日志到服务端
  7. #vim/etc/rsyslog.conf
  8. *.*@192.168.131.130

注:行尾新增上面这行内容,即客户端将本地日志发送到服务器


  1. c、重启rsyslog服务
  2. #servicersyslogrestart
  3.  
  4. d、编辑/etc/bashrc,将客户端执行的所有命令写入系统日志/var/log/message
  5. 文件尾部增加一行
  6. exportPROMPT_COMMAND='{msg=$(history1|{readxy;echo$y;});logger"[euid=$(whoami)]":$(whoami):[`pwd`]"$msg";}'
  7. #.!$#加载/etc/bashrc


5、测试Rsyslog Server是否可以正常接受Client端日志

Client端测试




Server端侦测

注:说明接收正常,包括你重启机器的一些Log都可以查看到




3、最后安装LogAnalyzer

  1. 安装LogAnalyzer

  1. #yum-yinstallwget
  2. #wget
  3. #tarxfloganalyzer-4.1.1.tar.gz
  4. #cdloganalyzer-4.1.1
  5. #mkdir/usr/local/apache2/htdocs/loganalyzer
  6. #cp-rsrc/*/usr/local/apache2/htdocs/loganalyzer/
  7. #cpcontrib/*/usr/local/apache2/htdocs/loganalyzer/
  8. #cd/usr/local/apache2/htdocs/loganalyzer/
  9. #chmod+xconfigure.shsecure.sh
  10. #./configure.sh
  11. #./secure.sh
  12. #chmod666config.PHP
  13. #cd..
  14. #chown-Rdaemon:daemonloganalyzer/
  15. #servicehttpdrestart
  16. #servicersyslogrestart


2、在浏览器安装向导中安装LogAnalyzer

打开浏览器输入:http://xxxx/loganalyzer/

提示没有配置文件,点击 here 利用向导生成

测试系统环境

点击"next",进入下一步

基础配置

在User Database Options 中,填入上面设置的参数,然后点击 "Next".

创建表

点击 Next 开始创建表

检查sql结果

创建管理用户

创建第一个系统日志source

完成



测试

LogAnalyzer 首页

点击"Statistics"

登录测试

点击"Admin Center"在Admin Center 里可以进行一些系统设置







本文转载参考:

https://www.cnblogs.com/fengyutech/p/4967509.html

猜你在找的CentOS相关文章