# cd /usr/local/src/ # wget http://www.phpwizardry.com/php-syslog-ng/phpsyslogng-2.8.tar.gz # tar xvzf phpsyslogng-2.8.tar.gz # cd phpsyslogng-2.8/scripts/ # vi dbsetup.sql
dbsetup.sql
71,74,77行目のパスワードを変更
70 # create users
71 INSERT INTO user (Host, User, Password) VALUES ('localhost','sysloguser', password('sysloguser'));
72 INSERT INTO db (Host, Db, User) VALUES ('localhost','syslog','sysloguser');
73
74 INSERT INTO user (Host, User, Password) VALUES ('localhost','syslogfeeder', password('syslogfeeder'));
75 INSERT INTO db (Host, Db, User) VALUES ('localhost','syslog','syslogfeeder');
76
77 INSERT INTO user (Host, User, Password) VALUES ('localhost','syslogadmin',password('syslogadmin'));
78 INSERT INTO db (Host, Db, User) VALUES ('localhost','syslog','syslogadmin');
79 COMMIT;
80 FLUSH PRIVILEGES;
# mysql -u root -p < dbsetup.sql Enter password: 管理者パスワードを入力 # # mysql -u root -p syslog Enter password: 管理者パスワードを入力
Welcome to the MySQL monitor. Commands END with ; OR \g. Your MySQL connection id IS 2239 to server version: 5.0.21-LOG Type 'help;' OR '\h' for HELP. Type '\c' to clear the buffer. mysql> SHOW tables; +------------------+ | Tables_in_syslog | +------------------+ | actions | | logs | | search_cache | | user_access | | users | +------------------+ 5 rows IN SET (0.01 sec) mysql> exit Bye
# mkfifo /tmp/mysql.pipe # # vi /etc/syslog-ng/syslog-ng.conf
/etc/syslog-ng/syslog-ng.conf
####################
# options
####################
options {
sync (0);
time_reopen (10);
stats(86400);
log_fifo_size (2048);
log_msg_size(8192);
chain_hostnames(no);
long_hostnames (off);
keep_hostname (no);
use_dns (no);
use_fqdn (no);
create_dirs(yes);
dir_perm(0700);
perm(0600);
group(root);
owner(root);
};
####################
# sources
####################
source local { file ("/proc/kmsg" log_prefix("kernel: ")); unix-stream ("/dev/log"); internal(); };
source net { udp( ip(0.0.0.0) port(514) ); internal(); };
####################
# destination
####################
destination netudp { udp("<自分自身のIPアドレス>" port(514) ); };
destination d_summary { file("/var/log/summary.log"); };
destination d_mysql_p {
pipe("/tmp/mysql.pipe"
template("INSERT INTO logs
(host, facility, priority, level, tag, datetime, program, msg)
VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$LEVEL', '$TAG', '$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC',
'$PROGRAM', '$MSG' );\n") template-escape(yes));
};
####################
# filter
####################
filter f_summary { level(debug..emerg); };
####################
# log
####################
log { source(local); filter(f_summary); destination(netudp); };
log { source(net); filter(f_summary); destination(d_summary); };
log { source(net); filter(f_summary); destination(d_mysql_p); };
/etc/init.d/syslog-ng
################################################################################
#
# Program: syslog-ng init script for Red Hat
#
################################################################################
# the following information is for use by chkconfig
# if you are want to manage this through chkconfig (as you should), you must
# first must add syslog-ng to chkconfig's list of startup scripts it
# manages by typing:
#
# chkconfig --add syslog-ng
#
# DO NOT CHANGE THESE LINES (unless you know what you are doing)
# chkconfig: 2345 12 88
# description: syslog-ng is the next generation of the syslog daemon. \
# syslog-ng gives you the flexibility of logging not only by facility and \
# severity, but also by host, message content, date, etc. it can also replace \
# klogd's function of logging kernel messages
#
# This following block of lines is correct, do not change! (for more info, see
# http://www.linuxbase.org/spec/refspecs/LSB_1.1.0/gLSB/facilname.html)
### BEGIN INIT INFO
# Provides: $syslog
### END INIT INFO
################################################################################
#
# This is an init script for syslog-ng on the Linux platform.
#
# It totally relies on the Redhat function library and works the same
# way as other typical Redhat init scripts.
#
#
# Platforms (tested): Linux (Redhat 7.3)
#
#
# Author: Gregor Binder <gbinder@sysfive.com>
# Changed: October 10, 2000
#
# Last Changed: September 27, 2002
# Updated by: Diane Davidowicz
# changes: Brought the start script up to snuff as far as compliance
# with managing the startup script through chkconfig;
# added PATH variable ability to hook in path to syslog-ng (if
# its necessary); converted init script format to the
# standard init script format in Red Hat (7.3 to be exact)
# including using the /etc/sysconfig/syslog-ng file to
# managed the arguments to syslog-ng without changing this
# script, and disabled klogd but noted where and under what
# conditions it should be enabled. HAPPY LOGGING.
#
# Copyright (c) 2000 by sysfive.com GmbH, All rights reserved.
#
#
################################################################################
#
# configuration
#
INIT_PROG=syslog-ng
#
# Source Redhat function library.
#
. /etc/rc.d/init.d/functions
# Tack on path to syslog-ng if not already in PATH
SYSLOGNG_PATH=":/usr/local/sbin"
MYSQL="/usr/local/mysql/bin/mysql"
PATH=$PATH$SYSLOGNG_PATH
export PATH
# for MySQL
test -e /tmp/mysql.pipe || /usr/bin/mkfifo /tmp/mysql.pipe
# /etc/sysconfig/ is the standard way to pull in options for a daemon to use.
# Source config
if [ -f /etc/sysconfig/syslog-ng ] ; then
. /etc/sysconfig/syslog-ng
else
SYSLOGNG_OPTIONS=
fi
RETVAL=0
umask 077
ulimit -c 0
# See how we were called.
start() {
echo -n "Starting $INIT_PROG: "
daemon $INIT_PROG $SYSLOGNG_OPTIONS
RETVAL=$?
echo
$MYSQL -u syslogfeeder --password=syslogfeeder syslog < /tmp/mysql.pipe &
# syslog-ng can handle kernel messages. If you do this, don't
# run klogd. Consult the following FAQ question to find out why.
#
# http://www.campin.net/syslog-ng/faq.html#klogd
#
# If you still prefer to run klogd without syslog-ng handling
# kernel messages, uncomment the following block of lines
#echo -n $"Starting kernel logger: "
#daemon klogd $KLOGD_OPTIONS
#echo
[ $RETVAL -eq 0 ] && touch "/var/lock/subsys/${INIT_PROG}"
return $RETVAL
}
stop() {
# Same here concerning klogd. Uncomment the following block of
# code if you are needing to run it
#echo -n $"Shutting down kernel logger: "
#killproc klogd
#echo
echo -n "Stopping $INIT_PROG: "
killproc $INIT_PROG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f "/var/lock/subsys/${INIT_PROG}"
return $RETVAL
}
rhstatus() {
status $INIT_PROG
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/syslog-ng ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload}"
exit 1
esac
exit $?
# /etc/init.d/syslog-ng stop Stopping syslog-ng: [ OK ] # /etc/init.d/syslog-ng start Starting syslog-ng: [ OK ]
# cd /usr/local/src/ # cp -r phpsyslogng-2.8 /var/www/html/phpsyslogng # chown -R apache:apache /var/www/html/phpsyslogng/ # # cd /var/www/html/phpsyslogng/ # vi config/config.php
config/config.php
45,51行目のパスワードを変更
38 //========================================================================
39 // BEGIN: DATABASE CONNECTION INFO
40 //========================================================================
41 // DBUSER is the name of the basic user.
42 define('DBUSER', 'sysloguser');
43
44 // DBUSERPW is DBUSER's database password.
45 define('DBUSERPW', 'sysloguser');
46
47 // DBADMIN is the name of the admin user.
48 define('DBADMIN', 'syslogadmin');
49
50 // DBADMINPW is DBADMIN's database password.
51 define('DBADMINPW', 'syslogadmin');
52
53 // DBNAME is the name of the database you are using.
54 define('DBNAME', 'syslog');
55
56 // DBHOST is the host where the MySQL server is running.
57 define('DBHOST', 'localhost');
58
59 // DBPORT is the port where the MySQL server is listening.
60 // The default port is 3306.
61 define('DBPORT', '3306');
62 //========================================================================
63 // END: DATABASE CONNECTION INFO
# cd /var/www/html/phpsyslogng/scripts/ # vi logrotate.php
logrotate.php
1行目 php のパスを変更
6行目 php-syslog-ng のパスを変更
1 #!/usr/local/bin/php
2 <?php
3 // Copyright (C) 2005 Claus Lund, clauslund@gmail.com
4 echo "\nStarting logrotate\n";
5 echo date("Y-m-d H:i:s");
6 $APP_ROOT = '/var/www/html/phpsyslogng';
# crontab -e 以下を追加 55 23 * * * /usr/local/bin/php /var/www/html/phpsyslogng/scripts/logrotate.php > /dev/null 2>&1