lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2010年11月17日

在Ubuntu10.04上通过mysql源代码进行编译安装

Filed under: Linux,mysql — 标签:, , , , — lizongbo @ 00:10

在Ubuntu10.04上通过mysql源代码进行编译安装MySQL Community Server

操作系统是linode上的Ubuntu 10.04,
MySQL Community Server目前最新正式版为:mysql 5.1.51 GA.
源代码下载地址为:
http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.51.tar.gz

来源:http://www.mysql.com/downloads/mirror.php?id=394595#mirrors
http://www.mysql.com/downloads/

1.先下载源代码到本地:
root@618119.com:/usr/local/app# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.51.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/
2.解压mysql-5.1.51.tar.gz到/usr/local/app/mysql-5.1.51:
root@618119.com:/usr/local/app# tar -zxvf mysql*
3.进入解压得到的源码目录中:
root@618119.com:/usr/local/app# cd mysql*
4.运行configure进行检查:
root@618119.com:/usr/local/app/mysql-5.1.51# ./configure -prefix=/usr/local/app/mysql -with-charset=utf8 -with-collation=utf8_general_ci -with-extra-charsets=latin1
提示信息:checking for termcap functions library… configure: error: No curses/termcap library found
5.安装libncurses5-dev进行解决:
root@618119.com:/usr/local/app/mysql-5.1.51# sudo apt-get install libncurses5-dev
6.在编译安装nginx时候已经安装了 gcc libc6-dev build-essential 组件
直接开始运行make编译源代码:
root@618119.com:/usr/local/app/mysql-5.1.51# make
7.等待一段时间后,源码编译完成,运行make install进行安装:
root@618119.com:/usr/local/app/mysql-5.1.51# make install
8.复制系统服务脚本:
root@618119.com:/usr/local/app/mysql# cp /usr/local/app/mysql/share/mysql/mysql.server  /etc/init.d/mysql
9.再运行命令: sudo /usr/sbin/update-rc.d -f mysql defaults,将mysql安装为默认服务。
root@618119.com:/usr/local/app/mysql# sudo /usr/sbin/update-rc.d -f mysql defaults
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = “zh_CN.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).
Adding system startup for /etc/init.d/mysql …
/etc/rc0.d/K20mysql -> ../init.d/mysql
/etc/rc1.d/K20mysql -> ../init.d/mysql
/etc/rc6.d/K20mysql -> ../init.d/mysql
/etc/rc2.d/S20mysql -> ../init.d/mysql
/etc/rc3.d/S20mysql -> ../init.d/mysql
/etc/rc4.d/S20mysql -> ../init.d/mysql
/etc/rc5.d/S20mysql -> ../init.d/mysql
10.复制默认配置到/etc目录:
root@618119.com:/usr/local/app/mysql# cp /usr/local/app/mysql/share/mysql/my-medium.cnf /etc/my.cnf
11:添加名字为mysql的用户:
root@618119.com:/usr/local/app/nginx# sudo adduser –system –no-create-home –disabled-login –disabled-password –group mysql
12.初始化数据库(如果没初始化,启动mysql会提示“Manager of pid-file quit without updating file”):
root@618119.com:/usr/local/app/mysql/bin# ./mysql_install_db –user=mysql
Installing MySQL system tables…
101022 15:24:16 [Warning] ‘–skip-locking’ is deprecated and will be removed in a future release. Please use ‘–skip-external-locking’ instead.
OK
Filling help tables…
101022 15:24:16 [Warning] ‘–skip-locking’ is deprecated and will be removed in a future release. Please use ‘–skip-external-locking’ instead.
OK

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/local/app/mysql/bin/mysqladmin -u root password ‘new-password’
/usr/local/app/mysql/bin/mysqladmin -u root -h 618119.com password ‘new-password’

Alternatively you can run:
/usr/local/app/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/app/mysql ; /usr/local/app/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/app/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/app/mysql/bin/mysqlbug script!

13.启动mysql数据库.
root@618119.com:/usr/local/app/mysql/bin# sudo /etc/init.d/mysql start

14.命令行进入数据库进行测试:
root@618119.com:/usr/local/app/mysql/bin# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.51-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| test               |
+——————–+
3 rows in set (0.00 sec)

mysql> quit
Bye

