Utilize shell scripts,linux commands, open source tools,java, to Maximize the Power of Linux.
Focused on working with linux and shell, search engine technology including Chinese segmenter
Any questions please contact me at gmail: david.ullua
Labels
- working with linux (9)
- tools for developer (7)
- java (4)
- common tools (3)
- php (3)
- shell (3)
- linux (1)
- linux virtualization (1)
- mysql (1)
5/31/2007
Utilize hudson and ant to set up a daily build system step by step
0). download hudson from https://hudson.dev.java.net/servlets/ProjectDocumentList.
You can download jnlp release jar or old release war package.
1).Hudson needs a web container such as glassfish, tomcat or winstone.
But Hudson ships with Winstone, so you can run it standalone by run : java -jar hudson.war, or java -jar hudson.jar if you downloaded the jnlp release.
Use the -D option to specify HUDSON_HOME in the invocation:
$ java -DHUDSON_HOME=/path/to/home -jar hudson.war
Alse you can use the environment variable:
$ export HUDSON_HOME=/path/to/hudson_home
$ java -jar hudson.war
HUDSON_HOME: Hudon needs some diskspace to perform builds and keep archives.
(By default, this is set to ~/.hudson , but you can change it: https://hudson.dev.java.net/admin.html)
2).If you don't have container yet, you can run hudson standalone (with shipped container Winstone), then you can access the portal of hudson by http://hostname:8080/ (default port is 8080), and create a new job, set some basic configurations. it will run by the schedule you configured.
3).If you have a container already (like tomcat), just deploy hudson.war to the webapps directory of tomcat, restart tomcat. then you can access the portal from http://hostname:8081/hudson, assume 8081 is the port for tomcat. for glassfish please take a reference at https://hudson.dev.java.net/containers/glassfish.html.
4). you can configure automatic build (like crontab), or periodical build or build by email, ref: https://hudson.dev.java.net/build.html
5). if you met problem when run ant task (), make sure your ant target is correct. My ant target is "-f CustomBuild.xml makepackage", it runs makepackage in ant build file CustomBuild.xml. If still fails, you can just checkout your project from repository to a clean directory, and run ant command to check whether it runs through, if fails check ant build file.
6).if can't send email successfully, just click "Manage Hudson" in the index page of the hudson portal, click "System Configuration" to configure smtp related info. If your SMTP need authentication, click "Advanced" in the "E-mail Notification" section, and enter the username plus password.
It should works, else email me your problem.
5/28/2007
gains of subversion (SVN带来的收益)
Date: 05/28/2007, Suzhou
When I working on .Net and VSS. Our team was often troubled by the crippled VSS. In many cases, someone modified a common file like DbHelper.cs, or a business logic class Order.cs, and we need to modify the file too. Then we need to wait for him/her to checkin/commit the file, even worse, he/she is taking a vacation in another city, then we have to modify the file's read-only attribute on local disk, however could not checkin/commit the changes. It wasted us lots of time in waiting and in checkin/checkout.
If you are suffering from "lock, checkout and modify" model of VSS (Visual Source Safe) in team cooperation, or you are searching for a version control system, I suggest you to try subversion (SVN) as source management system. Subversion has a model of "checkout, modify, update and commit". After checkout a file/folder, anyone can modify a file in the same time, then when execute updating(if no concurrent modification you don't need to update, just commit directly), svn will merge other's modification to your working copy automatically, then you can commit your copy safely. If it can't merge these modifications, it would tell you where are conflicts, and you can resolve them manually and then commit safely. you can reference the manual in http://subversion.tigris.org .
Even if you are using dotnet, there is subversion plugins for VS.net. Now my team are using java, SVN has helped us in source code management and team cooperation greatly. I believe that it is one of the most successful open source project.
当我使用.net和VSS的时候,我们的团队经常被憋足的VSS所绊倒。很多情况下,有人修改了一个公用文件DbHelper.cs 或者一个业务逻辑文件Order.cs, 这时我们也需要修改这个文件。然后我们不得不等他/她签入/提交文件。更糟糕的是,此时他/她可能正在另一个城市旅行,这时我们只好修改本地文件的只读属性,但依然无法签入。大量的时间在等待和签入签出中被浪费了。
如果您正在被VSS的“锁定,签出,修改”模型所困扰,或者您正在寻找一个版本管理系统,那么我向您推荐subversion (SVN). Subversion使用"签出,修改,更新和提交"的模型,当签出一个文件或目录后,每一个人都可以同时修改同样的文件,然后执行更新(如果没有并发修改就不需要更新,可以直接提交), svn会自动合并其他人的修改到您的工作文件中.然后您可以安全地提交您的机器上的拷贝. 如果svn无法合并更改,那么她会告诉您哪些地方有冲突,您可以手工解决这些冲突,然后安全地提交. 您可以参考http://subversion.tigris.org 上面的手册.
即时您在使用dotnet, 仍然有VS.net的subversion插件可以使用。现在我的Team使用java, SVN在代码管理和团队协作上给了我们很大的帮助。我相信她是最优秀的开源项目之一。
2/02/2007
Apache 2.2.4, tomcat5.0.28 整合,以及中文乱码问题解决
Author: David Euler, 2007, david.ullua _at_ gmail (请用gmail.com替换gmail)
这篇文章主要参考从google搜索到的整合方法和问题解决方法,以及apache.org官方网站的文档。
并经过实际的验证 (os: slackware 11, 软件版本参考安装)。
目录
I.安装Apache, Tomcat, tomcat-connector (mod_jk) , 并整合apache与tomcat
II.tomcat, apache整合后,去掉tomcat的8080端口服务,用户只能通过80端口访问服务器
III.Tomcat/Apache乱码问题解决.
IV.虚拟主机配置
---------------------------------------------------------------------------------------------------------------
I.安装Apache, Tomcat, tomcat-connector (mod_jk) , 并整合apache与tomcat
共分5个步骤,详述如下
1、准备,下载需要的文件。这里假定你已经正确安装配置好了JDK。
到Apache官方网站下载所需要的文件:
httpd-2.2.4.tar.gz , apache的httpd server包 (需要编译安装,安装时)
apache-tomcat-5.5.20.tar.gz, apache的tomcat包, 不需要编译安装(解压即可)
tomcat-connectors-1.2.20-src.tar.gz (mod_jk的安装包)
2、安装Apache。
# tar xzvf httpd-2.2.4.tar.gz
或 tar jxvf httpd-2.2.4.tar.bz2
# cd httpd-2.2.4
参考INSTLL安装文档,如下即可安装apache(自带有cgi,perl, apxs的支持):
# ./configure --prefix=/usr/local/apache2 (不需要加--enable-so参数,
# make
# make install
3、安装Tomcat (解压即可)
# cp apache-tomcat-5.5.20.tar.gz /usr/local/
# cd /usr/local
# tar xzvf apache-tomcat-5.5.20.tar.gz
# ln -s apache-tomcat-5.5.20 tomcat
4、编译生成mod_jk
# tar xzvf tomcat-connectors-1.2.20-src.tar.gz
# cd tomcat-connectors-1.2.20-src/jk/native
# ./configure --with-apxs=/usr/local/apache2/bin/apxs
# make
# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/
5、配置
在/usr/local/apache2/conf/下面建立两个配置文件mod_jk.conf和workers.properties。
# vi mod_jk.conf
添加以下内容:
# 指出mod_jk模块工作所需要的工作文件workers.properties的位置
JkWorkersFile /usr/local/apache2/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/apache2/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理
JkMount /servlet/* worker1
JkMount /*.jsp worker1
# vi workers.properties
添加以下内容:
# Defining a worker named worker1 and of type ajp13,
# 注意8009是tomcat的ajp13端口,注意不是8080
worker.list=worker1
# Set properties for worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
#worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
6.再配置httpd.conf,作以下修改:
将Listen 80 修改为 Listen 127.0.0.1:80
将ServerName 修改为 ServerName localhost:80
在DirectoryIndex中添加 index.jsp, 假设网页放在/var/wwwroot下,要修改DocumentRoot
DocumentRoot "/var/wwwroot"
<Directory "/var/wwwroot">
Options Includes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
XBitHack on
</Directory>
<Directory "/var/wwwroot/WEB-INF">
Order deny,allow
Deny from all
</Directory>
增加关于加载mod_jk的语句:
LoadModule jk_module modules/mod_jk.so
Include /usr/local/apache2/conf/mod_jk.conf
在/var/wwwroot下建立一个index.jsp,启动Apache和Tomcat,用浏览器访问http://localhost/,应可看到正确的页面。
---------------------------------------------------------------------------------------------------------------
II.tomcat, apache整合后,去掉tomcat的8080端口服务,用户只能通过80端口访问服务器 (以统一日志分析等的处理):
找到server.xml, 去掉port="8080"
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="5000" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
URIEncoding="UTF-8" useBodyEncodingForURI="true" />
---------------------------------------------------------------------------------------------------------------
III.Tomcat/Apache乱码问题解决
首先,确保 httpd.conf中的下面一行的注释没有打开(未配置AddDefaultCharset ):
#AddDefaultCharset ISO-8859-1
然后依情况按步骤1), 2)操作
如果你的网页中定义的charset为UTF-8, 如下
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
那么步骤1-2用UTF-8替代GBK
1)如果你将apache和tomcat整合了,那么修改tomcat/conf中的server.xml
<Connector port="8009" enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" URIEncoding="GBK"/>
添加URIEncoding="GBK",请确保你的jsp的开头:
<%@page contentType="text/html;charset=GBK"%>
里的charset和URIEncoding一致。 (均为GBK或UTF-8)
2)如果没有将tomcat和apache整合,那么修改如下的标签:
<Connector
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK"/>
参考:
http://www.gbunix.com/htmldata/2006_08/15/23/article_1383_1.html
http://dev.cbw.com/web/apache/2005524308_3480676.shtml
---------------------------------------------------------------------------------------------------------------
IV.虚拟主机配置:
删除掉下面这一行的#(取消注释)
#Include conf/extra/httpd-vhosts.conf
vi conf/extra/httpd-vhosts.conf, 根据文件中的例子添加虚拟主机。
参考:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
http://httpd.apache.org/docs/2.2/vhosts/examples.html
SVN 项目管理使用FAQ
* Author David Lv Euler
* Createddate 2007-2-1
* Contact david.ullua at gmail (please add .com to gmail)
* You can redistribute the total file wherever you like, but pls keep the
author's info. The document is provided WITHOUT any warranty.
****************************************************************/
1.如何将eclipse的项目添加到SVN管理:
a.对于建立好的项目(未受SVN管理),在eclipse中,右键点击项目名,点"ShareProject", 选"SVN",点"下一步"
b.选择"创建新的资源库位置",或者"使用已有的资源库位置",选择资源库后点"下一步",
c.假定选择或者创建的资源库位置为svn://172.16.100.26, 通常要选择服务器上特定的目录下面保存项目,
比如在svn://172.16.100.26/dev-source/app/下面,那么就选择"使用指定的模块名",
点浏览并选择:svn://172.16.100.26/dev-source/app/,
这个时候在输入框里面会有一个"New Folder"被选中, 把New Folder改为项目的名称。点"下一步"。
2.如何利用eclipse(已安装subclipse插件), 从SVN上取得项目到本地的Workspace中:
a. Eclipse 中点"File" -> "New" -> "other" , 选择SVN, "从SVN取出项目".
b. 选择"创建新的资源库位置",或者"使用已有的资源库位置",选择资源库后点"下一步"
c. 选择要导出的项目在SVN上的路径,比如dev-source/monternet/Server,
点"Next", 选择"做为新项目取出,
并使用新建项目向导进行配置", 点Finish. 这时会弹出New Project的向导,
因为项目在SVN上,本地上没有,所以会出现这个向导。
d. 在新建项目向导中,选择"Java" -> "Java Project"(比如ServerCore可能需要选择这个),
或者 "Web" -> "Dynamic Web Project" (比如LinuxWebSite项目可能需要选择这个).
点"Next", 输入Project name, 比如RobooProject. 点Next, 点"Finish"。
这样就完成了从SVN服务器上取出项目到Eclipse的workspace中
3. 为什么提交总是失败。
需要注意两点:
a.若与Tortoise 同时使用,那么尽量不要同时使用Tortoise和eclipse对一个目录进行操作。
b.在把其他目录的文件拷贝到受SVN管理的项目中时, 需要按目录提交,而不是按文件提交。
c.在对类名/文件名进行重构时,需要按目录(文件所在的目录)提交,而不是对单个的文件进行提交。
4.SVN客户端的常用命令有哪些?
如果装了Subversion, 在windows和linux下都可以用命令行来获取SVN上的信息。 有几个命令比较常用:
svn co
svn list
svn info
svn add
svn commit
比如
svn list svn://172.16.100.26/dev-doc/ , 显示服务器上指定目录的内容
svn co svn://172.16.100.26/dev-doc/ , 获取服务器上的内容
svn info svn://172.16.100.26/dev-doc/tools/subversion/svn_tutorial.txt , 显示SVN
上指定文件的信息。
svn info 显示当前受SVN 管理的目录信息。
svn add files_on_local_disk 添加本地文件到SVN 管理(此命令尚未将文件上传到SVN中)
svn commit (提交所做的改动, 上传用svn add 命令添加的文件)
5. 如何使用命令获取SVN的项目到eclipse中进行管理?
用命令获取项目, 再从eclipse打开项目会更方便。比如获取ServerCore项目, 我这样做:
1. svn co svn://172.16.100.26/dev-src/ServerCore(获取服务器上的项目到当前目录下,会产生RobooCore
目录)
2.从eclipse新建项目, 指定步骤1中获取到的项目目录. 这样就完成了从SVN获取项目到Eclipse.
比前面问题2中的a, b, c, d 四步要方便很多。
6. 为什么会遇到 Authentication Failed?
Authentication Failed通常是因为没有对应目录的权限所导致。
7. 为什么我遇到 Out of date: '/dev-src/xxx/yyy' in transaction '102-1'
当本机修改的文件不是服务器上的最新版本,修改本机文件后commit, 会提示out of date的错误。
需要先从服务器上获取最新版本(update), 然后进行修改,这时候再提交就可以了。
1/29/2007
Mysql starting error: ... STOPPING server from pid file /var/lib/mysql/roboo-lvzg.pid , mysqld ended
When I start mysqld server (in slackware linux 11), got error as follows:
root@kseeker-lvzg:~# mysqld_safe --user='mysql' &
[1] 10624
root@kseeker-lvzg:~# Starting mysqld daemon with databases from /var/lib/mysql
STOPPING server from pid file /var/lib/mysql/kseeker-lvzg.pid
070129 18:55:45 mysqld ended
oh, you need to su mysql and run mysql_install_db to fix the problem.
root@kseeker-lvzg:~# su mysql
mysql@kseeker-lvzg:/root$ mysql_install_db
Installing all prepared tables
Fill help tables
To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h kseeker-lvzg password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
1/25/2007
利用~/.netrc文件自动ftp下载文件 (当天或昨天的tomcat日志)
home目录中添加文件.netrc,内容如下:
#download files begin with test under user david's home
machine 172.16.100.30 login david password 3287
macdef init
binary
prompt
!clear
mget test*
!clear
bye
#get the log of yesterday:
#echo "catalina.`date --date='1 days ago' +%Y-%m-%d `.log" | ftp www.kseeker.com
#download file specified by the second arg (the log filename)
machine www.kseeker.com login david password pass92342@#$@**(89
macdef init
binary
prompt
cd /home/tomcat/logs
mget $2
bye
注意:bye后要有一空行,.netrc文件的属性须是600,
可以使用这个命令下载172.16.100.30上面/home/david/目录test开头的文件:%ftp 172.16.100.30
可以使用这个命令来下载服务器上昨天的tomcat日志(文件名如: catalina.2007-01-24.log):
%echo "catalina.`date --date='1 days ago' +%Y-%m-%d `.log" | ftp www.kseeker.com
man netrc, 可以看到更多信息:
NETRC(5) BSD File Formats Manual NETRC(5)
NAME
netrc, .netrc -- user configuration for ftp
DESCRIPTION
This file contains configuration and autologin information for the File Transfer Protocol client ftp(1).
The .netrc file contains login and initialization information used by the auto-login process. It resides in the user's
home directory. The following tokens are recognized; they may be separated by spaces, tabs, or new-lines:
......
1/15/2007
add authentication for awstats in apache
but we can use apache's auth_module to add authentication for a specified directory( in this case is awstats).
assume awstats config file is /etc/awstats/awstats.kseeker.com.conf ,
awstats is installed at /usr/local/awstats/, awstats.pl is located at /usr/local/awstats/wwwroot/cgi-bin.
and httpd.conf is located at /etc/httpd/conf/.
step 1: config awstats to enable authentication access
%vi /etc/awstats/awstats.kseeker.com.conf, find the line contains AllowAccessFromWebToAuthenticatedUsersOnly, and the line contains
AllowAccessFromWebToFollowingAuthenticatedUsers, change them as follows:
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers="david"
step 2: enable apache authentication for awstats directory
%vi /etc/httpd/conf/httpd.conf, set AllowOverride to All for "/usr/local/awstats/wwwroot/cgi-bin" directory:
<Directory "/usr/local/awstats/wwwroot/cgi-bin">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
step 3: add authentication file and .htacess file, add user , and restart apache
%cd /usr/local/awstats/wwwroot/cgi-bin
%htpasswd -c userfile david //create user file, it will prompt for user's password.
%cat > .htaccess
AuthUserFile /usr/local/awstats/wwwroot/cgi-bin/userfile
AuthName "Restricted Area For Customers"
AuthType Basic
require valid-user
Ctrl + D
% apachectl restart
Blog Archive
About Me
- euler
- I am a senior developer and a team leader with 3 years development experience in Suzhou, China, focus on mobile web search, linux, Java and machine learning in NLP (natural language processing). My goal is to improve people's life with computer technology.