Wednesday, August 21, 2013

Add CentOS6 Repo to Amazon AMI

Step 1, add centos.repo to /etc/yum.repos.d
[base]
name=CentOS-6 - Base
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=i386&repo=os
#baseurl=http://mirror.centos.org/centos/6/os/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
#[updates]
name=CentOS-6 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=i386&repo=updates
#baseurl=http://mirror.centos.org/centos/6/updates/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=i386&repo=extras
#baseurl=http://mirror.centos.org/centos/6/extras/i386/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=i386&repo=centosplus
#baseurl=http://mirror.centos.org/centos/6/centosplus/i386/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=i386&repo=contrib
#baseurl=http://mirror.centos.org/centos/6/contrib/i386/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

Step 2,
sudo rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

Tuesday, August 20, 2013

add swap to ec2 ubuntu

You can add a 1 GB swap to your instance with these commands:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
sudo mkswap /swapfile
sudo swapon /swapfile
To enable it by default after reboot, add this line to /etc/fstab:
/swapfile swap swap defaults 0 0

Thursday, August 8, 2013

Ubuntu Apache: how to hide server version and operation system from users?

1, find the file: conf.d/security
root@cmnew:/etc/apache2# less /etc/apache2/conf.d/security

2, change two parts;
ServerTokens Prod
ServerSignature Off

2, restart apache
root@cmnew:/etc/apache2# /etc/init.d/apache2 restart



Tuesday, August 6, 2013

get linux disk space data

freespace:
[root@ip-10-99-41-92 cloudwatch]# df --local --block-size=1M / | grep / |  tr -s ' ' | cut -d ' ' -f 4
6949







usedpercent
[root@ip-10-99-41-92 cloudwatch]# df --local /  | grep /  | tr -s ' ' | cut -d ' ' -f 5 | grep -o "[0-9]*"
13

[root@ip-10-99-41-92 cloudwatch]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda1             8256952   1057996   7115100  13% /
tmpfs                   304240         0    304240   0% /dev/shm

Wednesday, June 5, 2013

gem install rmagick failed

[root@Redmine config]# yum install ImageMagick-devel

gem install json "ERROR: Failed to build gem native extension."

[root@Redmine config]# yum install ruby-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.einstein.yu.edu
 * extras: mirrors.einstein.yu.edu
 * updates: centos.aol.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ruby-devel.i686 0:1.8.7.352-10.el6_4 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================
 Package                   Arch                Version                            Repository              Size
===============================================================================================================
Installing:
 ruby-devel                i686                1.8.7.352-10.el6_4                 updates                313 k

Transaction Summary
===============================================================================================================
Install       1 Package(s)

Total download size: 313 k
Installed size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
ruby-devel-1.8.7.352-10.el6_4.i686.rpm                                                  | 313 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ruby-devel-1.8.7.352-10.el6_4.i686                                                          1/1
  Verifying  : ruby-devel-1.8.7.352-10.el6_4.i686                                                          1/1

Installed:
  ruby-devel.i686 0:1.8.7.352-10.el6_4

Complete!
[root@Redmine config]# gem install json -v '1.8.0'
Building native extensions.  This could take a while...
Successfully installed json-1.8.0
Installing ri documentation for json-1.8.0
/usr/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block
/usr/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block
Done installing documentation for json after 1 seconds
1 gem installed
[root@Redmine config]#

Tuesday, April 30, 2013

Add a nagios service monitor

Step 1: Write a script to monitor service using any scripting languages. In this article, I use perl to monitor port 8888
=================================
root@restmq:/usr/local/nagios/etc/objects# less ~/nagios/checkrestmq.pl

#!/usr/bin/perl -w

my $restmq_result = `netstat -na | grep 8888` ;

#print "$restmq_result" ;
# OK  WARNING  UNKNOWN CRITICAL

if ($restmq_result)
{
   print "OK\n"
}
else
{
   print "CRITICAL\n"
}

Step 2 : Add this perl into nagios command.cfg
Default location:
/usr/local/nagios/etc/objects/commands.cfg

define command{
       command_name    check_restmq
       command_line    /home/chang/nagios/checkrestmq.pl
}

Step 3: Add this command into service localhost.cfg
 #check_restmq
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             RestMQ
        check_command                   check_restmq
        notifications_enabled           0
        }



Step 4: restart nagios
  /etc/init.d/nagios stop
  /etc/init.d/nagios start

install nagios 3.5 in ubuntu 12

  • Prerequirement
  105  apt-get install apache2 libapache2-mod-php5 build-essential
  106  apt-get install libgd2-xpm-dev
  107  /usr/sbin/useradd -m -s /bin/bash nagios
  108  passwd nagios
  109  /usr/sbin/groupadd nagcmd
  110  /usr/sbin/usermod -a -G nagcmd nagios
  111  /usr/sbin/usermod -a -G nagcmd www-data
  • Download Nagios
  114  mkdir download
  115  cd download/
  116  wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz
  117  wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

  • Install Nagios
  118  tar xvf nagios-3.5.0.tar.gz
  119  cd nagios/
  120  ./configure --with-command-group=nagcmd

