Deploy flask cms in CentOS

Source: Internet
Author: User
Tags install mongodb virtualenv

Deploy flask cms in CentOS
Recently, I have learned python, but I have never had any programming experience and can't practice it. So I am going to build my own python framework website to play it and consolidate my knowledge ~ Based on the opinions of beginners on the Internet, I finally chose the web framework suitable for beginners for flask. So I found this project: https://github.com/quokkaproject/quokka. I started to build a runtime environment. My system Environment Virtual Machine system: centOS release 6.4 (Final) kernel: 2.6.32-504.23.4.el6.x86 _ 64 Memory: 997 MB I download and install the new Python version

[Root @ linux2 tmp] # wget javastmp] # tar zxf Python-2.7.10.tgz [root @ linux2 tmp] # cd Python-2.7.10 [root @ linux2 Python-2.7.10] #. /configure [root @ linux2 Python-2.7.10] # make & make installii install python-pip and virtualenv [root @ linux2 tmp] # wget https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz # download pip source package [root @ linux2 pip-7.1.2] # wget https://bootstrap.pypa.io/get-pip.py # download installation script [root @ linux2 pip-7.1.2] # python get-pip.py # will update the installation of setuptools, wheel and other packages [root @ linux2 pip-7.1.2] # pip install virtualenv

 

Iii. The new version of git linux comes with a low version, and the command parameters used later are not supported. Therefore, here we will update the git command.
[root@linux2 pip-7.1.2]# yum clean all[root@linux2 pip-7.1.2]# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt[root@linux2 pip-7.1.2]# rpm -i http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm[root@linux2 pip-7.1.2]# yum --enablerepo=rpmforge-extras update git

 

2. Install mongodb
[Root @ linux2 tmp] # curl-O unzip tmp] # tar zxvf mongodb-linux-x86_64-rhel62-3.0.6.tgz [root @ linux2 tmp] # mv mongodb-linux-x86_64-rhel62-3.0.6/usr/local/mongodb [root @ linux2 mongodb] # vim /etc/mongodb. confport = 10101 dbpath =/data/db/datalogpath =/data/db/log/mongodb. loglogappend = true # log append not overwrite fork = true # Run [root @ linux2 mongodb] # mkdir-p/data/db/log # create a data folder and the log folder [root @ linux2 mongodb] #/usr/local/mongodb/bin/mongod-f/etc/mongodb. conf # Start mongodb. Pay attention to the high memory usage.

 

Note: The mongo database operation writes data to create a database, so you do not need to create a database here. As long as a program writes data to the database, it will create a new database. 3. install and configure quokka.
[Root @ linux2 ~] # Virtualenv-p/usr/local/bin/python2.7 quokka-env # specify the absolute path of the python version [root @ linux2 ~] # Source quokka-env/bin/activate # You need to exit the vir environment and use the deactivate command (without parameters) (quokka-env) [root @ linux2 www] # git clone https://github.com/quokkaproject/quokka -- branch development -- single-branch # only get the content of this branch, (quokka-env) [root @ linux2 www] # cd quokka/(quokka-env) [root @ linux2 quokka] # cp example. local_settings.py (quokka-env) [root @ linux2 quokka] # vim local_settings.py # configure the mongodb database... MONGODB_DB = "quokka_db" MONGODB_HOST = 'localhost' MONGODB _ PORT = 10101MONGODB_USERNAME = None # Here my database is local, so I can leave the password MONGODB_PASSWORD = None... (quokka-env) [root @ linux2 quokka] # cd .. (quokka-env) [root @ linux2 quokka] # pip install-r requirements/requirements.txt read the list of installation packages in txt

 

