Wednesday, December 28, 2011

mysql reset root password

http://www.cyberciti.biz/tips/recover-mysql-root-password.html

on fedora: /etc/init.d/mysqld
on debian: /etc/initd/mysql

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root 
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
/etc/init.d/mysql start

Wednesday, December 14, 2011

OpenLDAP


Install on ubuntu: 

sudo apt-get install slapd ldap-utils
sudo apt-get install phpldapadmin

sudo service apache2 restart
http://host/phpldapadmin

Reference

openldap-server.html
One correction: please quote the binding dn below in bash.

OpenLDAPServer

How to change RootDN 

/etc/ldap/slapd.d/cn=config/olcDatabase={1}hdb.ldif
olcDatabase={1}hdb.ldif:olcRootDN: cn=admin,dc=example,dc=com

How to change RootPWD
  • generate hash with slappasswd  
  • change RootPwd using the above generated hash. 
  • sudo service slapd restart
Clean Import 

  • service stop slapd
  • clean slapd db: rm -f /var/lib/ldap/*
  • slapadd -l .ldif
  • /var/lib/ldap$ sudo chown openldap:openldap * (make sure the ownership belongs to openldap)
  • service start slapd


Add entries

sudo ldapadd -x -D "cn=admin,dc=example,dc=com" -W -f frontend.example.com.ldif 
(it will prompt for password)


Search

  • ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
  • ldapsearch -x -b 'dc=example,dc=com' '(objectclass=*)'


Install python-ldap


  • sudo apt-get install build-essential python-dev libldap2-dev libssl-dev libsasl2-dev
  • pip install python-ldap


Thursday, December 8, 2011

increase Linux max number of FD limits


how to increase max fd

System level

  • sudo sysctl -w fs.file-max=100000
  • to survive the reboot: sudo vi /etc/sysctl.conf: fs.file-max = 100000

User level

  • sudo vi /etc/security/limits.conf:
    • uid soft nofile 4096
    • uid hard nofile 10240

VisualVM remote monitoring JVM

JMX set up for JVM argument



-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Wednesday, December 7, 2011

JVM GC tuning


HeapDump
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/home/blah/pid.hprof




Monday, December 5, 2011

nginx load balance


http {
 upstream mylb {
   server 127.0.0.1:9999;
   server 127.0.0.1:9998;
  }

  server {
   proxy_pass http://mylb
  }
}




Friday, November 25, 2011

install oracle instance client on ubuntu 11.10 x64


  • download *.rpm from oracle
  • sudo alien to install rpms
  • vi /etc/ld.so.conf.d/oracle-instantclient11.2-basic.conf 
    • /lib
    • /usr/lib/oracle/11.2/client64/lib
  • sudo ldconfig

Monday, November 21, 2011

mysql testdb


mysql> create database testdb;
Query OK, 1 row affected (0.03 sec)

mysql> create user 'testuser'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.06 sec)

mysql> use testdb;
Database changed
mysql> grant all on testdb.* to 'testdb'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges

mysql>select user, host from mysql.user;

Tuesday, November 8, 2011

DNS wildcard and DHCP with BIND vs dnsmasq


set up DNS wildcard for blah.dev

BIND configuration

/etc/bind/named.conf.local 
zone "dev" {
   type master;
   file "/etc/bind/db.dev";
};
run"named-checkconf named.conf.local"
/etc/bind/db.dev:  use the loopback address so the IP address is not affected by DHCP.
dev. 86400 IN SOA dev. hostmaster.dev. (
               20111101; serial yyyy-mm-dd
               10800; refresh every 15 min
                3600; retry every hour
                 3600000; expire after 1 month +
                86400 ); min ttl of 1 day
  IN NS dev.
  IN MX 10 dev.
  IN A 127.0.0.1
*.dev. IN A 127.0.0.1
named-checkzone dev db.dev

DHCP client configuration

  • uncomment the line in /etc/dhcp/dhclient.conf: prepend domain-name-servers 127.0.0.1;
  • sudo dhclient
  • sudo /etc/init.d/bind9 restart


Testing

ping blah.dev will return 127.0.0.1


Set up dnsmasq for local DNS cache and DHCP


disable dnsmasq from networkmanager

sudo vim /etc/NetworkManager.conf.  comment out dnsmasq
sudo service network-manager restart



Install and configure dnsmasq


  • sudo apt-get install dnsmasq
  • sudo vim /etc/dnsmasq.conf
  •     listen-address=127.0.0.1
  •     address=/dev/127.0.0.1
  •     address=/prod/127.0.0.1
  • sudo service dnsmasq restart


Set up Apache for vhost_alias
 

mod_vhost_alias
  • sudo a2enmod vhost_alias (this will enable module vhost_alias for loading). 
  • sudo vi /etc/apache2/mods-available/vhost_alias.conf    (create one if not existing)
<VirtualHost *:80>
# get the server name from the Host: header and put in %0

 # this is for dev
RewriteCond %{HTTP_HOST} ^mongo.dev$
RewriteRule (.*) http://localhost:28017/_replSet


RewriteCond %{HTTP_HOST} ^mongo.snap$
RewriteRule (.*) http://192.168.1.100:28000/_replSet



UseCanonicalName Off

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /var/www/vhosts/%0

<Directory />
# Global settings
Options FollowSymLinks
AllowOverride All
</Directory>

</VirtualHost>



Sunday, October 30, 2011

install Plone 4.1.x

Ubuntu: 11.10

Install all the required package
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install libxml2-dev
sudo apt-get install libbz2-dev
sudo apt-get install libjpeg62-dev
sudo apt-get install libreadline6-dev
 
 
./install.sh --target=/home/vyang/opt/plone --with-python=/usr/bin/python2.6 standalone 

Tuesday, October 25, 2011

Install RVM and Ruby



rvm, virutualenv

Remove ubuntu's ruby-rvm

sudo apt-get --purge ruby-rvm

Install 

curl -L https://get.rvm.io | bash -s stable
rvm list known
rvm install 1.9.3-head

Configuration (.bashrc)

 PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
source /home/victor.yang/.rvm/scripts/rvm




Install sproutcore

 Ubuntu 11.10

Step 1 has be done before step 2, otherwise the ruby will complain about "zlib not installed"

  1. apt-get install zlib1g-dev libssl-dev libreadline5-dev libxml2-dev libsqlite3-dev
  2. Follow steps in install sproutcore on linux



Monday, October 24, 2011

install sun-jdk 6, 7 on Ubuntu 12.04

 
http://www.devsniper.com/ubuntu-12-04-install-sun-jdk-6-7/
 
sudo update-alternatives --config java
sudo update-alternatives --config javac
 
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1 

Tuesday, October 11, 2011

Python study notes

python overview
  • abstraction: 
    • type: dynamic binding, strong type(for catching bugs)
    • object is first class:objects can be freely passed around, inspected, and placed in various data structures (e.g., lists or dictionaries) at run-time.
  • organizing code: package, module, class,method, function. 
  • flow control: if/else,while, iterator,generator, coroutine
  • error handling: try/except/finally
History of Python builtin types   
  • Influenced by ABC

python user defined class design
  • runtime data structure of instances and class, inheritance
    • instance dict, class dict
  • why "self" is needed
  • class implementation requires no special syntax: just a collection of functions (methods), variables (class variables), computed attributed(properties).  
  • new style classes
    • __new__(cls,*args,**kwargs) is used for change value for subclassing immutable type  
  • Attributes,Properties and Descriptors 
  • History of descriptor,staticmethod, classmethod, property
  • metaclass explained: metaclass 
    • type(name, bases, dict) Return a new type object. This is essentially a dynamic form of the class statement. Python will look for __metaclass__ in the class definition. If it finds it, if will use it to create the object class Foo. If it doesn't, it will use type to create the class.
       

object is first class
  • how to make method first class? via bound and unbound method
every statement is treated the same
  • benefit: share the same grammar rule, and hence the compiler could use the same byte code generation function for all of them.
exception design
  • early days implemented as string token (from Modula-3) 
  • user defined class as replacement


Monday, October 10, 2011

cpython source code study note





Python 2.7.2 source code
  • main():Modules/python.c 
  • Py_Main():Modules/main.c
  • Py_Initialize(): Python/pythonrun.c
    • PyRun_SimpleFileExFlags
    • PyRun_FileExFlags
      • PyParser_ASTFromFile returns AST module
        • Parser build CST: PyParser_ParseFileFlagsEx: Parser/parsetok.c
        • Transform CST to AST: PyAST_FromNode(): Python/ast.c
      • run_mod(mod) 
        • PyAST_Compile(mod) compile AST into byte code
        • PyEval_EvalCode runs the byte code
    • create first interpreter PyInterperterState_New()
    • create first thread PyThreadState_New()
    • initialize __builtin__ module: _PyBuiltin_Init()
    • initialize sys module: _PySys_init()

Saturday, September 17, 2011

DNS query tracing

dig @dns.server target.dns +tracing
watch it under wireshark, It is very useful to understand how DNS query works especially for a non-cached look up.
  • As a DNS client, dig will send a standard DNS query to the target DNS server via UDP port 53. 
  • For a non-cached look up, dig will ask the answer from root server, TLD (Top Level Domain) server, specific domain server in that order.

Sunday, September 11, 2011

Packet crafting and sniffing with Python extensions

  • libpcap: sudo apt-get install libpcap-dev
  • download and install pypcap, dpkt, dnet
  • pypcap 's installation is tricky: download the pyrex and recompile the pcap.pyx file will work. Furthermore, use Makefile instead of setup.py seems fixed issues.

Friday, January 21, 2011

Tab to space for indentation: Configure Eclipse and Pydev editors

Configure Eclipse and Pydev editors
  • Go to "Window > Preferences > General > Editors > Text Editors"
  • Set "Displayed tab width" to 4 and make sure "Insert spaces for tabs" is checked
  • Go to "Window > Preferences > Pydev > Editor"
  • Set "Tab length" to 4 and make sure "Replace tabs with spaces..." is checked

Oracle Net: TNS and EasyConnect


  1. sqlplus id/pwd@
  2. sqlplus id/pwd@server:port/service (service is schema that is given by DBA)