=================================================================
General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/apache2/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):

  • Install latest ssl library
check which version is avaiable
apt-cache search libssl | grep SSL
libssl-dev - SSL development libraries, header files and documentation
libssl-doc - SSL development documentation documentation
libssl1.0.0 - SSL shared libraries
libssl-ocaml - OCaml bindings for OpenSSL (runtime)
libssl-ocaml-dev - OCaml bindings for OpenSSL
libssl0.9.8 - SSL shared libraries
libsslcommon2 - enterprise messaging system - common SSL libraries
libsslcommon2-dev - enterprise messaging system - common SSL development file

 Install SSL library
 apt-get install libssl1.0.0 libssl-dev
  • Install Nagios plugin
  133  tar xvf nagios-plugins-1.4.16.tar.gz
  134  cd nagios-plugins-1.4.16/
  135  ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  146  make
  147  make install


  • Start Nagios
Configure Nagios to automatically start when the system boots.
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.
/etc/init.d/nagios start

Monday, April 15, 2013

mongodb for ubuntu


 2003  mkdir /data
 2004  mkdir /data/db/
 2005  mongod --journal
 2006  nohup mongod --journal &

Thursday, April 11, 2013

install RESTMQ in Ubuntu 12 64

1, Update system

  apt-get update
  apt-get upgrade
  apt-get install make cpp gcc
  apt-get install tcl
  apt-get install git

2, install redis
    cd /opt/
   wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz
  
    tar zxvf redis-2.6.12.tar.gz
      
   rm redis-2.6.12.tar.gz
   cd redis-2.6.12/
   make

   make test
  
3, Install twiested
 apt-get install python python-twisted python-twisted-web python-openssl  python-setuptools intltool

 twistd
 
4, install RESTMQ
  cd /opt/
   git clone https://github.com/gleicon/restmq.git
   cd restmq/

   python setup.py install

   cd start_scripts/
 
   ./restmq_server --listen=192.168.88.50
  
5, Open browser, check restmq is running:
http://192.168.88.50:8888/p/test

ubuntu install twisted, redis, restmq

Step 1 : install twisted
root@restmq:~# apt-get install python python-twisted python-twisted-web python-openssl python-simplejson python-setuptools intltool python-xdg python-chardet geoip-database python-libtorrent python-notify python-pygame python-glade2 librsvg2-common xdg-utils python-mako

Step 2: install redis.

root@restmq:~# apt-get install make cpp gcc


==========================

Installing Redis: jemalloc/jemalloc.h: No such file or directory


make distclean


root@restmq:/opt/redis-2.6.12/src# ./redis-server ../redis.conf
root@restmq:/opt/redis-2.6.12/src# pwd
/opt/redis-2.6.12/src
root@restmq:/opt/redis-2.6.12/src# ps -ef | grep redis
root     28454     1  0 22:27 ?        00:00:00 ./redis-server ../redis.conf
root     28458 18551  0 22:27 pts/1    00:00:00 grep --color=auto redis
root@restmq:/opt/redis-2.6.12/src# telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.


Step 3: install restMQ:

==============================================

root@restmq:/opt/restmq/start_scripts# ./restmq_server --listen=192.168.1.44

Friday, April 5, 2013

install restmq

prerequirements:

 yum install python-devel openssl-devel

Install:
 git clone  git://github.com/gleicon/restmq.git

 cd restmq/
 python setup.py install


Friday, March 8, 2013

gem install bson_ext issue

root@FSAllInOne:/opt/scanjobs# gem install bson_ext
Building native extensions.  This could take a while...
ERROR:  Error installing bson_ext:
        ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
checking for asprintf()... yes
checking for ruby/st.h... yes
checking for ruby/regex.h... yes
checking for ruby/encoding.h... yes
creating Makefile

make
compiling encoding_helpers.c
compiling bson_buffer.c
compiling cbson.c
cbson.c: In function âpack_extraâ:
cbson.c:184:27: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
cbson.c: In function âwrite_elementâ:
cbson.c:194:28: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
cbson.c: In function âobjectid_generateâ:
cbson.c:999:9: warning: implicit declaration of function âhtonlâ [-Wimplicit-function-declaration]
cbson.c:1007:5: warning: implicit declaration of function âhtonsâ [-Wimplicit-function-declaration]
cbson.c: In function âwrite_elementâ:
cbson.c:300:17: warning: ignoring return value of âasprintfâ, declared with attribute warn_unused_result [-Wunused-result]
linking shared-object bson_ext/cbson.so