Create an administrator and run quokka I to create a super Administrator (You need to log on to the Management Interface) $ python manage. py accounts_createsuperuseryou@email.comP4 $ W0Rdii fill sample data (optional if you want sample data) $ python manage. py populatecredentials for/admin will be email: admin@example.com passwd: adminiii run test $ python manage. py runserver -- host 0.0.0.0 -- port 5000 Site on http: // localhost: 5000 Admin on http: // localhost: 5000/admin at this point, quokka is successfully installed ~ If other pages are not displayed normally, ask the project owner: https://github.com/quokkaproject/quokka/issues, install HTTP server 4, configure nginx + Gunicorn to use the web built-in flask (with the preceding command) it is also possible to run the web, but it is not a professional web server after all. We recommend that you use mainstream web servers. Here I choose nginx. For other python deployment methods, refer to here: http://lutaf.com/141.htm I download and install nginx configuration if you want nginx to support google Performance module, you need to install google-perftools download link: http://download.savannah.gnu.org/releases/libunwind # libunwind Library provides basic function call chain and function call register functions for 64-bit CPU and operating system programs http: // https://github.com/gperftools/gperftools/releases # google performance library install libunwind
(quokka-env)[root@linux2 tmp]# tar zxf libunwind-1.1.tar.gz (quokka-env)[root@linux2 tmp]# cd libunwind-1.1(quokka-env)[root@linux2 libunwind-1.1]# CFLAGS=-fPIC ./configure (quokka-env)[root@linux2 libunwind-1.1]# make CFLAGS=-fPIC(quokka-env)[root@linux2 libunwind-1.1]# make CFLAGS=-fPIC install

 

Install google-perftools
(Quokka-env) [root @ linux2 tmp] # wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.4/gperftools-2.4.tar.gz (quokka-env) [root @ linux2 gperftools-2.4] #. /configure (quokka-env) [root @ linux2 gperftools-2.4] # make & make install add thread directory for google-perftools [root @ localhost home] # mkdir/tmp/tcmalloc [root @ localhost home] # chmod 0777 /tmp/tcmalloc

 

Install nginx
(Quokka-env) [root @ linux2 nginx] # yum install-y gcc-c ++ gcc automake autoconf libtool make (quokka-env) [root @ linux2 tmp] # curl-O http://nginx.org/download/nginx-1.8.0.tar.gz # download the latest stable version of nginx (quokka-env) [root @ linux2 tmp] # tar zxvf nginx-1.8.0.tar.gz (quokka-env) [root @ linux2 tmp] # cd nginx-1.8.0 (quokka-env) [root @ linux2 nginx-1.8.0] # groupadd www (quokka-env) [root @ linux2 nginx-1.8.0] # useradd-s/sbin/nologin-g www (quokka-env) [root @ linux2 nginx-1.8.0] #. /configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-google_perftools_module -- with-http_gzip_static_module -- with-http_sub_module (quokka-env) [root @ linux2 nginx-1.8.0] # make & make installnginx compilation module Description: -- with-http_stub_status_module: provide the ability to view server statistics-with-http_ssl_module: Support HTTPS/SSL -- with-http_gzip_static_module: provides pre-compressed static files-with-google_perftools_module: Support for Google Performance Tools-with-http_sub_module: can replace text on pages

 

Configure nginx
(Quokka-env) [root @ linux2 conf] # vim nginx. confworker_processes 1; google_perftools_profiles/tmp/tcmalloc; # Add the thread directory events {worker_connections 1024;} http {include mime. types; default_type application/octet-stream; sendfileon; keepalive_timeout 65; upstream quokka {server unix:/tmp/quokka. sock fail_timeout = 0;} server {listen 80 default_server; return 444; # return http code 444 when the request does not match server_name} server {# configure listen 80 without host header; server_name *. eason. wang; return 301 https:/eason. wang $ request_uri;} server {listen 80; client_max_body_size 4G; server_name eason. wang; # server name is your domain name keepalive_timeout 5; root/data/www/quokka; # I haven't figured out why I need to configure this path location/{try_files $ uri @ proxy_to_app;} location @ proxy_to_app {proxy_set_header X-Forwarded-For $ scheme; proxy_set_header Host $ http_host; proxy_redirect off; proxy_pass http: // quokka;} error_page 500 502 503 504/50 x.html; location =/50x.html {root html ;}}}

 

Install and configure a python wsgi http Server in gunicorn.
(Quokka-env) [root @ linux2 logs] # pip install gunicorn (quokka-env) [root @ linux2 quokka] # cd/data/www/quokka/(quokka-env) [root @ linux2 quokka] # vim start_gunicorn.sh # Start script #! /Bin/bashNAME = 'quokka '# Name of the application FLASKDIR =/data/www/quokka # SOCKFILE =/tmp/quokka in the django project directory. sock # use this sock to communicate with USER = www # USER NUM_WORKERS running this application = 3 # Number of worker processes used by gunicorn DJANGO_WSGI_MODULE = wsgi # wsgi module echo "starting $ NAME as 'whoami '"# activate python virtual runtime environment cd $ FLASKDIRsource/root/quokka-env/bin/activate # Start flaskexec/root/quokka-env/bin/gunicorn \ -- workers $ NUM_WORKERS \ -u www \ -- bind = unix: $ SOCKFILE \ wsgi run (quokka-env) [root @ linux2 quokka] #. /start_gunicorn.sh &

 

