Tuesday, January 11, 2011

import openssl key to tomcat

1. Generate a self-signed certificate (or CA trusted certificate if needed)
1) Generate a private key
openssl genrsa -des3 -out es.key 2048
2) Generate a CSR
openssl req -new -key es.key -out es.csr
 3) Generate a self-signed certificate
openssl x509 -req -days 3650 -in es.csr -signkey es.key -out es.crt

2, Import the SSL Ceritificate into PKCS#12 keystore:
openssl pkcs12 -export -in es.crt -inkey es.key -out es.p12 -name es_tomcat

3, list privatekeyentry
keytool -list -v -keystore es.p12 -storetype pkcs12

4,Import CA/cacert.crt into the Java cacerts, so that the tomcat install can talk to itself if needed.
keytool -import -keystore es.keystore -file es.crt

5, Covert the PKCS#12 keystore to JKS keystore
keytool -importkeystore -srckeystore es.p12 -destkeystore es.jks -srcstoretype pkcs12

keytool -list -v -keystore es.jks

6 update server.xml
vim /opt/tomcat/conf/server.xml




cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat stop
cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat start
less /opt/tomcat/logs/catalina.out

Friday, January 7, 2011

Thursday, January 6, 2011

clear mysql-bin log file or disable mysql bin log

Step 1,
Go to folder
/var/lib/mysql

Step 2:
Run:
[root@localhost mysql]# mysqladmin -u xxxx -pxxxx flush-logs

Mysql will create a new bin-log file - for my server it is mysql-bin.000014
-rw-rw---- 1 mysql mysql 22770974 Jan 6 04:02 mysql-bin.000011
-rw-rw---- 1 mysql mysql 79427070 Jan 6 04:04 mysql-bin.000012
-rw-rw---- 1 mysql mysql 109593 Jan 6 04:07 mysql-bin.000013
-rw-rw---- 1 mysql mysql 1318 Jan 6 04:07 mysql-bin.000014
-rw-rw---- 1 mysql mysql 266 Jan 6 04:07 mysql-bin.index

Step 3:
You can delete all mysql-bin log file except the latest one.
Here is the sample:
rm mysql-bin.000004 -f
rm mysql-bin.000005 -f
rm mysql-bin.000006 -f
rm mysql-bin.000007 -f
rm mysql-bin.00000* -f


Delete mysql bin log file older than 2 days
find /var/lib/mysql/mysql-bin.* -mtime +2 -exec rm {} \;

Thursday, December 16, 2010

ubuntu enable apache rewrite engine

root@SS:/# a2enmod rewrite
Module rewrite installed; run /etc/init.d/apache2 force-reload to enable.
root@SS:/# /etc/init.d/apache2 force-reload

Thursday, November 25, 2010

Adding a startup script to be run at bootup - ubuntu

513 mkdir startup
514 mv iptable-rules.20101124 startup/
515 cd startup/
516 ll
517 vim mybootup.sh
518 ll
519 cp mybootup.sh /etc/init.d/
520 chmod +x /etc/init.d/mybootup.sh
521 update-rc.d mybootup.sh defaults

Tuesday, November 23, 2010

Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

My OS is ubuntu.
I have issue when I try to run 'rake db:create'.
greg@cm-test:/mydisk/ruby/blog/config$ rake db:create
(in /mydisk/ruby/blog)
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.


Here is what I did to fix this issue
1, find current libmysqlclient for your system. Then install it
greg@cm-test:/mydisk/ruby/blog/config$ sudo apt-get install libmysqlclient15-dev

2, After install mysql lib, need to install gem mysql

greg@cm-test:/mydisk/ruby/blog/config$ sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

You need to find correct path for mysql_config
greg@cm-test:/mydisk/ruby/blog/config$ sudo updatedb
greg@cm-test:/mydisk/ruby/blog/config$ locate mysql_config

3, do bundle all
greg@cm-test:/mydisk/ruby/blog/config$ sudo bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.3)
Using builder (2.1.2)
Using i18n (0.4.2)
Using activemodel (3.0.3)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.3)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.10)
Using actionmailer (3.0.3)
Using arel (2.0.4)
Using activerecord (3.0.3)
Using activeresource (3.0.3)
Using bundler (1.0.7)
Installing mysql2 (0.2.6) with native extensions
Using thor (0.14.6)
Using railties (3.0.3)
Using rails (3.0.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

greg@cm-test:/mydisk/ruby/blog/config$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.3)
* actionpack (3.0.3)
* activemodel (3.0.3)
* activerecord (3.0.3)
* activeresource (3.0.3)
* activesupport (3.0.3)
* arel (2.0.4)
* builder (2.1.2)
* bundler (1.0.7)
* erubis (2.6.6)
* i18n (0.4.2)
* mail (2.2.10)
* mime-types (1.16)
* mysql2 (0.2.6)
* polyglot (0.3.1)
* rack (1.2.1)
* rack-mount (0.6.13)
* rack-test (0.5.6)
* rails (3.0.3)
* railties (3.0.3)
* rake (0.8.7)
* thor (0.14.6)
* treetop (1.4.9)
* tzinfo (0.3.23)

greg@cm-test:/mydisk/ruby/blog/config$ rake db:create
(in /mydisk/ruby/blog)

Thursday, November 18, 2010