make install
/usr/bin/install -c -m 0755 cbson.so /usr/local/rvm/gems/ruby-2.0.0-p0/gems/bson_ext-1.8.3/ext/bson_ext/bson_ext
/usr/bin/install: cannot create regular file `/usr/local/rvm/gems/ruby-2.0.0-p0/gems/bson_ext-1.8.3/ext/bson_ext/bson_ext': No such file or directory
make: *** [install-so] Error 1


Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p0/gems/bson_ext-1.8.3 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.0.0-p0/gems/bson_ext-1.8.3/ext/cbson/gem_make.out

======================================================================

solution:
I reinstall ruby 1.9.3 and it worked
http://www.ruby-lang.org/en/news/2013/02/22/ruby-1-9-3-p392-is-released/
1234  cd ruby-1.9.3-p392/
 1236  ./configure
 1237  make
 1238  make install
 1249  gem install bson_ext

gem install qpid failure - ubuntu

need:

apt-get install libxml2 libxml2-dev
gem install libxml-ruby

Monday, March 4, 2013

mongodb ensureIndex not working

> db.FileScan_files.ensureIndex({md5:1},{unique:true})
> db.FileScan_files.insert({md5:""})
> db.FileScan_files.insert({md5:""})


md5 is a bad name for mongodb
MongoDB speaks JavaScript, so utilize JS naming conventions.

> db.FileScan_files.ensureIndex({md:1},{unique:true})
> db.FileScan_files.insert({md:""})
> db.FileScan_files.insert({md:""})
E11000 duplicate key error index: filescan.FileScan_files.$md_1  dup key: { : "" }

Thursday, February 21, 2013

Install pynids-0.6.1 in centos

Error:
Package requirements (glib-2.0 >= 2.2.0) were not met.

Fix:
1, do
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig


2, download  libnids-1.24
do:
./configure
make
make install

3, go to pynids-0.6.1

 python setup.py build
python setup.py install

Thursday, February 14, 2013

sed find and replace all file

[root@govd drupal]# find /var/www/drupal/ -type f -exec sed -i "s/Any\ unauthorized/AnyUnauthorized/g" {} \;
[root@govd drupal]# find /var/www/drupal/ -exec grep -l "Any unauthorized" {} \;

Thursday, February 7, 2013

install LAMP in ubuntu

a, update ubuntu
1 apt-get update
2 apt-get upgrade

b, install LAMP
apt-get install apache2 php5 libapache2-mod-php5 mysql-server php5-cli

Tuesday, February 5, 2013

node.js+mongoDB+bootStrap+ angularjs

 nodejs book
http://visionmedia.github.com/masteringnode/book.html

expressjs
http://expressjs.com/guide.html

================
1, install node.js
   29  wget http://nodejs.org/dist/v0.8.18/node-v0.8.18.tar.gz
   35  ./configure
   36  make
   32  yum search gcc
   33  yum install gcc-c++
   38  yum install mlocate
   40  updatedb
   54  /usr/local/bin/node
   55  /usr/local/bin/node --help
   56  /usr/local/bin/node -v

2,

centos 6 repo



File name:
 /etc/yum.repos.d/CentOS-Base.repo:


# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Monday, January 28, 2013

good linux tools


http://www.shutterstock.com/pic-108551444/stock-photo-intruder-detection-concept-in-word-tag-cloud-on-black-background.html

http://alienvps.com/vps-hosting/

http://www.cyberciti.biz/faq/howto-check-linux-rootkist-with-detectors-software/

Zeppoo Software

Zeppoo - Zeppoo allows you to detect rootkits on i386 and x86_64 architecture under Linux, by using /dev/kmem and /dev/mem. Moreover it can also detect hidden tasks, connections, corrupted symbols, system calls and so many other things. Download source code here

Chkrootkit Software

Chkrootkit - chkrootkit is a tool to locally check for signs of a rootkit. Type the following command to install chkrootkit
$ sudo apt-get install chkrootkit
Start looking for rootkits, enter:
$ sudo chkrootkit
Look for suspicious strings, enter:
$ sudo chkrootkit -x | less
You need to specify the path for the external commands used by chkrootkit such as awk, grep and others. Mount /mnt/safe using nfs in read-only mode and set /mnt/safe binaries PATH as trusted one, enter:
$ sudo chkrootkit -p /mnt/safe

rkhunter software

rkhunter - rkhunter (Rootkit Hunter) is a Unix-based tool that scans for rootkits, backdoors and possible local exploits. rkhunter is a shell script which carries out various checks on the local system to try and detect known rootkits and malware. It also performs checks to see if commands have been modified, if the system startup files have been modified, and various checks on the network interfaces, including checks for listening applications. Type the following command to install rkhunter:
$ sudo apt-get install rkhunter
The following command option tells rkhunter to perform various checks on the local system:
$ sudo rkhunter --check
The following command option causes rkhunter to check if there is a later version of any of its text data files:
$ sudo rkhunter --update
The following option tells rkhunter which directories to look in to find the various commands it requires:
$ sudo rkhunter --check --bindir /mnt/safe


Friday, January 25, 2013

Wednesday, January 16, 2013

remove / create windows softlink

1, run cmd as administrator

2, windows remove softlink
rmdir foldername

3, create softlink
C:\>mklink /D sitscape c:\Git\dev_lamp\sitscape
symbolic link created for sitscape <<===>> c:\Git\dev_lamp\sitscape

Thursday, January 3, 2013

http://www.d3-generator.com/

http://www.d3-generator.com/

http://www.jsoneditoronline.org/

http://alignedleft.com/tutorials/d3/making-a-bar-chart/

http://angularjs.org/