Problem 1. When installing pip, the python get-pip.py is successfully executed, but there is no pip command. I have repeatedly confirmed that there is no error in executing this installation command. I think it may be a problem with the Python version, because the default value of linux is python 2.6.6, I want to use virtualenv, so I am too lazy to make environment variables, so I use the absolute path method to specify the new version of python to reinstall the solution. [Root @ linux2 pip-7.1.2] #/usr/local/bin/python2.7 get-pip.py -- when a force-reinstall2 or mongodb encounters a database deletion operation, run the DELETE Command [root @ linux2 shell] #/usr/local/mongodb/bin/mongo 127.0.0.1: 10101> use xxx # select the database to be deleted> db. dropDatabase () # delete database 3. When pip is installed, the error "cocould not find a version that satisfies the requirement... ", use the-v parameter to view the detailed cause and solve the problem. Example:
[root@linux2 www]# pip install pyshorteners==0.5.5 -vCollecting pyshorteners==0.5.5  Getting page https://pypi.python.org/simple/pyshorteners/  Starting new HTTPS connection (1): pypi.python.org  "GET /simple/pyshorteners/ HTTP/1.1" 404 28063  Could not fetch URL https://pypi.python.org/simple/pyshorteners/: 404 Client Error: Not Found - skipping  1 location(s) to search for versions of pyshorteners:  * https://pypi.python.org/simple/pyshorteners/  Getting page https://pypi.python.org/simple/pyshorteners/  "GET /simple/pyshorteners/ HTTP/1.1" 404 28063  Could not fetch URL https://pypi.python.org/simple/pyshorteners/: 404 Client Error: Not Found - skipping  Could not find a version that satisfies the requirement pyshorteners==0.5.5 (from versions: )Cleaning up...No matching distribution found for pyshorteners==0.5.5Exception information:Traceback (most recent call last):  File "/root/quokka-env/lib/python2.7/site-packages/pip/basecommand.py", line 211, in mainstatus = self.run(options, args)  File "/root/quokka-env/lib/python2.7/site-packages/pip/commands/install.py", line 305, in runwb.build(autobuilding=True)  File "/root/quokka-env/lib/python2.7/site-packages/pip/wheel.py", line 705, in buildself.requirement_set.prepare_files(self.finder)  File "/root/quokka-env/lib/python2.7/site-packages/pip/req/req_set.py", line 334, in prepare_filesfunctools.partial(self._prepare_file, finder))  File "/root/quokka-env/lib/python2.7/site-packages/pip/req/req_set.py", line 321, in _walk_req_to_installmore_reqs = handler(req_to_install)  File "/root/quokka-env/lib/python2.7/site-packages/pip/req/req_set.py", line 461, in _prepare_filereq_to_install.populate_link(finder, self.upgrade)  File "/root/quokka-env/lib/python2.7/site-packages/pip/req/req_install.py", line 250, in populate_linkself.link = finder.find_requirement(self, upgrade)  File "/root/quokka-env/lib/python2.7/site-packages/pip/index.py", line 571, in find_requirement'No matching distribution found for %s' % reqDistributionNotFound: No matching distribution found for pyshorteners==0.5.5

 

We can see from the above that the connection is 404, so we can verify whether there is a problem with 404 or pip. You can directly access the web or use curl for verification (quokka-env) [root @ linux2 www] # curl-I https://pypi.python.org/simple/pyshorteners/HTTP/1.1 404 Not Found page 404 is a problem with the project owner adjusting the page or revoking it. If you want to solve the problem as soon as possible, search for the project on github. Generally, how can I install it locally in README documents. 4. An error is reported when nginx is started.
nginx: error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directorynginx: error while loading shared libraries: libunwind.so.8: cannot open shared object file: No such file or directory

 

