Build a Python + Nginx + Tornado + Mysql environment using Centos

Source: Internet
Author: User
The combination of PythonTornado is gaining more and more attention. Like Nginx, Tornado uses epoll for process scheduling. The non-blocking call method easily solves the problem of high concurrency. In addition, Python is an artifact for lightweight and multi-concurrency program development. Therefore, this group looks pretty good. Next I will introduce

The combination of PythonTornado is gaining more and more attention. Like Nginx, Tornado uses epoll for process scheduling. The non-blocking call method easily solves the problem of high concurrency. In addition, Python is an artifact for lightweight and multi-concurrency program development. Therefore, this group looks pretty good. Next I will introduce

The combination of Python + Tornado is gaining more and more attention. Like Nginx, Tornado uses epoll for process scheduling. The non-blocking call method easily solves the problem of high concurrency. In addition, Python is an artifact for lightweight and multi-concurrency program development. Therefore, this group looks pretty good.
Next I will introduce how to quickly build a running environment for UNIX (LINUX and MAC are configured in the same way:
1. Install Python
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz tar xvfz Python-2.7.5.tgzcd Python-2.7.5 ./configuremakesudo make install

2. Install the Python package management tool setuptools, pip, and packaging tool distribute.
wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.pywget http://python-distribute.org/distribute_setup.py python distribute_setup.pywget https://github.com/pypa/pip/raw/master/contrib/get-pip.py python get-pip.py

3. Install Readline
sudo pip install readline

4. Install Mysql
# Install cmake wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gztar Xvfz cmake-2.8.8.tar.gzcd./configuremakesudo make install # install mysql wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.29.tar.gztar Xvfz mysql-5.5.29.tar.gzcd mysql-5.5.29cmake. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/usr/localmysql/data/-DMYSQL_UNIX_ADDR =/usr/localmysql/data/mysqld. sock-keys = 1-DSYSCONFDIR =/etc-DEXTRA_CHARSETS = all-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_unicode_ci-DWITH_DEBUG = 0 makesudo make install # download and install mysql-python http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gztar Xvfz MySQL-python-1.2.3.tar.gzcd MySQL-python-1.2.3 # modify site. path of mysql_config in py (/bin/mysql_config under mysql installation path), site. pymysql_config =/usr/local/mysql/bin/mysql_config # compile and install python setup. py buildsudo python setup. py install # Add the lib under the mysql installation path to the environment variable LD_LIBRARY_PATH export LD_LIBRARY_PATH =/usr/local/mysql/lib/: $ LD_LIBRARY_PATH
5. install some common Python modules and tornado
pip install tornadopip install torndb pip install requestspip install markdown

6. Configure Mysql
groupadd mysql useradd -g mysql mysql chown mysql.mysql -R /service/mysql/ /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

7. Install Nginx
wget http://nginx.org/download/nginx-0.8.33.tar.gz tar zxvf nginx-0.8.33.tar.gzcd nginx-0.8.33 ./configuremake make install

8. Configure nginx and edit the/usr/local/nginx/conf/nginx. conf file.
user nobody;worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events {    worker_connections 1024;}http {    include mime.types;    default_type application/octet-stream;    upstream snail {        server 127.0.0.1:8888;    }    sendfile on; #tcp_nopush on; keepalive_timeout 65;    proxy_read_timeout 200;    tcp_nopush on;    tcp_nodelay on;    gzip on;    gzip_min_length 1000;    gzip_proxied any;    server {        listen 80;        server_name localhost; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html;        location = /50x.html {            root html;        }        location / {            proxy_pass_header Server;            proxy_set_header Host $http_host; #proxy_redirect false; proxy_set_header X-Real-IP $remote_addr;            proxy_set_header X-Scheme $scheme;            proxy_pass http://snail; }    }}

9. Create a project
vi demo.pyimport tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world")application = tornado.web.Application([    (r"/", MainHandler),]) if __name__ == "__main__":    application.listen(8888)    tornado.ioloop.IOLoop.instance().start()

10. Run this project
# Start the project nohup python demo. py & # restart Nginx/usr/local/nginx/sbin/nginx-s reload

Enter http: // 127.0.0.1 in the browser to view the page output hello word!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.