发布时间:2014-09-05 17:21:43作者:知识屋
安装脚本如下,文章最后有打包下载,遇到的问题在脚本中有注释
#!/bin/sh
# mysql conf
mysql_user=root #mysql root 用户名
mysql_pwd=fuckmysqlintruder #mysql root 密码
run_user=user #syslog库用户
run_pwd=user #syslog库用户密码
# Install env.
yum -y install mysql mysql-devel mysql-server php php-mysql php-pdo php-common php-gd httpd zlib-devel gcc gcc-c++
# Install rsyslog..
tar xvf rsyslog-5.6.2.tar.gz
cd rsyslog-5.6.2
./configure --enable-mysql --prefix=/usr/local/rsyslog #支持mysql,指定安装路径
make && make install
cd ..
# creat rsyslog config..
sed -e "s/ommysql:localhost,Syslog,root,/ommysql:localhost,Syslog,${run_user},${run_pwd};dbFormat/g" rsyslog.conf > /etc/rsyslog.conf
#这里设置rsyslog.conf中的mysql连接账户和密码
#rsyslog支持数据模板,我定义了一个插入db的模板,在rsyslog.conf中
#$template dbFormat,"insert into SystemEvents (Message, Facility,FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values (%msg%, %syslogfacility%, %fromhost-ip%,%syslogpriority%, %timereported:::date-mysql%, %timegenerated:::date-mysql%, %iut%, %syslogtag%)",sql
#其中红色字体部分如果是%HOSTNAME%,那么库中记录的就是hostname,不是ip;所以如果要改成显示ip,那么使用%fromhost-ip%
# stop system syslog..
service syslog stop #因为有rsyslog了,系统自带的syslog停掉
chkconfig syslog off
# create rsyslog startup script
cp /etc/init.d/{syslog,rsyslog} #rsyslog没有启动脚本,复制syslog脚本
# edit rsyslog startup script
sed -i s/syslog/rsyslog/g /etc/init.d/rsyslog #修改syslog字符为rsyslog
chmod 700 /etc/init.d/rsyslog
chkconfig --add rsyslog #添加rsyslog服务
chkconfig rsyslog on
# create rsyslog bin ln
ln -sv /usr/local/rsyslog/sbin/rsyslogd /sbin/rsyslogd #创建软连结,rsyslog脚本启动的是/sbin下的rsyslogd
# conf mysql
service mysqld start
chkconfig mysqld on
mysqladmin -u root -p password ${mysql_pwd} #设置mysql的root密码,脚本执行到这里要点下回车,默认root密码为空
# create sql
cat > createDB.sql << EOF #创建Syslog数据库和表,并授权,为什么给all privileges,因为安装时会有create 操作,装完以后降权
CREATE DATABASE Syslog default character set utf8;
USE Syslog;
CREATE TABLE SystemEvents
(
ID int unsigned not null auto_increment primary key,
CustomerID bigint,
ReceivedAt datetime NULL,
DeviceReportedTime datetime NULL,
Facility smallint NULL,
Priority smallint NULL,
FromHost varchar(60) NULL,
Message text,
NTSeverity int NULL,
Importance int NULL,
EventSource varchar(60),
EventUser varchar(60) NULL,
EventCategory int NULL,
EventID int NULL,
EventBinaryData text NULL,
MaxAvailable int NULL,
CurrUsage int NULL,
MinUsage int NULL,
MaxUsage int NULL,
InfoUnitID int NULL ,
SysLogTag varchar(60),
EventLogType varchar(60),
GenericFileName VarChar(60),
SystemID int NULL
) DEFAULT CHARSET=utf8;
CREATE TABLE SystemEventsProperties
(
ID int unsigned not null auto_increment primary key,
SystemEventID int NULL ,
ParamName varchar(255) NULL ,
ParamValue text NULL
) DEFAULT CHARSET=utf8;
grant all privileges on Syslog.* to ${run_user}@localhost identified by ${run_pwd};
EOF
# import sql
mysql -u${mysql_user} -p${mysql_pwd} < createDB.sql #导入sql
# start rsyslog
service rsyslog restart #启动rsyslog
# install loganalyzer
tar xvf loganalyzer-3.0.4.tar.gz
cd loganalyzer-3.0.4
cp -r src/ /var/www/html/loganalyzer
cp -r contrib/* /var/www/html/loganalyzer
cd ..
chown -R apache.apache /var/www/html/loganalyzer
# use web install loganalyzer.
/bin/sh /var/www/html/loganalyzer/configure.sh
/bin/sh /var/www/html/loganalyzer/secure.sh
# start httpd
service httpd start
chkconfig httpd on
# edit src/include/functions_common.php function GetStringWithHTMLCodes
sed -i s/htmlentities.*/htmlentities($myStr,ENT_QUOTES,"UTF-8");/g /var/www/html/loganalyzer/include/functions_common.php
#loganalyzer乱码的原因是使用了,htmlentities对输出进行编码,如果有中文会出现问题,应该指定字符集,修改这个函数为
#return htmlentities($myStr,ENT_QUOTES,"UTF-8");
# reduce the privilege
read -n 1 -p Please go to install web, when finished, press Enter... #到这里先进web安装loganalyzer,完毕以后再来降权
cat > priv.sql << EOF #发现浏览日志详细日志的时候,会用到alter,加grant进去了.
revoke all privileges on Syslog.* from ${run_user}@localhost;
grant insert,delete,update,select,alter on Syslog.* to ${run_user}@localhost identified by ${run_pwd};
EOF
mysql -u${mysql_user} -p${mysql_pwd} < priv.sql
# clean
rm -rf priv.sql createDB.sql loganalyzer-3.0.4 rsyslog-5.6.2
完
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能