zoukankan      html  css  js  c++  java
  • Centos7下安装python3 Mr

    1.在centos 7中安装python3环境

    1、yum更新yum源

    yum update
    

    2、安装Python 3.7所需的依赖否则安装后没有pip3包

    yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
    

    3、在官网下载所需版本,这里用的是3.7.4版本

    wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
    
    1. 安装Python

    1、解压

    tar -xvf Python-3.7.4.tgz
    

    2、配置编译

    cd Python-3.7.0
    ./configure --prefix=/usr/local/python3  # 配置编译的的路径(这里--prefix是指定编译安装的文件夹)
    ./configure --enable-optimizations  # 执行该代码后,会编译安装到 /usr/local/bin/ 下,且不用添加软连接或环境变量
    make && make install
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3  # 添加软连接
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
    

    3、将/usr/local/python3/bin加入PATH

    [root@linux-node1 testProj]# vim /etc/profile
    #然后在文件末尾添加
    export PATH=$PATH:/usr/local/python3/bin
    
    [root@linux-node1 testProj]# source /etc/profile # 修改完后,还需要让这个环境变量在配置信息中生效,执行命令
    

    2. 初始化一个django项目

    [root@linux-node1 /]# pip3 install django==2.0.4
    [root@linux-node1 /]# mkdir /code/
    [root@linux-node1 /]# cd /code/
    [root@linux-node1 testProj]# django-admin startproject mmcsite
    [root@linux-node1 testProj]# cd /code/mmcsite
    [root@linux-node1 testProj]# python3 manage.py runserver 0.0.0.0:8000
    # 页面中访问:http://0.0.0.0:8000/
    

    3. 安装Gunicorn并使用uWSGI启动这个服务

    • 安装gunicorn
    [root@linux-node1 mmcsite]#  pip3 install gunicorn                          # 安装Gunicorn
    [root@linux-node1 mmcsite]# gunicorn mmcsite.wsgi -b 0.0.0.0:8000 -w 3      # 命令行下测试
    -c    # 指定一个配置文件(py文件)
    -b    # 与指定的socket进行绑定
    -D    # 以守护进程形式来运行Gunicorn进程,其实就是将这个服务放到后台去运行
    -w    # 工作的进程数量
    -k    # 工作进程类型,sync(默认), eventlet, gevent, or tornado, gthread, gaiohttp.
    # 参考:http://docs.gunicorn.org/en/latest/settings.html
    [root@linux-node1 mmcsite]#  ps -ef|grep gunicorn                          # 查看Gunicorn进程已经运行
    
    • /mmc/site/gunicorn_config.py Gunicorn配置文件
    [root@linux-node1 mmcsite]#  vim /code/mmcsite/gunicorn_config.py  # Gunicorn配置文档
    # gunicorn_config.py
    import logging
    import logging.handlers
    from logging.handlers import WatchedFileHandler
    import os
    import multiprocessing
    bind = '0.0.0.0:8000'           #绑定ip和端口号
    backlog = 512                   #监听队列
    chdir = '/code/mmcsite'         #gunicorn要切换到的目的工作目录
    timeout = 30                    #超时
    worker_class = 'gevent'         #使用gevent模式,还可以使用sync 模式,默认的是sync模式
    
    workers = multiprocessing.cpu_count() * 2 + 1     #进程数
    threads = 2                                       #指定每个进程开启的线程数
    loglevel = 'info'                                 #日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置
    access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' 
    accesslog = "/code/mmcsite/gunicorn_access.log"      #访问日志文件
    errorlog = "/code/mmcsite/gunicorn_error.log"        #错误日志文件
    
    • 启动
    [root@linux-node1 mmcsite]#  gunicorn mmcsite.wsgi -c gunicorn_config.py -D   # 在后台使用Gunicorn运行项目
    [root@linux-node1 mmcsite]#  ps -ef|grep gunicorn                             # 查看Gunicorn进程已经运行
    http://192.168.56.11:8000/
    
  • 相关阅读:
    DEBUG 知识
    转载:telnet启动后的登录问题
    通过ip找主机名
    转载:网线的相关知识
    hdu2717(广度优先搜索)
    hdu1241(bfs)
    hdu1060 数论
    大数除(hdu2117)
    hdu1159(DP)
    hdu2181__DFS
  • 原文地址:https://www.cnblogs.com/xinzaiyuan/p/12045365.html
Copyright © 2011-2022 走看看