Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Last active December 13, 2015 15:49
Show Gist options
  • Save alejandrobernardis/4936980 to your computer and use it in GitHub Desktop.
Save alejandrobernardis/4936980 to your computer and use it in GitHub Desktop.
Python Environment

CentOS 6.3 Minimal Install


Update & Dependencies

$: yum update
$: yum install nano wget tree gcc gcc-c++ compat-gcc-34-c++ gcc-gfortran zlib zlib-devel bzip2 bzip2-devel openssl openssl-devel ncurses ncurses-devel sqlite sqlite-devel gdbm gdbm-devel readline readline-devel expat expat-devel freetype freetype-devel libjpeg libjpeg-devel libpng libpng-devel gdb bison libtool make automake strace autoconf gettext automake curl mercurial

Profile

$: curl -o ~/.bash_profile https://gist.github.com/pjx-octopus/4954968/raw/dc0108ae3da48c52a761fcbb2a647b1d30a404f5/bash_profile
$: . ~/.bash_profile

Time Zone

$: cp /etc/localtime /etc/localtime.old
$: cp -f /usr/share/zoneinfo/Mexico/General /etc/localtime (or -> New York)

Directories

$: mkdir -p ~/backups ~/downloads

Python 2.7


Download

$: cd ~/downloads
$: wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
$: tar xvjf Python-2.7.3.tar.bz2
$: cd Python-2.7.3

Install

$: ./configure
$: make
$: make install (or -> make altinstall)

Setuptools & Pip

Download

setuptools:

$: cd ~/downloads
$: wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
$: tar xfvz setuptools-0.6c11.tar.gz
$: cd setuptools-0.6c11
$: python setup.py build
$: python setup.py install

pip:

$: cd ~/downloads
$: wget http://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz#md5=db8a6d8a4564d3dc7f337ebed67b1a85
$: tar xfvz pip-1.2.1.tar.gz
$: cd pip-1.2.1
$: python setup.py build
$: python setup.py install

Supervisor

$: pip install supervisor

PIL

$: pip install pil

Virtualenv

$: pip install virtualenv

MongoDB


Repo (stable)

$: curl -o /etc/yum.repos.d/10gen.repo https://gist.github.com/pjx-octopus/4954941/raw/c3a0f251d0f6a5197fc6b4e89325ee043380283b/10gen.repo.i686

or x86_64

$: curl -o /etc/yum.repos.d/10gen.repo https://gist.github.com/pjx-octopus/4954953/raw/8557153b9b189d5a2b1e5a75060060a7b85c81a5/10gen.repo.x86_64

Install

$: yum update
$: yum search mongo
$: yum install mongo-10gen mongo-10gen-server

Config (optional)

$: service mongod stop    
$: cp /etc/mongod.conf /etc/mongod.conf.old
$: nano /etc/mongod.conf

- paste -
# mongo.conf
logpath=/var/log/mongo/mongod.log
logappend=true
fork=true
dbpath=/var/lib/mongo
auth=true
bind_ip=127.0.0.1
rest=false
nohttpinterface=true
- paste -

$: service mongod start

Administration & Security

$: mongo
> use admin
> db.addUser("username", "password")
> db.auth("username", "password")

Nginx


Repo (stable)

$: curl -o /etc/yum.repos.d/nginx.repo https://gist.github.com/pjx-octopus/4954959/raw/2a144cf8cb2d43bffc8d5aa76811f700a90ef813/nginx.repo

Install

$: yum update
$: yum search nginx
$: yum install nginx

Config

$: service nginx stop
$: mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
$: nano /etc/nginx/nginx.conf

-- paste --
# before close config
include /etc/nginx/sites-enabled/*.conf;
-- paste --

$: service nginx start

Iptables:


Config

$: iptables --line-numbers -n -L (or -> netstat -tulpn)

-- view --
X    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
X    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
-- view --

$: nano /etc/sysconfig/iptables

-- paste --
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --sport 80 --dport 8000:8999 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --sport 443 --dport 8000:8999 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 28017 -j ACCEPT
-- paste --

$: service iptables restart

Service (supervisord)


$: mkdir -p /etc/supervisord /var/log/supervisord

$: curl -o /etc/supervisord.conf https://gist.github.com/pjx-octopus/4954988/raw/c6f84d0e6375afa7dc5c099941397c14ab278dba/supervisord.conf

$: curl -o /etc/rc.d/init.d/supervisord https://gist.github.com/pjx-octopus/4954992/raw/d63d93c9ccb05be2b22de7d144e487c713900b83/supervisord
$: chmod +x /etc/rc.d/init.d/supervisord

$: chkconfig --list
$: chkconfig --add supervisord
$: chkconfig supervisord on (or -> chkconfig –level 345 supervisord on) 

$: service supervisord start
$: service supervisord stop
$: service supervisord reload

SSH Auth

Config (local)

# create
$: ssh-keygen -t rsa -f ~/.ssh/proc3ssdev -C "proc3ssdev"
$: Enter passphrase (empty for no passphrase): `proc3ssdev` (or -> any password)

# add
$: ssh-add ~/.ssh/proc3ssdev
$: Enter passphrase (empty for no passphrase): `proc3ssdev` (or -> any password)

# copy
$: pbcopy < ~/.ssh/proc3ssdev.pub

Config (remote)

$: mkdir ~/.ssh
$: chmod 0700 ~/.ssh

$: touch ~/.ssh/authorized_keys
$: chmod 0600 ~/.ssh/authorized_keys

$: cp /etc/ssh/sshd_config /etc/ssh/sshd_config.old

Cron (any task)


$: touch /a/path/script.py

-- paste --
file: (deploy)/var/www/vhosts/domain.com/backoffice/tasks/script.py
-- paste --

$: chmod +x /a/path/script.py
$: crontab -l
$: crontab -e

-- paste --
0 1 * * 6 /a/path/script.py -i > /tmp/script.log
-- paste --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment