MySQL
安装 MySQL
启动 MySQL
设置 Root 密码,根据提示进行 MySQL 配置
| 1
 | $ ./usr/local/Cellar/mysql/5.6.22/bin/mysql_secure_installation
 | 
Nginx
安装 Nginx
在配置文件中设置 Nginx 为80端口
| 1
 | $ vi /usr/local/etc/nginx/nginx.conf
 | 
pip
下载 get-pip.py 文件,需要管理员权限
| 1
 | $ sudo python get-pip.py
 | 
或者使用 easy_install 安装 pip
VirtualEnv
安装 virtualenv ,需要管理员权限
| 1
 | $ sudo pip install virtualenv
 | 
VirtualEnvWrapper
安装 virtualenv ,需要管理员权限
| 1
 | $ sudo pip install virtualenvwrapper
 | 
创建 .virtualenvs 目录存放虚拟环境以及配置
在 ~/.zshrc 增加配置
| 1 2
 | export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
 | 
执行如下命令或者重新打开终端
创建虚拟环境
查看所有虚拟环境
切换虚拟环境
退出虚拟环境
删除虚拟环境
iPython
安装 iPython
MySQL-Python
安装 MySQL-Python
| 1
 | $ pip install mysql-python
 | 
测试
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 | import MySQLdb as mdb import sys try: 	con = mdb.connect('localhost', 'root', 'password', 'database') 	cur = con.cursor() 	cur.execute('select VERSION()') 	ver = cur.fetchone() 	print 'Database version : %s ' % ver except mdb.Error, e: 	print 'Error %d: %s' % (e.args[0], e.args[1]) 	sys.exit() finally: 	if con: 		con.close()
 | 
Tornado
安装 Tornado
安装 Supervisor 并且配置 Nginx 运行 Tornado 程序
Supervisor 是一个进程监控程序,使用 Supervisor 来守护管理 Tornado 进程。另外使用 Nginx 作为 Tornado 多进程多端口的反向代理,同时可以达到均衡负载的作用。
Tornado 程序如下 [/Users/youname/repo/tornado-test/app.py]
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 | import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options define('port', default=8000, help='run on the given port', type=int) class AppHandler(tornado.web.RequestHandler):     def get(self):         greeting = self.get_argument('greeting', 'Hello')         self.write(greeting + ', friendly user!') if __name__ == '__main__':     tornado.options.parse_command_line()     app = tornado.web.Application(handlers=[(r'/', AppHandler)])     http_server = tornado.httpserver.HTTPServer(app, xheaders=True)     http_server.listen(options.port)     tornado.ioloop.IOLoop.instance().start()
 | 
安装 Supervisor
| 1
 | $ pip install supervisor
 | 
生成 Supervisor 配置文件
| 1
 | $ echo_supervisord_conf > ./supervisord.conf
 | 
修改配置文件如下,配置 Tornado 开了四个进程,端口为 8001 - 8004
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 | [group:testapp] programs=tornado-test [program:tornado-test] command=python /Users/youname/repo/tornado-test/app.py --port=80%(process_num)02d process_name=%(program_name)s%(process_num)d  numprocs=4 directory=/Users/youname/repo/tornado-test autostart=true redirect_stderr=true stdout_logfile=/Users/youname/repo/tornado-test/tornado.log stdout_logfile_maxbytes=100MB  stdout_logfile_backups=10 loglevel=info numprocs=4 numprocs_start=1
 | 
启动 Supervisor
| 1
 | $ supervisord -c ./supervisord.conf
 | 
查看运行状态
重新加载配置文件
停止所有 Supervisor
| 1
 | $ supervisorctl stop all
 | 
停止某个 Supervisor
| 1
 | $ supervisorctl stop [groupname]:[programname]
 | 
配置 Nginx
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 | upstream tornadoes {     server 127.0.0.1:8001;     server 127.0.0.1:8002;     server 127.0.0.1:8003;     server 127.0.0.1:8004; } server {     listen       80;     server_name  localhost;     location / {         proxy_pass_header Server;         proxy_set_header Host $http_host;         proxy_redirect off;         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Scheme $scheme;         proxy_pass http://tornadoes;     }
 | 
运行 Nginx
停止 Nginx
配置 Tornado 环境到这。