The preceding two errors are caused by the 64-bit operating system. The solution is to find two lib files and connect them to/usr/lib64.
(Quokka-env) [root @ linux2 ~] # Whereis libprofiler. so.0 libunwind. so.8 # locate the two lib file locations libprofiler. so:/usr/lib64/libprofiler. so.0/usr/local/lib/libprofiler. so.0/usr/local/lib/libprofiler. solibunwind. so:/usr/lib64/libunwind. so.8/usr/local/lib/libunwind. so.8/usr/local/lib/libunwind. so (quokka-env) [root @ linux2 ~] # Ln-s/usr/local/lib/libprofiler. so.0/usr/lib64/(quokka-env) [root @ linux2 ~] #/Usr/local/nginx/sbin/nginx-V/usr/local/nginx/sbin/nginx: error while loading shared libraries: libunwind. so.8: cannot open shared object file: No such file or directory (quokka-env) [root @ linux2 ~] # Ln-s/usr/local/lib/libunwind. so.8/usr/lib64/

 

5. solve the problem that the specified gunicorn-u has no permission
(quokka-env)[root@linux2 quokka]# gunicorn -u www --workers 3 --bind unix:/tmp/quokka.sock -m 007 wsgi[2015-09-24 10:53:57 +0000] [28230] [INFO] Starting gunicorn 19.3.0[2015-09-24 10:53:57 +0000] [28230] [INFO] Listening at: unix:/tmp/quokka.sock (28230)[2015-09-24 10:53:57 +0000] [28230] [INFO] Using worker: sync[2015-09-24 10:53:57 +0000] [28235] [INFO] Booting worker with pid: 28235[2015-09-24 10:53:57 +0000] [28235] [ERROR] Exception in worker process:Traceback (most recent call last):  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app  File "/data/www/quokka/wsgi.py", line 4, in <module>from werkzeug.serving import run_simpleImportError: No module named werkzeug.servingTraceback (most recent call last):  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app  File "/data/www/quokka/wsgi.py", line 4, in <module>from werkzeug.serving import run_simpleImportError: No module named werkzeug.serving[2015-09-24 10:53:57 +0000] [28235] [INFO] Worker exiting (pid: 28235)Traceback (most recent call last):  File "/root/quokka-env/bin/gunicorn", line 11, in <module>sys.exit(run())  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in runWSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in runsuper(Application, self).run()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in runArbiter(self).run()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 174, in runself.manage_workers()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workersself.spawn_workers()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 541, in spawn_workerstime.sleep(0.1 * random.random())  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 214, in handle_chldself.reap_workers()  File "/root/quokka-env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workersraise HaltServer(reason, self.WORKER_BOOT_ERROR)gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

 

Based on the executed command and stack trace, we can basically determine two error messages: ImportError: No module named werkzeug. serving import module error. check whether it is a module problem. For a large File "/root...", check whether the www account has permissions under the/root account in the env folder. Check the two errors below:
(quokka-env)[root@linux2 tmp]# pythonPython 2.7.10 (default, Sep 21 2015, 17:31:07) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> from werkzeug.serving import run_simple

 

No error reported. It seems that the module is correct.
(quokka-env)[root@linux2 tmp]# gunicorn --workers 3 --bind unix:/tmp/quokka.sock -m 007 wsgi       [2015-09-24 11:36:19 +0000] [28350] [INFO] Starting gunicorn 19.3.0[2015-09-24 11:36:19 +0000] [28350] [INFO] Listening at: unix:/tmp/quokka.sock (28350)[2015-09-24 11:36:19 +0000] [28350] [INFO] Using worker: sync[2015-09-24 11:36:19 +0000] [28355] [INFO] Booting worker with pid: 28355[2015-09-24 11:36:19 +0000] [28356] [INFO] Booting worker with pid: 28356[2015-09-24 11:36:19 +0000] [28357] [INFO] Booting worker with pid: 28357

 

Removed-u www can be started normally, which seems to be a problem caused by permissions ~ Solution: [root @ linux2/] # ll... drwxr -----. 14 root 4096 September 23 19:50 root... [root @ linux2/] # chmod g + x root why is the execution permission of the Group required, the reason is that the permission for executing the gunicorn command is the current user and the current user group (which can be changed through-g), and we changed the start user to www, so it will try to use the www user permission, www does not have this permission. It will attempt the permissions of the current user group (both the root group), so you must grant the root group the execution permission.

Related Article

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.