rsyslog的mysql的helloworld

http://downloads.mysql.com/archives.php?p=mysql-5.1&v=5.1.45x iazai
mysql的rpm包http://rpm.scl.rs/mysql/Downloads/MySQL-5.1/
redhat5.4上
mysql安装参考http://hi.baidu.com/ablenavy/blog/item/ee85fff21b3e971db17ec560.html

rpm -q ncurses
rpm -q ncurses-devel
yum install ncurses-devel
mysql-5.1.49.tar.gz

../configure \
--prefix=/usr/local/mysql \
--localstatedir=/data \
--sysconfdir=/usr/local/mysql \
--with-unix-socket-path=/tmp/mysql.sock \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=gbk,latin1 \
--with-plugins=partition,blackhole,heap,innobase,myisam,ndbcluster,csv,federated \
--without-debug \
--enable-thread-safe-client \
--enable-assembler \
--enable-profiling \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-mysqld-user=mysql \
--without-embedded-server \
--with-server-suffix=-community \
--with-tcp-port=3306 \
#--with-named-curses-libs=/usr/lib/libncurses.so.5.5


make 
make install

mkdir /usr/local/mysql
mkdir /data
useradd mysql
./mysql_install_db --basedir=/mysql --datadir=/data/ --user=mysql
chown -R root:mysql /usr/local/mysql
chown -R mysql:mysql /data

ln -sf /mysql/bin/mysqladmin /sbin/mysqladmin
ln -sf /mysql/bin/mysql /sbin/mysql

cp /mysql/share/mysql/my-large.cnf /mysql/my.cnf
[mysqld]下面添加
datadir=/data
log-error=/data/mysql.err
federated
ndbcluster

./mysqld_safe --user=mysql &

#ln -s /mysql /usr/local/mysql
#ln -s /tmp/mysql.sock /mysql/mysql.sock
mysql
或mysql --sock=/tmp/mysql.sock

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
chkconfig --list mysqld
service mysqld start
service mysqld stop

改密码
mysqladmin -uroot password "haoning" --sock=/tmp/mysql.sock

root@red54apple backup]# ps -ef|grep mysql
root      4079     1  0 16:42 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data --pid-file=/data/red54apple.pid
mysql     4260  4079  0 16:42 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/data --user=mysql --log-error=/data/mysql.err --pid-file=/data/red54apple.pid --socket=/tmp/mysql.sock --port=3306
root      4296 16425  0 16:45 pts/2    00:00:00 grep mysql
[root@red54apple backup]





---------------------------------------http://www.cublog.cn/u2/76419/showart_1783316.html--------------
/configure --enable-mysql
最好是
/configure --prefix=/usr/local/rsyslog --enable-mysql
make
make install

cp rsyslog.conf /etc/
打开注释
# UDP Syslog Server:
#$ModLoad imudp.so  # provides UDP syslog reception
#$UDPServerRun 514 # start a UDP syslog server at standard port 514

mysql
source /opt/backup/rsyslog-6.1.0/plugins/ommysql/createDB.sql

之后加载mysql模块,当然你一定要确认ommysql.so在lib文件夹里存在,如果你之前使用./configure --enable-mysql进行配置则会在/usr/local/lib/rsyslog下存在ommysql.so文件(操作系统不同,目录可能不一样),然后在rsyslog.conf文件中加上:

$ModLoad ommysql
#local4.*     :ommysql:127.0.0.1,yourdb,yourname,yourpass;
local4.*     :ommysql:127.0.0.1,Syslog,root,haoning;


修改etc/init.d/syslog:
-----------
[root@red54apple ommysql]# cat /etc/init.d/syslog
#!/bin/bash
#
# syslog        Starts syslogd/klogd.
#
#
# chkconfig: 2345 12 88
# description: Syslog is the facility by which many daemons use to log \
# messages to various system log files.  It is a good idea to always \
# run syslog.
### BEGIN INIT INFO
# Provides: $syslog
### END INIT INFO

# Source function library.
. /etc/init.d/functions

[ -f /usr/local/sbin/rsyslogd ] || exit 0
[ -f /sbin/klogd ] || exit 0
RETVAL=0

start() {
        echo -n $"Starting rsyslog: "
        /usr/local/sbin/rsyslogd
        RETVAL=$?
        echo
        echo -n $"Starting kernel logger: "
        daemon klogd $KLOGD_OPTIONS
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rsyslog
        return $RETVAL
}
stop() {
        echo -n $"Shutting down kernel logger: "
        killproc klogd
        echo
        echo -n $"Shutting down system rsyslog: "
        killproc rsyslogd
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/rsyslog
        return $RETVAL
}
rhstatus() {
        status rsyslogd
        status klogd
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        rhstatus
        ;;
  restart)
        restart
        ;;
  reload)
        reload
        ;;
  condrestart)
        [ -f /var/lock/subsys/rsyslog ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart}"
        exit 2
esac

exit $?
---------------------------------------

rsyslog.conf:

# UDP Syslog Server:
$ModLoad imudp.so  # provides UDP syslog reception
$UDPServerRun 514 # start a UDP syslog server at standard port 514
# MySQL log
$ModLoad ommysql
$template MySQLInsert,"insert into SystemEvents( ReceivedAt,DeviceReportedTime,message,FromHost,syslogtag) values('%timegenerated:::date-mysql%','%timereported:::date-mysql%','%msg%','%fromhost-ip%','%syslogtag%')", SQL

local4.*     :ommysql:127.0.0.1,syslogdatabase,syslogusername,syslogpass;MySQLInsert
--------------------------------202----------------------------
[@zjm_106_202 ~]# cat /etc/rsyslog.conf
$ModLoad imudp.so
$ModLoad ommysql.so
$UDPServerRun 514

:syslogtag, !contains, "#CMS5"                          /opt/log/all.log
:syslogtag, contains, "#CMS5"                           /opt/log/cms5.log
:syslogtag, contains, "#CMS5.CAS"                           /opt/log/cas.log
:syslogtag, contains, "#CMS5.CAS" :ommysql:localhost,CasSyslog,syslog,syslog
local6.*                                                /opt/log/audit.log
local6.* :ommysql:localhost,Syslog,syslog,syslog

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /opt/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog


# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 *

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
[@zjm_106_202 ~]# 
-------------------------------------------------------
/usr/local/sbin/rsyslogd -c5
如果报错,看清楚,可能是安装的时候没指定安装路径,直接装到/usr/local/lib下面了,找不到so动态库了
可以建立ln -s /usr/local/lib /usr/local/rsyslog/lib解决



另一台机器
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestLog {

	private static final Logger logger = LoggerFactory.getLogger(TestLog.class);
	public static void main(String[] args) {
		logger.info("test haoning");

	}

}

log4j
log4j.rootLogger=INFO,CONSOLE,SYSLOG
#log4j.rootLogger=INFO,SYSLOG,CONSOLE,DAILY_ROLLING_FILE
log4j.addivity.org.apache=true
log4j.debug=false

###################
# Console Appender
###################
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.Threshold=DEBUG
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} %l %m%n



########################
# RSYSLOG
########################
app.name=#CMS5.SERVER
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.SyslogHost= 10.10.10.10
log4j.appender.SYSLOG.Facility=local5
log4j.appender.SYSLOG.Threshold=INFO
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern=${app.name} %d{yyyy-MM-dd HH:mm:ss} %c:%L %m%n

需要
commons-logging-1.0.4.jar
ganymed-ssh2-build210.jar
log4j-1.2.13.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar

----------------
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SyslogAppender.html

你可能感兴趣的:(mysql)