15.运行mysql自带的测试脚本需要等的时间比较久:
root@618119.com:/usr/local/app/mysql# cd /usr/local/app/mysql/mysql-test ; perl mysql-test-run.pl
测试结果是1000多项只有600项通过:
main.mysql_client_test                   [ fail ]
Test ended at 2010-10-22 15:35:39

CURRENT_TEST: main.mysql_client_test
mysqltest: At line 15: command “$MYSQL_CLIENT_TEST –getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1” failed

Output from before failure:
exec of ‘/usr/local/app/mysql/bin/mysql_client_test –defaults-file=/usr/local/app/mysql/mysql-test/var/my.cnf –testcase –vardir=/usr/local/app/mysql/mysql-test/var –getopt-ll-test=25600M >> /usr/local/app/mysql/mysql-test/var/log/mysql_client_test.out.log 2>&1’ failed, error: 256, status: 1, errno: 0

The result from queries just before the failure was:
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;

– saving ‘/usr/local/app/mysql/mysql-test/var/log/main.mysql_client_test/’ to ‘/usr/local/app/mysql/mysql-test/var/log/main.mysql_client_test/’

Only  653  of 1415 completed.
mysql-test-run: *** ERROR: Not all tests completed
166.使用符号链接方便直接运行 mysql命令:
root@618119.com:/usr/local/app/mysql# sudo ln -s /usr/local/app/mysql/bin/mysql /usr/bin/
root@618119.com:/usr/local/app/mysql# sudo ln -s /usr/local/app/mysql/bin/mysqladmin /usr/bin/

开始在resin上安装phpMyAdmin:
phpMyAdmin最新版本 3.3.7:
下载地址:http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.7/phpMyAdmin-3.3.7-all-languages.tar.gz
来源:
http://www.phpmyadmin.net/home_page/index.php

下载后解压到:lizongbo@618119.com:/etc/init.d$ cd /usr/local/app/resin/webapps
然后改名:
lizongbo@618119.com:/usr/local/app/resin/webapps$ mv phpMyAdmin-3.3.7-all-languages/ phpMyAdmin

尝试resin最新版跑phpMyAdmin跑不了。
还是想办法配置nginx吧,可以参考:
http://www.linuxidc.com/Linux/2010-03/25161.htm
mysql JDBC驱动:
最新正式版为:Connector/J 5.1.13
下载地址:http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector- java-5.1.13.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/
来源:http://www.mysql.com/downloads/connector/j/

root@618119.com:/usr/local/app# wget http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/Connector-J/mysql-connector-java-5.1.13.tar.gz
root@618119.com:/usr/local/app# tar -zxvf mysql-c*
复制jdbc驱动到resin的lib目录:
root@618119.com:/usr/local/app/mysql-connector-java-5.1.13# cp /usr/local/app/mysql-connector-java-5.1.13/mysql-connector-java-5.1.13-bin.jar /usr/local/app/resin/lib

2010年11月4日

linode上配置resin的CGIservlet来支持perl运行awstats7.0

Filed under: Linux,nginx,Resin — 标签:, , , , , — lizongbo @ 00:19

linode上配置resin的CGIservlet来支持perl运行awstats7.0
在网上搜索了linode的vps上安装配置nginx来支持awstats的相关文章,感觉比较麻烦,而我的linode vps上因为部署了Resin4.0.12,因此我选择通过resin的CGIservlet来运行awstats.

1.如果是windows操作系统,需要下载安装最新的ActivePerl:
http://downloads.activestate.com/ActivePerl/releases/5.12.2.1202/ActivePerl-5.12.2.1202-MSWin32-x86-293621.msi
来源:http://www.activestate.com/activeperl/downloads

2.下载最新的AWStats:
AWStats 6.9正式版是2008年底发布的,因此下载7.0beta版来:
http://awstats.sourceforge.net/files/awstats-7.0.tar.gz
来源: http://awstats.sourceforge.net/

3.下载准备插件
GeoLiteCity.dat
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
来源:http://www.maxmind.com/app/geolitecity
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
来源:http://www.maxmind.com/app/geolitecountry
http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
来源:http://www.maxmind.com/app/asnum
http://www.ieasy.org/download/qqwry.pl
http://www.ieasy.org/download/qqhostinfo.pm
来源:http://www.ieasy.org/reload/cat2/awstats_qqhosti.html
geoip插件的依赖库:http://geolite.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.25.tar.gz
来源:http://www.maxmind.com/app/perl

