Saturday, March 13, 2010

linux find command - to find file with some content

find files with password under folder /opt/activemq

sudo find /opt/activemq/ -exec grep -l  password {} \;


sudo find /opt/SWS_4/ -exec grep -l "sigTypeList" {} \;


find .  -name "*.log" | xargs grep "localhost post"


Tuesday, March 9, 2010

enable mysql slow query log in my.cnf

Step 1:  add following two line under mysqld
[mysqld]
log-slow-queries=/var/log/mysql-slow.log
long_query_time = 10

step 2: create an empty log file and chage the owner
  vim /var/log/mysql-slow.log
  chown mysql:mysql /var/log/mysql-slow.log

step 3: reboot mysql
  /etc/init.d/mysqld stop
  /etc/init.d/mysqld start

Saturday, February 27, 2010

ssh scp without password

Issue: How to login (ssh or scp) from your homepc to your remote server without password.

Solution:
1, in your homepc




bob@homepc ~ $ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa):     # Press 'enter' here
Enter passphrase (empty for no passphrase):     # Press 'enter' here
Enter same passphrase again:     # Press 'enter' here
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.

# Entering a password when asked during the key generation processes when prompted would require you to enter a  password each time you SSH/SCP to the server which defeats the purpose of this document.

DO NOT enter the password



You will find two files generated:
greg


@cm-test:~/.ssh$ ls

id_dsa  id_dsa.pub  known_hosts



Then scp  

id_dsa.pub to you remote server
scp  ~/.ssh/id_dsa.pub bob@yourserver.com:~/.ssh/


2, in your remote server
a, go to .ssh folder
cd ~/.ssh

b, add public key into this file  authorized_keys
run:
cat id_dsa.pub >> authorized_keys


If authorized_keys not exist, this command will create it.


c, change file permission
chmod 700 authorized_keys


You should be able to login to your server without password.




There are some tricks about the account:
In the home box, if your user name is bob, the public key and private key is on /home/bob/.ssh/ folder


If you want to log to remote server using account greg, then copy public key to remote server folder /home/greg/.ssh/


This case only allow home pc bob logon to remote server using greg account.








Monday, February 22, 2010

change host name without reboot - redhat

1, update hosts

vim /etc/hosts


# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       revolutionNew   localhost.localdomain localhost

2, update network

 cd /etc/sysconfig/
 vim network


NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=revolutionNew

3, run 

hostname revolutionNew

4, run
 hostname

5, restart network
  /etc/init.d/network restart

6, disconnect ssh and relogin

Friday, February 19, 2010

how to enable xmlwriter in php

By install php-xml, you may enable it.
[root@localhost html]# yum install php-xml

check:
[root@localhost html]# php -m
[PHP Modules]
bz2
calendar
ctype
curl
date
dbase
dom
exif
ftp
gettext
gmp
hash
iconv
libxml
mime_magic
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
posix
pspell
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zlib

how to redirect root to a specified path?

I want to redirect all incoming traffic from http://www.example.com https://www.example.com
to https://www.example.com/new

Step 1: enable overwrite in httpd.conf



    Options FollowSymLinks
    #AllowOverride None
    AllowOverride all


Step 2, generate .htaccess under root /




[root@localhost html]# pwd
vim /var/www/html/.htaccess




RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(/)?$  https://www.example.com/new/$1 [R,L]

error message - RewriteEngine not allowed here

If you try to redirect your root to a folder and got this error msg
for example:
redirect www.example.com/  www.example.com/new/

You may update https.conf


    Options FollowSymLinks
    #AllowOverride None
    AllowOverride all