Latest Entries »

I’m developing a s smart map service.

Hope it will open soon.

Just a quick shot of the data we collected for 3 weeks

result_0521


# This procedure will take capture for a process
 
cat /proc/[PID]/maps
# find memory address
00622000-0066a000 rw-p 00622000 00:00 0                                  [heap]
 
gdb --pid [PID]
(gdb) dump memory /root/[outputfile] 0x00621000 0x00622000
 
xdd [outputfile] > [outputfile].hex
 
vimdiff [outputfile]1.hex [outputfile]2.hex

link: https://gist.github.com/fortable1999/1733b49002a30904aa00

setup salt minion

setup salt minion

on minion side:


curl -L https://bootstrap.saltstack.com -o install_salt.sh
sudo sh install_salt.sh git develop
sed -i 's/#master: salt/master: master.com/g' /etc/salt/minion
sed -i 's/#id:/#id: worker01/g' /etc/salt/minion
salt-minion -d
ps aux | grep minion

on master side:


salt-key -L
salt-key -A
salt '*' test.ping

Server restart manual

AFTER RESTART:
1. restart nginx
2. restart postgresql


/usr/local/bin/postmaster -D /usr/local/postgresql/data > postgresql.log 2>&1 &

3. restart rabbitmq


/etc/init.d/rabbitmq-server start

4. restart postfix/dovecot
5. open iptables
6. restart django


$ ssh -i XXX.pem ec2-user@xxx.xxx.xxx.xxx

[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ cat <<EOF > python_install.sh
  cd /root
  mkdir Downloads
  cd Downloads/
  wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz
  wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
  tar -xzvf Python-3.4.1.tgz 
  tar -xzvf Python-2.7.8.tgz 
  yum install -y gcc ncurses-devel ncurses-libs ncurses sqlite-devel readline-devel openssl-devel xz-devel bzip2-devel
  cd Python-3.4.1
  ./configure --prefix=/usr/local/python-3.4.1
  make
  make install
  cd Python-2.7.8
  ./configure --prefix=/usr/local/python-2.7.8
  make
  make install
  echo 'export PATH=/usr/local/python-3.4.1/bin:/usr/local/python-2.7.8/bin:$PATH' >> /home/ec2-user/.bashrc
EOF

[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo su root python_install.sh
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ source ~/.bashrc

Django Tips & Hacks

take care of __unicode__ for model

take care of reverse_lazy

Using template to start app: https://github.com/fortable1999/dj-app

Install using yum

yum install postfix dovecot libgsasl-devel

Edit Dovecot configure

1. config dovecot.conf

vim /etc/dovecot/dovecot.conf


add/uncomment these

protocols = imap pop3
mail_location = maildir:~/Maildir
listen = *

2. config 10-mater.conf

vim /etc/dovecot/conf.d/10-master.conf


add these lines into service auth {…}

 unix_listener /var/spool/postfix/private/auth {
 mode = 0666
 user = postfix
 group = postfix
}

Config Postfix

vim /etc/postfix/main.cf

Add these lines:

mydomain = XXX.com
myorigin = $mydomain
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# mynetworks_style = host
virtual_mailbox_domains = hash:/etc/postfix/virtual
relay_domains = gmail.com, google.com, xxx.com

virtual_alias_maps = hash:/etc/postfix/virtual
home_mailbox = Maildir/

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
# smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, check_relay_domains
smtpd_recipient_restrictions =
        permit_sasl_authenticated,
        reject_unauth_destination,
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

restart server

/etc/init.d/dovecot restart
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

nginx


# nginx installation
sudo useradd nginx
sudo yum instal pcre-devel
cd ~/Downloads
wget http://nginx.org/download/nginx-1.5.12.tar.gz
tar -xzvf nginx-1.5.12.tar.gz
cd nginx-1.5.12
./configure --prefix=/usr/local/nginx
make
sudo make install
sudo chown -R nginx:nginx /usr/local/nginx

postgres


# postgresql installation
cd ~/Downloads
wget http://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz
tar -xzvf postgresql-9.3.4.tar.gz
cd postgresql-9.3.4
./configure --prefix=/usr/local/postgresql
make
make install
sudo createuser postgres
sudo passwd postgres
# initial database
mkdir /usr/local/postgresql/data
chown postgres:postgres -R /usr/local/postgresql/data
su - postgres
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
# start postgresql
/usr/local/postgresql/bin/postmaster -D /usr/local/postgresql/data/ > postgresql.log 2>&1 &
cat postgresql.log
# create database
/usr/local/postgresql/bin/createdb testdb
/usr/local/postgresql/bin/psql testdb

elasticsearch

cd ~/Downloads/
wget http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz
tar -xzvf jdk-7u51-linux-x64.tar.gz
sudo mv jdk1.7.0_51 /usr/local/.
sudo cp -si /usr/local/jdk1.7.0_51/bin/* /usr/local/bin/
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.tar.gz
tar -xzvf elasticsearch-1.1.0.tar.gz
sudo mv elasticsearch-1.1.0 /usr/local/.
sudo useradd elasticsearch
sudo chown -R elasticsearch:elasticsearch /usr/local/elasticsearch-1.1.0



memcahced installation


# memcached installation
sudo yum install libevent-devel
cd ~/Downloads/
wget http://www.memcached.org/files/memcached-1.4.17.tar.gz
tar -xzvf memcached-1.4.17.tar.gz 
cd memcached-1.4.17
./configure --prefix=/usr/local/memcached
make
sudo make install
# start memcached
/usr/local/memcached/bin/memcached &

test


# install Python 3.3.5
sudo yum install ncurses-devel ncurses-libs ncurses sqlite-devel readline-devel openssl-devel xz-devel bzip2-devel
mkdir ~/Downloads
cd ~/Downloads
wget wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tgz
tar -xvf Python-3.3.5.tgz
cd Python-3.3.5
./configure --prefix=/usr/local/python-3.3.5
make
sudo make install
cp -s /usr/local/python-3.3.5/ /usr/local/bin
cp -s /usr/local/python-3.3.5/ /usr/bin

# create virutalenv for mangaconnect
cd ~
pyvenv-3.3 production_env
cd production_env
source bin/activate
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py

Zhao’s Git cheat sheet

—–Not completed————-

Difference comparing

  • compare two different branch:
    
     git diff dev master
     
  • compare one file in different branch:
    
     git diff dev master -- hello.py
     

Rollback

  • undo one commit:
    
    git reset HEAD^ --soft
    
  • undo 3 commit:
    
    git reset HEAD^3 --soft
    
Follow

Get every new post delivered to your Inbox.