4.将下载的awstats-7.0.tar.gz!/awstats-7.0/wwwroot/解压成/usr/local/app/resin/webapps/awstats/

建立 /usr/local/app/resin/webapps/awstats/WEB-INF/resin-web.xml,内容如下:

<web-app xmlns=”http://caucho.com/ns/resin”
xmlns:resin=”urn:java:com.caucho.resin”>

<servlet >
<servlet-name>cgi</servlet-name>
<servlet-class>com.caucho.servlets.CGIServlet</servlet-class>
<!–下面三个是可配置的参数,参考:http://www.caucho.com/resin-javadoc/com/caucho/servlets/CGIServlet.html
<init>
<executable>C:\\Perl\\bin\\perl</executable>
<ignoreExitCode>false</ignoreExitCode>
<stderrIsException>true</stderrIsException>
</init>
–>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>*.pl</url-pattern>
</servlet-mapping>

<session-config>
<use-persistent-store/>
</session-config>
<!–
– Security configuration
–>
<resin:BasicLogin realmName=”awstats statistics”/>
<resin:Deny>
<url-pattern>*.conf</url-pattern>
<url-pattern>*.pm</url-pattern>
<url-pattern>*.txt</url-pattern>
</resin:Deny>

<resin:Allow url-pattern=”/*”>
<resin:IfUserInRole role=”awstats_role”/>
</resin:Allow>

<resin:XmlAuthenticator password-digest=”none”>
<resin:user name=”awstats” password=”awstats” group=”awstats_role”/>
</resin:XmlAuthenticator>

</web-app>

5.安装Geo-IP-PurePerl组件:
root@lizongbo.com:/usr/local/app# wget http://geolite.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.25.tar.gz
root@lizongbo.com:/usr/local/app# tar -zxvf Geo-IP-PurePerl-1.25.tar.gz
root@lizongbo.com:/usr/local/app# cd Geo-IP-PurePerl-1.25
root@lizongbo.com:/usr/local/app/Geo-IP-PurePerl-1.25# perl Makefile.PL
root@lizongbo.com:/usr/local/app/Geo-IP-PurePerl-1.25# make
root@lizongbo.com:/usr/local/app/Geo-IP-PurePerl-1.25# make test
root@lizongbo.com:/usr/local/app/Geo-IP-PurePerl-1.25# make install

6.在/usr/local/app/resin/webapps/awstats/cgi-bin/下面建立awstats.localhost.conf配置,内容如下:

Include=”awstats.model.conf”
LogFile=”/usr/local/app/resin/log/access.log.%yyyy%MM%dd”
SiteDomain=”localhost”
LoadPlugin=”decodeutfkeys”
LoadPlugin=”hashfiles”
LoadPlugin=”tooltips”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD  /usr/local/app/resin/webapps/awst
ats/cgi-bin/plugins/GeoLiteCity.dat”
LoadPlugin=”geoip GEOIP_STANDARD /usr/local/app/resin/webapps/awstats/cgi-bin/pl
ugins/GeoIP.dat”
LoadPlugin=”geoip_asn_maxmind  GEOIP_STANDARD  /usr/local/app/resin/webapps/awst
ats/cgi-bin/plugins/GeoIPASNum.dat”
LoadPlugin=”qqhostinfo”

LogFormat=1
HostAliases=”localhost lizongbo.com 127.0.0.1 REGEX[^[a-zA-Z0-9]+\.lizongbo\.com$]”

DirIcons=”/awstats/icon”
DNSLookup=1
DirData=”.”
DirCgi=”/cgi-bin”

AllowToUpdateStatsFromBrowser=1

7.下载纯真ip库:
http://update.cz88.net/soft/ip_setup.exe
来源:http://www.cz88.net/fox/
运行ip_setup.exe安装之后,找到C:\Program Files\cz88.net\ip下面的qqwry.dat,上传到服务器的/usr/local/app/resin/webapps/awstats/cgi-bin/plugins。
root@lizongbo.com:/usr/local/app/resin/webapps/awstats/cgi-bin/plugins# cp /usr/local/app/geoip/qqwry.dat  ./
由于linux下区分文件名大小写,所以必须将ip库文件名改成QQWry.Dat.
root@lizongbo.com:/usr/local/app/resin/webapps/awstats/cgi-bin/plugins# mv qqwry.dat  QQWry.Dat
参考:http://www.ieasy.org/reload/cat2/awstats_qqhosti.html
root@lizongbo.com:/usr/local/app/resin/webapps/awstats/cgi-bin/plugins# vi qqwry.pl
然后在  my $ipfile=”./QQWry.Dat”;
下面再插入下面一行:
my $ipfile=”${DIR}/plugins/QQWry.Dat”;

8.在命令行上测试一下:
root@lizongbo.com:/usr/local/app/resin/log# /usr/bin/perl /usr/local/app/resin/webapps/awstats/cgi-bin/awstats.pl -config=localhost -output
<html><body>
<br /><span style=”color: #880000″>
Error: Plugin load for plugin ‘decodeutfkeys’ failed with return code: Error: Can’t locate URI/Escape.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl . /usr/local/app/resin/webapps/awstats/cgi-bin/lib /usr/local/app/resin/webapps/awstats/cgi-bin/plugins) at (eval 3) line 1.

</span><br />
<br /><b>Setup (‘/usr/local/app/resin/webapps/awstats/cgi-bin/awstats.localhost.conf’ file, web server or permissions) may be wrong.</b><br />
Check config file, permissions and AWStats documentation (in ‘docs’ directory).
</body></html>

根据错误信息提示,需要安装URI组件,于是下载: http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.56.tar.gz
来源:http://search.cpan.org/dist/URI/

root@lizongbo.com:/usr/local/app# wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.56.tar.gz
root@lizongbo.com:/usr/local/app# tar -zxvf URI-1.56.tar.gz
root@lizongbo.com:/usr/local/app# cd URI-1.56
root@lizongbo.com:/usr/local/app/URI-1.56# perl Makefile.PL
root@lizongbo.com:/usr/local/app/URI-1.56# make
root@lizongbo.com:/usr/local/app/URI-1.56# make test
root@lizongbo.com:/usr/local/app/URI-1.56# make install

root@lizongbo.com:/usr/local/app/resin/webapps/awstats/cgi-bin/plugins# ls -alh *.dat
-rw-r–r– 1 root root 1.1M Oct 30 10:40 GeoIP.dat
-rw-r–r– 1 root root 3.5M Oct 30 10:40 GeoIPASNum.dat
-rw-r–r– 1 root root  30M Oct 30 10:40 GeoLiteCity.dat
-rw-r–r– 1 root root 8.1M Oct 30 10:40 qqwry.dat

9.在浏览器中访问:http://lizongbo.com/awstats/cgi-bin/awstats.pl?config=localhost
输入用户名awstats,密码:awstats,即可查看统计结果。

Windows的resin上运行awstats还需要安装perl插件:

开始菜单–>ActivePerl 5.12.2 Build 1202–>Perl Package Manager (实际命令是:C:\Perl\bin\wperl.exe -x ppm.bat)
输入URI,搜索到插件,然后选中点右键:Install URI 1.56。

windows下resin-web.xml里的cgi配置是:
<init>
<executable>C:\\Perl\\bin\\perl</executable>
<ignoreExitCode>true</ignoreExitCode>
</init>
否则会出下面的错误信息:
java.io.IOException: Cannot run program “/usr/bin/perl” (in directory “D:\3gdev\Java\resin-4.0.10\webapps\awstats\cgi-bin”):
CreateProcess error=3, ???????
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at com.caucho.servlets.CGIServlet.service(CGIServlet.java:211)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:131)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183)
at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:92)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:789)
at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:662)
at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:625)
at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:576)
at com.caucho.network.listen.TcpSocketLink$AcceptTask.doTask(TcpSocketLink.java:1159)
at com.caucho.network.listen.TcpSocketLink$ConnectionReadTask.runThread(TcpSocketLink.java:1092)
at com.caucho.network.listen.TcpSocketLink$AcceptTask.run(TcpSocketLink.java:1126)
at com.caucho.env.thread.ResinThread.runTasks(ResinThread.java:170)
at com.caucho.env.thread.ResinThread.run(ResinThread.java:126)
不过我配置之后通过浏览器访问时还是出现了下面的出错信息:
javax.servlet.ServletException: CGI execution failed.  Exit code -1072365564
at com.caucho.servlets.CGIServlet.service(CGIServlet.java:296)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
at com.caucho.server.security.SecurityFilterChain.doFilter(SecurityFilterChain.java:131)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:183)
at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:92)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:286)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:789)
at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:662)
at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:625)
at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:576)
at com.caucho.network.listen.TcpSocketLink$AcceptTask.doTask(TcpSocketLink.java:1159)
at com.caucho.network.listen.TcpSocketLink$ConnectionReadTask.runThread(TcpSocketLink.java:1092)
at com.caucho.network.listen.TcpSocketLink$AcceptTask.run(TcpSocketLink.java:1126)
at com.caucho.env.thread.ResinThread.runTasks(ResinThread.java:170)
at com.caucho.env.thread.ResinThread.run(ResinThread.java:126)

-1072365564 就是 cgi perl 0xc0150004,可惜在网上搜索了很久,也没找到有用的信息。
儿通过dos夏的命令行运行却是能正常执行的。

相关参考:http://blog.chinaunix.net/u/31550/showart_317525.html

在Tomcat中通过cgi安装配置awstats:

http://618119.com/archives/2007/12/07/41.html

2010年10月24日

在Ubuntu 10.04上安装JDK1.6.0_21和编译配置Resin4.0.12

Filed under: Java,JVM,Linux,Resin,RMI — 标签:, , , , , , , — lizongbo @ 00:37

在Ubuntu 10.04上安装JDK1.6.0_21和编译配置Resin4.0.12

1.首先是安装最新版的jdk,先下载JDK 1.6.0_21(来源:http://www.oracle.com/technetwork/java/javase/downloads/index.html):
root@618119.com:/usr/local/app$ wget “http://cds.sun.com/***/jdk-6u21-linux-x64.bin”
这个url里带有会话信息,现在已经无效,JDK的官方下载不提供简洁的下载地址,需要每次到页面区获取下载地址)
2.再将下载到的文件改名:
root@618119.com:/usr/local/app$ mv jdk-6u21-linux-x64.bin\?BundledLineItemUUID\=SSeJ_hCwV9QAAAEroI4AHoII\&OrderID\=gVSJ_hCwmL8AAAErko4AHoII\&ProductID\=xKiJ_hCySHIAAAEpT7wzBGsB\&FileName\=%2Fjdk-6u21-linux-x64.bin   jdk-6u21-linux-x64.bin
3.给安装程序加上可执行权限:
root@618119.com:/usr/local/app$ chmod +x ./jdk-6u21-linux-x64.bin
4.开始安装JDK:
root@618119.com:/usr/local/app$ ./jdk-6u21-linux-x64.bin
(JDK安装好之后,可以通过符号连接建立jdk目录,这样在一行升级jdk版本的时候通过修改符号连接自动切换到新版本jdk:
root@618119.com:/usr/local/app# ln -s ./jdk1.6.0_21/ ./jdk )
5.然后添加环境变量到系统:
编辑 /etc/enviroment增加下面一行:
JAVA_HOME=”/usr/local/app/jdk1.6.0_21″
添加后的/etc/environment内容如下:
root@618119.com:/etc# more /etc/environment
PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”
JAVA_HOME=”/usr/local/app/jdk1.6.0_21″
6.再开始下载resin4.0.12(来源:http://www.caucho.com/download/)
root@618119.com:/usr/local/app# wget http://www.caucho.com/download/resin-4.0.12.tar.gz
7.解压安装文件:
root@618119.com:/usr/local/app# tar -zxvf resin*
7.进入resin目录开始编译安装,安装目录设置为:/usr/local/app/resin
root@618119.com:/usr/local/app# cd resin*
root@618119.com:/usr/local/app/resin-4.0.12# ./configure –prefix=/usr/local/app/resin
root@618119.com:/usr/local/app/resin-4.0.12# make
root@618119.com:/usr/local/app/resin-4.0.12# make install
8.可以看到系统服务脚本已经生成:
root@618119.com:/etc/init.d# more /etc/init.d/resin
9.尝试启动resin 4.0.12,失败了:
root@618119.com:/usr/local/app/resin/log# /usr/local/app/resin/bin/resin.sh start启动不了:
启动不了的原因是因为是root登录的。
Resin从4.0版本起,在默认的resin.xml里配置判断条件,如果当前用户名是root,则resin的watchdog监控进程使用www-data这个用户名来启动真正的resin进程。
root@618119.com:/usr/local/app/resin/bin# ./resin.sh start
然后root@618119.com:/usr/local/app/resin/bin# ./resin.sh shutdown
root@618119.com:/usr/local/app/resin/bin# tail ../log/*.log
可以看到出错日志如下:
—————————————————————————–

com.caucho.config.ConfigRuntimeException: java.io.IOException: Cannot create directory: /usr/local/app/resin/resin-data/default
at com.caucho.config.ConfigException.create(ConfigException.java:168)
at com.caucho.server.resin.Resin.configure(Resin.java:1006)
at com.caucho.server.resin.Resin.initMain(Resin.java:983)
at com.caucho.server.resin.Resin.main(Resin.java:1230)
Caused by: java.io.IOException: Cannot create directory: /usr/local/app/resin/resin-data/default
at com.caucho.vfs.FilePath.mkdirs(FilePath.java:489)
at com.caucho.env.service.RootDirectoryService.<init>(RootDirectoryService.java:81)
at com.caucho.server.resin.Resin.configureRoot(Resin.java:1073)
at com.caucho.server.resin.Resin.configure(Resin.java:1001)
… 2 more

—————————————————————————–

[2010/10/18 15:35:45.200] http listening to localhost:6600
[2010/10/18 15:35:45.289]
[2010/10/18 15:35:47.084] Watchdog detected close of Resin[,pid=20430]
exit reason: BAD_CONFIG (exit code=2)
[2010/10/18 15:35:48.814] Watchdog detected close of Resin[,pid=20454]
exit reason: BAD_CONFIG (exit code=2)
[2010/10/18 15:35:50.563] Watchdog detected close of Resin[,pid=20476]
exit reason: BAD_CONFIG (exit code=2)
[2010/10/18 15:35:52.470] Watchdog detected close of Resin[,pid=20508]
exit reason: BAD_CONFIG (exit code=2)

—————————————————————————–

10.解决办法为:注释resin.xml里的第147到150行:
root@618119.com:/usr/local/app/resin/conf# vi ./resin.xml

147 <!–      <resin:if test=”${resin.userName == ‘root’}”>
148         <user-name>www-data</user-name>
149         <group-name>www-data</group-name>
150       </resin:if> –>

11.然后再运行
root@618119.com:/usr/local/app/resin/bin# ./resin.sh start
或者root@618119.com:/usr/local/app/resin/bin# /etc/init.d/resin start
均可正常启动了。

12.再运行下面的命令将resin也添加为系统默认的服务:
root@618119.com:/etc# sudo /usr/sbin/update-rc.d -f resin defaults

13.修改resin配置允许外网访问resin-admin,编辑/usr/local/app/resin/conf/resin.xml,找到
<resin:set var=”resin_admin_external” value=”false”/>
改为:
<resin:set var=”resin_admin_external” value=”true”/>
保存resin.xml,重启resin。
root@618119.com:/usr/local/app/resin/conf# /usr/local/app/resin/bin/resin.sh restart

14:访问http://618119.com:8080/resin-admin/,因为是第一次访问,可以生成帐号和密码。
我的username设置为:resinadmin,Password设置为:618119.com(密码一定要用不容易被人猜到的),Realm保持为resin不变。
点“Create Configuration File”进行提交,生成的文件为:/usr/local/app/resin/conf/admin-users.xml.generated
15.将生成的文件改名为admin-users.xml:
root@618119.com:/usr/local/app/resin/conf# mv admin-users.xml.generated  admin-users.xml
然后resin会自动重新加载.
16.再访问http://localhost:8080/resin-admin/,输入刚才帐号和密码,登录之后,就可以看到服务器状态信息了。

接下来配置外网访问JMX管理。
由于jdk的jmx管理端口启动时无法绑定指定的ip,默认是绑定到所有ip的,因此在公网上开放jmx端口时,必须设置jmx访问的帐号和密码:
操作步骤如下:
在/usr/local/app/resin/conf建立jmx权限配置文件:
1.复制jdk提供的jmx帐号和密码配置文件模板到resin的conf目录:
root@618119.com:/usr/local/app/resin/conf# cp /usr/local/app/jdk1.6.0_21/jre/lib/management/jmxremote.* /usr/local/app/resin/conf
查看文件:
root@618119.com:/usr/local/app/resin/conf# ls -alh jmxremote.*
-rw-r–r– 1 root root 4.0K Oct 23 14:49 jmxremote.access
-r–r–r– 1 root root 2.8K Oct 23 14:49 jmxremote.password.template
2.在/usr/local/app/resin/conf下重命名:jmxremote.password.template为jmxremote.password:
root@618119.com:/usr/local/app/resin/conf# mv jmxremote.password.template  jmxremote.password
3.给密码文件加上写权限:
root@618119.com:/usr/local/app/resin/conf# chmod +w jmxremote.password
查看文件:
root@618119.com:/usr/local/app/resin/conf# ls -alh jmxremote.*
-rw-r–r– 1 root root 4.0K Oct 23 14:49 jmxremote.access
-rw-r–r– 1 root root 2.8K Oct 23 14:49 jmxremote.password
4.以追加文件方式往jmx权限控制文件中加入一个有读写权限的帐号,帐号名字是resinjmx
root@618119.com:/usr/local/app/resin/conf# echo “resinjmx         readwrite” >> jmxremote.access
查看帐号添加是否ok:
root@618119.com:/usr/local/app/resin/conf# tail jmxremote.access
# Default access control entries:
# o The “monitorRole” role has readonly access.
# o The “controlRole” role has readwrite access and can create the standard
#   Timer and Monitor MBeans defined by the JMX API.

monitorRole   readonly
controlRole   readwrite \
create javax.management.monitor.*,javax.management.timer.* \
unregister
resinjmx         readwrite
5.往jmx权限控制的密码文件中加入resinjmx帐号的密码:618119
root@618119.com:/usr/local/app/resin/conf# echo “resinjmx 618119” >> jmxremote.password
查看密码信息是否添加ok:
root@618119.com:/usr/local/app/resin/conf# tail jmxremote.password
# or specify another, less accessible file in the management config file
# as described above.
#
# Following are two commented-out entries.  The “measureRole” role has
# password “QED”.  The “controlRole” role has password “R&D”.
#
# monitorRole  QED
# controlRole   R&D

resinjmx 618119

6.修改jmxremote.*的权限,只允许启动resin的用户名对该文件拥有读写权限:
root@618119.com:/usr/local/app/resin/conf# chmod 600 jmxremote.access
root@618119.com:/usr/local/app/resin/conf# chmod 600 jmxremote.password
root@618119.com:/usr/local/app/resin/conf# ls -alh jmxremote.*
-rw——- 1 root root 4.0K Oct 23 14:54 jmxremote.access
-rw——- 1 root root 2.9K Oct 23 14:57 jmxremote.password
(如果文件权限没有正确设置,在启动使用了jmx的resin时,jvm-default.log中的出错信息为:
Error: Password file read access must be restricted: /usr/local/app/resin//conf/jmxremote.password,可以参考:http://www.opennms.org/wiki/Tomcat_6_JMX_How-To
)
7.配置/usr/local/app/resin/conf的resin.xml
在<server-default>节点下加入下列启动参数,并保存resin.xml
<!–
需要在远程服务器上运行hostname -i,如果显示的127.0.0.1,则需要加上下面一行来指定hostname为公网ip
<jvm-arg>-Djava.rmi.server.hostname=75.126.115.214</jvm-arg>
配置该项的时候,java.rmi.server.hostname=127.0.0.1是肯定不行的,我就是这样绕了弯路:
root@618119.com:/usr/local/app/resin/log# hostname -i
75.126.115.214
–>
<jvm-arg>-Dcom.sun.management.jmxremote.port=50000</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote.ssl=false</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote.authenticate=true</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote.password.file=${resin.root}/conf/jmxremote.password</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote.access.file=${resin.root}/conf/jmxremote.access</jvm-arg>

8.重启resin:
root@618119.com:/usr/local/app/resin/conf# /usr/local/app/resin/bin/resin.sh shutdown
Resin/4.0.12 shutdown watchdog at 127.0.0.1:6600
root@618119.com:/usr/local/app/resin/conf# /usr/local/app/resin/bin/resin.sh start
Resin/4.0.12 launching watchdog at 127.0.0.1:6600
Resin/4.0.12 started -server ” for watchdog at 127.0.0.1:6600

9.在本地电脑运行/usr/local/app/jdk1.6.0_21/bin/jconsole,远程进程填上:618119.com:50000,
点“连接”,提示连接失败。
重新在用户名填resinjmx,口令填:618119.com.
连接成功。

resin.xml中的其它设置:
1.resin4.0默认启动了https端口在8443,可以将resin.xm中下面几行注释掉来关闭https功能:

<http address=”127.0.0.1″ port=”8443″>
<jsse-ssl self-signed-certificate-name=”resin@localhost”/>
</http>
2.resin4.0的resin.xml里没将stdout和stderr显示的声明出来了,
可以将stdout,stderr,accesslog配置成按天输出:
<stdout-log path-format=”log/stdout.log.%Y%m%d”
timestamp=”%Y-%m-%d %H:%M:%S”
rollover-period=”1D”/>
<stderr-log path-format=”log/stderr.log.%Y%m%d”
timestamp=”%Y-%m-%d %H:%M:%S”
rollover-period=”1D”/>
<access-log path-format=”log/access.log.%Y%m%d”
format=’%h %l %u %t “%r” %s %b “%{Referer}i” “%{User-Agent}i” “%{X-Real-IP}i”‘
rollover-period=”1D”/>
stdout-log和stderr-log放到resin元素节点下面.
参考:http://618119.com/archives/2009/02/18/135.html

3.增加Java虚拟机 其它的jvm启动参数:
<!–以server方式启动java虚拟机–>
<jvm-arg>-server</jvm-arg>
<!–指定文件编码默认为UTF-8–>
<jvm-arg>-Dfile.encoding=UTF-8</jvm-arg>
<!–输出log4j自身的调试信息–>
<jvm-arg>-Dlog4j.debug=true</jvm-arg>
<!–指定默认语言为英语–>
<jvm-arg>-Duser.language=en</jvm-arg>
<!–启用gc日志–>
<jvm-arg>-verbose:gc</jvm-arg>
<!–指定输出gc日志的路径–>
<jvm-arg>-Xloggc:${resin.root}/log/gc.log</jvm-arg>
<!–gc日志打印gc详细信息–>
<jvm-arg>-XX:+PrintGCDetails</jvm-arg>
<!–gc日志打印时间戳–>
<jvm-arg>-XX:+PrintGCTimeStamps</jvm-arg>

4.配置泛域名方式的虚拟主机(将发给*.lizongbo.com的请求全部转给一个webapp):

<host id=”lizongbo.com” root-directory=”/usr/local/app/resin/vhost/lizongbo.com”>
<host-alias-regexp>^([^/]*).lizongbo.com</host-alias-regexp>
<web-app id=”/” root-directory=”webapps/ROOT”/>
</host>

(host-alias-regexp的正则表达式是用的java的Pattern.compile(name, Pattern.CASE_INSENSITIVE); ,因此是java的标准正则。

lizongbo.com是才申请的,因此使用301永久重定向跳转到 http://618119.com

index.jsp的代码为:<?xml version=”1.0″ encoding=”UTF-8″?>
<%@page contentType=”text/html; charset=UTF-8″ language=”java”
pageEncoding=”UTF-8″%>
<%@ page import=”java.util.*” session=”false”%>
<%
String goURL=”http://618119.com/”;
response.setHeader(“Location”, goURL);
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
%>)

5.通过ps aux|grep java可以看到最终启动的resin进程命令为:
/usr/local/app/jdk1.6.0_21/bin/java -server -Dfile.encoding=UTF-8 -Dcom.sun.management.jmxremote.port=50000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/usr/local/app/resin//conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/usr/local/app/resin//conf/jmxremote.access -Dlog4j.debug=true -Duser.language=en -verbose:gc -Xloggc:/usr/local/app/resin//log/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Dresin.server=1 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/app/resin/ -Xss1m -Xmx256m -Dresin.watchdog= -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/app/resin/ -Dresin.root=/usr/local/app/resin/ -Dresin.watchdog= -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/app/resin/ -Dresin.root=/usr/local/app/resin/ com.caucho.server.resin.Resin –root-directory /usr/local/app/resin/ -conf /usr/local/app/resin/conf/resin.xml -socketwait 37260 start –log-directory /usr/local/app/resin/log

Older Posts »

Powered by WordPress