Last active
May 27, 2016 13:52
-
-
Save vandorjw/10337264 to your computer and use it in GitHub Desktop.
Centos Nginx Python3.4 uWSGI Emperor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here are steps: | |
1. # yum upgrade | |
2. $ curl -O http://fedora.mirror.nexicom.net/epel/6/i386/epel-release-6-8.noarch.rpm | |
3. # yum localinstall epel-release-6-8.noarch.rpm | |
4. $ curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm | |
5. # yum localinstall pgdg-centos93-9.3-1.noarch.rpm | |
6. # yum install postgresql93-server postgresql93-contrib postgresql93-devel | |
7. # service postgresql-9.3 initdb | |
8. # service postgresql-9.3 start | |
9. # chkconfig postgresql-9.3 on | |
At this point CentOS6 is fully updated and running postgres. Time to install nginx. | |
This should go in /etc/yum.repos.d/nginx.repo | |
[nginx] | |
name=nginx repo | |
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ | |
gpgcheck=0 | |
enabled=1 | |
Aside: This configures a repository for nginx, provided by the nginx team. | |
1. # yum install nginx | |
2. # service nginx start | |
3. # chkconfig nginx on | |
At this point nginx is installed and running (Although not yet configured for YOUR needs). Time to install Python3. | |
1. # yum groupinstall 'development tools' | |
2. # yum install zlib-dev openssl-devel sqlite-devel bzip2-devel xz-libs pcre-devel | |
3. $ curl -O http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz | |
4. $ xz -d Python-3.4.0.tar.xz | |
5. $ tar -xvf Python-3.4.0.tar | |
6. $ cd Python-3.4.0 | |
7. $ ./configure | |
8. $ make | |
9. # make altinstall | |
10. # ln -s /usr/local/bin/python3.4 /usr/bin/python3 | |
Python3 is installed at this point. Time to create virtualenvironments. | |
1. $ cd /srv/ | |
2. $ python3 -m venv uwsgi | |
3. $ source /srv/uwsgi/bin/activate | |
4. $ pip install uwsgi | |
Place the following in /etc/init.d/uwsgi | |
(This script could be improved) | |
#!/bin/sh | |
# | |
# uwsgi Startup script for uwsgi | |
# | |
# chkconfig: - 85 15 | |
# processname: uwsgi | |
# description: uwsgi is an HTTP and reverse proxy server | |
# | |
### BEGIN INIT INFO | |
# Provides: uwsgi | |
# Required-Start: $local_fs $remote_fs $network | |
# Required-Stop: $local_fs $remote_fs $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: start and stop uwsgi | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
DAEMON=/srv/uwsgi/bin/uwsgi | |
DAEMON_OPTS="--ini /srv/uwsgi/emperor.ini" | |
OWNER=uwsgi | |
NAME=uwsgi | |
RETVAL=0 | |
get_pid() { | |
if [ -f /var/run/$daemon_name.pid ]; then | |
echo `cat /var/run/$daemon_name.pid` | |
fi | |
} | |
case "$1" in | |
start) | |
echo -n "Starting $NAME: " | |
PID=$(get_pid) | |
if [ -z "$PID" ]; then | |
[ -f /var/run/$NAME.pid ] && rm -f /var/run/$NAME.pid | |
touch /var/run/$NAME.pid | |
chown $OWNER /var/run/$NAME.pid | |
$DAEMON $DAEMON_OPTS | |
fi | |
;; | |
stop) | |
echo -n "Stopping $NAME: " | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 3 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
rm -f /var/run/$NAME.pid &> /dev/null | |
fi | |
;; | |
reload) | |
echo "Reloading $NAME" | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 1 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
rm -f /var/run/$NAME.pid &> /dev/null | |
fi | |
;; | |
force-reload) | |
echo "Reloading $NAME" | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 15 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
rm -f /var/run/$NAME.pid &> /dev/null | |
fi | |
;; | |
restart) | |
$0 stop | |
sleep 2 | |
$0 start | |
;; | |
status) | |
killall -10 $DAEMON | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 | |
**Run the following, to keep selinux happy** | |
1. # semanage fcontext -a -t initrc_exec_t -r s0 "/etc/init.d/uwsgi" | |
2. # restorecon /etc/init.d/uwsgi | |
**Run the next commands to auto-start uwsgi-emperor on boot** *and turn off when system turns of* | |
1. # chkconfig --add nginx | |
2. # chkconfig nginx on | |
3. # service nginx start | |
Place the following in /srv/uwsig/emperor.ini | |
[uwsgi] | |
uid = uwsgi | |
gid = uwsgi | |
emperor-pidfile = /var/run/uwsgi.pid | |
emperor = /srv/uwsgi/vassals | |
master = true | |
die-on-term = true | |
daemonize = true | |
logto = /srv/uwsgi/log/emperor. | |
##What is left to do? | |
A metric crapload. You are about 25% of the way finished at this point. You still are required to do the following: | |
1. Place your vassal file in /srv/uwsgi/vassals. | |
2. Create database to use in postgres. | |
3. Configure your firewall. Both IP-tables and AWS Security Policy. | |
4. Configure nginx to to work with your vassal. | |
##Optional: | |
* DNS? | |
* Redundancy | |
* Configure Backups? | |
## Additional NOTE: | |
For pip to be able to install psycopg2, it needs to be able to find pg_config. | |
Easiest way to do this, is to add "/usr/pgsql-9.3/bin" to your path. | |
Alter your ~/.bash_profile to include it: | |
PATH=$PATH:$HOME/bin:/usr/pgsql-9.3/bin | |
export PATH | |
Then source it: | |
source ~/.bash_profile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment