一、基本环境搭建

1)查看服务器

  1. [root@Myjumpserver ~]# cat /etc/sysconfig/selinux
  2. SELINUX=disabled
  3. SELINUXTYPE=targeted
  4. [root@Myjumpserver ~]# cat /etc/redhat-release
  5. CentOS release 6.6 (Final)
  6. [root@Myjumpserver ~]# uname -r
  7. 2.6.-.el6.x86_64

2)安装基本的依赖包

  1. yum -y install gcc
  2. yum -y install gcc-c++
  3. yum -y install glibc.i686
  4. yum -y install dos2unix
  5. yum -y install vsftpd
  6. yum install -y redhat-lsb
  7. yum -y install zlib*
  8. yum install nss -y

二、搭建mysql,nginx,python环境

1.1)安装mysql5.6版本

  1. rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
  2. yum install -y mysql-server mysql-devel

1.2)设置mysql

  1. 修改my.cnf文件
  2. vim /etc/my.cnf
  3. [mysqld]
  4. innodb_file_per_table #独立表空间模式
  5.  
  6. service mysqld start #启动
  7.  
  8. mysql_secure_installation #MySQL安全配置向导
  9. Enter current password for root (enter for none): <–初次运行直接回车
  10. Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
  11. Remove anonymous users? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
  12. Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
  13. Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车
  14. Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车
  15.  
  16. mysql -uroot -p # 进入mysql
  17. CREATE DATABASE myjumpserver CHARACTER SET utf8 COLLATE utf8_bin;
  18. GRANT ALL PRIVILEGES ON myjumpserver.* TO user@'%' IDENTIFIED BY '';
  19. FLUSH PRIVILEGES;
  20. 创建库 myjumpserver
  21. 授权用户 user
  22. 用户密码
  23. 连接地址 任意网段

1.3)测试连接

2.1)安装nginx

  1. yum install -y gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel 安装依赖包
  2. cd /opt/
  3. wget http://nginx.org/download/nginx-1.9.9.tar.gz
  4. cd nginx-1.9.
  5. useradd nginx -s /sbin/nologin -M
  6. ./configure --user=nginx --group=nginx # 编译参数
  7. make && make install
  8. [root@Myjumpserver nginx]# ll /usr/local/nginx/
  9. total
  10. drwx------ nginx root Nov : client_body_temp
  11. drwxr-xr-x root root Nov : conf
  12. drwx------ nginx root Nov : fastcgi_temp
  13. drwxr-xr-x root root Nov : html
  14. drwxr-xr-x root root Nov : logs
  15. drwx------ nginx root Nov : proxy_temp
  16. drwxr-xr-x root root Nov : sbin
  17. drwx------ nginx root Nov : scgi_temp
  18. drwx------ nginx root Nov : uwsgi_temp
  19. [root@Myjumpserver nginx-1.9.]# /usr/local/nginx/sbin/nginx -t
  20. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  21. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2.2)常用的编译参数

  1. ./configure \
  2. --prefix=/home/nginx \
  3. --sbin-path=/usr/sbin/nginx \
  4. --user=nginx \
  5. --group=nginx \
  6. --conf-path=/etc/nginx/nginx.conf \
  7. --error-log-path=/home/log/nginx/error.log \
  8. --http-log-path=/home/log/nginx/access.log \
  9. --with-http_ssl_module \
  10. --with-http_gzip_static_module \
  11. --with-http_stub_status_module \
  12. --with-http_realip_module \
  13. --pid-path=/home/run/nginx.pid \
  14. --with-pcre=/home/software/pcre-8.35 \
  15. --with-zlib=/home/software/zlib-1.2. \
  16. --with-openssl=/home/software/openssl-1.0.1i

编译参数说明

  1. -prefix=/home/nginx \ Nginx安装的根路径,所有其它路径都要依赖该选项
  2. --sbin-path=/usr/sbin/nginx \ nginx的可执行文件的路径(nginx
  3. --user=nginx \ worker进程运行的用户
  4. --group=nginx \ worker进程运行的组
  5. --conf-path=/etc/nginx/nginx.conf \ 指向配置文件(nginx.conf
  6. --error-log-path=/var/log/nginx/error.log \ 指向错误日志目录
  7. --http-log-path=/var/log/nginx/access.log \ 设置主请求的HTTP服务器的日志文件的名称
  8. --with-http_ssl_module \ 使用https协议模块。默认情况下,该模块没有被构建。前提是opensslopenssl-devel已安装
  9. --with-http_gzip_static_module \ 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
  10. --with-http_stub_status_module \ 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
  11. --with-http_realip_module \ 启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
  12. --pid-path=/var/run/nginx.pid \ 指向pid文件(nginx.pid
  13.  
  14. 设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4. 8.30)并解压,
  15. 剩下的就交给Nginx的./configuremake来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
  16. --with-pcre=/home/software/pcre-8.35 \
  17.  
  18. 指定 zlib(版本1.1.3 1.2.)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib
  19. --with-zlib=/home/software/zlib-1.2. \
  20.  
  21. 指向openssl安装目录
  22. --with-openssl=/home/software/openssl-1.0.1i

2.3)nginx文件夹说明

  1. conf: 配置文件夹,最重要文件是nginx.conf
  2. html: 静态网页文件夹
  3. logs: 日志文件夹
  4. sbin: nginx 的可执行文件,启动、停止等操作

2.4)nginx启动命令

  1. /usr/local/nginx/sbin/nginx 启动
  2. /usr/local/nginx/sbin/nginx -s stop 停止
  3. /usr/local/nginx/sbin/nginx -s reload 平滑重启

2.5)修改nginx配置文件

  1. user nginx;
  2. worker_processes ;
  3. worker_cpu_affinity ;
  4. worker_rlimit_nofile ;
  5.  
  6. pid /var/run/nginx.pid;
  7.  
  8. events {
  9. worker_connections ;
  10. use epoll;
  11. multi_accept off;
  12. }
  13.  
  14. http {
  15. include /usr/local/nginx/conf/mime.types;
  16. default_type application/octet-stream;
  17.  
  18. log_format main '$remote_addr --- $remote_user --- [$time_local] --- $request --- '
  19. '"$status" --- $body_bytes_sent --- "$http_referer" --- '
  20. '"$http_user_agent" --- "$http_x_forwarded_for"';
  21. log_format mtr '$remote_addr [$time_local] "$request_uri" '
  22. '$status "$http_referer" '
  23. '"$http_user_agent" "$host"';
  24.  
  25. sendfile on;
  26.  
  27. keepalive_timeout ;
  28. client_header_timeout ;
  29. client_body_timeout ;
  30. server_tokens off;
  31. tcp_nodelay on;
  32.  
  33. gzip on;
  34.  
  35. include /usr/local/nginx/conf/vhost/*.conf;
  36.  
  37. fastcgi_send_timeout 300;
  38. fastcgi_read_timeout 300;
  39. #fastcgi_buffer_size 16k;
  40. #fastcgi_buffers 16 16k;
  41. #fastcgi_busy_buffers_size 16k;
  42. fastcgi_buffer_size 64k;
  43. fastcgi_buffers 4 64k;
  44. fastcgi_busy_buffers_size 128k;
  45.  
  46. server_names_hash_bucket_size 128;
  47. client_header_buffer_size 2k;
  48. large_client_header_buffers 4 4k;
  49. client_max_body_size 100k;
  50. open_file_cache max=51200 inactive=20s;
  51. open_file_cache_valid 30s;
  52. open_file_cache_min_uses 1;
  53. }

nginx.conf

在子文件夹(vhost),创建jumpserver.conf

  1. [root@Myjumpserver vhost]# cat jumpserver.conf
  2. server {
  3. listen ;
  4. server_name localhost;
  5.  
  6. #charset koi8-r;
  7.  
  8. #access_log logs/host.access.log main;
  9. access_log /data/log/nginx/myjumpserver_access.log main;
  10. error_log /data/log/nginx/myjumpserver_error.log;
  11.  
  12. location / {
  13. uwsgi_pass 192.168.10.13:;
  14. include uwsgi_params;
  15. }
  16.  
  17. location /static {
  18. alias /opt/wwwroot/MyJumpserver/static/;
  19. }
  20.  
  21. #error_page /.html;
  22.  
  23. # redirect server error pages to the static page /50x.html
  24. #
  25. error_page /50x.html;
  26. location = /50x.html {
  27. root html;
  28. }
  29.  
  30. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  31. #
  32. #location ~ \.php$ {
  33. # proxy_pass http://127.0.0.1;
  34. #}
  35.  
  36. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  37. #
  38. #location ~ \.php$ {
  39. # root html;
  40. # fastcgi_pass 127.0.0.1:;
  41. # fastcgi_index index.php;
  42. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  43. # include fastcgi_params;
  44. #}
  45.  
  46. # deny access to .htaccess files, if Apache's document root
  47. # concurs with nginx's one
  48. #
  49. #location ~ /\.ht {
  50. # deny all;
  51. #}
  52. }

jumpserver.conf

语法测试

  1. [root@Myjumpserver vhost]# /usr/local/nginx/sbin/nginx -t
  2. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  3. nginx: [emerg] open() "/data/log/nginx/myjumpserver_access.log" failed (: No such file or directory)
  4. nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
  5. [root@Myjumpserver vhost]# mkdir -p /data/log/nginx/
  6. [root@Myjumpserver vhost]# touch myjumpserver_access.log
  7. [root@Myjumpserver vhost]# /usr/local/nginx/sbin/nginx -t
  8. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  9. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

关于jumpserver.conf配置文件说明

  1. [root@Myjumpserver vhost]# cat jumpserver.conf
  2. server {
  3. listen ;
  4. server_name localhost;
  5.  
  6. access_log /data/log/nginx/myjumpserver_access.log main;
  7. error_log /data/log/nginx/myjumpserver_error.log;
  8.  
  9. location / {
  10. uwsgi_pass 192.168.10.13:;
  11. include uwsgi_params;
  12. }
  13. # django项目文件, MyJumpserver,静态资源这里加载
  14. location /static {
  15. alias /opt/wwwroot/MyJumpserver/static/;
  16. }
  17.  
  18. # redirect server error pages to the static page /50x.html
  19. error_page /50x.html;
  20. location = /50x.html {
  21. root html;
  22. }
  23. }
  24. # 访问localhost: ===>192.168.10.13:(uwsgi服务提供的)

3.1)python3环境的安装

python3 安装文档:https://www.cnblogs.com/linu/articles/9879572.html

  1. [root@Myjumpserver Python-3.6.]# python3 -V
  2. Python 3.6.
  3. [root@Myjumpserver Python-3.6.]# pip3 -V
  4. pip 9.0. from /usr/local/python3/lib/python3./site-packages (python 3.6)

3.2)python3模块安装

  1. pip3 install django==1.11. -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  2. pip3 install pymysql -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  3. pip3 install uwsgi -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  4. ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi # 特别重要

三、拷贝代码到nginx代码目录测试

1)python测试

  1. [root@Myjumpserver wwwroot]# ls /opt/wwwroot/
  2. MyJumpserver
  3. [root@Myjumpserver wwwroot]# cd MyJumpserver/
  4. [root@Myjumpserver MyJumpserver]# python3 manage.py runserver 192.168.10.13:
  5. Performing system checks...
  6.  
  7. System check identified no issues ( silenced).
  8. November , - ::
  9. Django version 1.11., using settings 'MyJumpserver.settings'
  10. Starting development server at http://192.168.10.13:888/
  11. Quit the server with CONTROL-C.

2)使用uwsgi测试,http方式启动

  1. [root@Myjumpserver MyJumpserver]# ls
  2. backup manage.py MyJumpserver static static_time.py templates test.py uwsgi.ini uwsgi.log uwsgi.pid web01
  3. [root@Myjumpserver MyJumpserver]# vim uwsgi.ini
  4. [root@Myjumpserver MyJumpserver]# pwd
  5. /opt/wwwroot/MyJumpserver
  6. [root@Myjumpserver MyJumpserver]# ls
  7. backup manage.py MyJumpserver static static_time.py templates test.py uwsgi.ini uwsgi.log uwsgi.pid web01
  8. [root@Myjumpserver MyJumpserver]# cat uwsgi.ini
  9. [uwsgi]
  10. # 使用nginx 连接时使用
  11. # socket=192.168.10.13:
  12.  
  13. # 直接做web服务器使用
  14. http=192.168.10.13:
  15. # 项目目录
  16. chdir=/opt/wwwroot/MyJumpserver
  17.  
  18. # 项目中wsgi.py 文件的目录,相对于项目目录
  19. wsgi-file=MyJumpserver/wsgi.py
  20. processes=
  21. threads=
  22. master=True
  23. pidfile=uwsgi.pid
  24. daemonize=uwsgi.log

启动命令

  1. uwsgi --ini uwsgi.ini
  2. ps ajx|grep uwsgi
  3. 停止
  4. uwsgi --stop uwsgi.pid(不好用,经常报pid找不到)
  5. sudo pkill -f uwsgi -(不好用,有可能报错,无效的-)
  6. killall - uwsgi(该命令最好用)  yum install psmisc -y 安装killall命令

启动程序

  1. [root@Myjumpserver MyJumpserver]# uwsgi --ini uwsgi.ini
  2. [uWSGI] getting INI configuration from uwsgi.ini
  3. [root@Myjumpserver MyJumpserver]# ps -ef|grep uwsgi
  4. root : ? :: uwsgi --ini uwsgi.ini
  5. root : ? :: uwsgi --ini uwsgi.ini
  6. root : ? :: uwsgi --ini uwsgi.ini
  7. root : ? :: uwsgi --ini uwsgi.ini
  8. root : ? :: uwsgi --ini uwsgi.ini
  9. root : pts/ :: grep uwsgi

没有加载静态文件,说明成功。因为uwsgi不能使用Django的路径加载

3)使用socket方式启动,并配合nginx检查

访问网页

四、重点总结

1)uwsgi.ini文件

  1. [root@Myjumpserver MyJumpserver]# cat uwsgi.ini
  2. [uwsgi]
  3. # 使用nginx 连接时使用
  4. socket=192.168.10.13:
  5.  
  6. # 直接做web服务器使用
  7. #http=192.168.10.13:
  8. # 项目目录
  9. chdir=/opt/wwwroot/MyJumpserver
  10.  
  11. # 项目中wsgi.py 文件的目录,相对于项目目录
  12. wsgi-file=MyJumpserver/wsgi.py
  13. processes=
  14. threads=
  15. master=True
  16. pidfile=uwsgi.pid
  17. daemonize=uwsgi.log

2)nginx的配置文件,

  1. [root@Myjumpserver vhost]# cat jumpserver.conf
  2. server {
  3. listen ;
  4. server_name localhost;
  5.  
  6. access_log /data/log/nginx/myjumpserver_access.log main;
  7. error_log /data/log/nginx/myjumpserver_error.log;
  8.  
  9. location / {
  10. uwsgi_pass 192.168.10.13:;
  11. include uwsgi_params;
  12. }
  13. # django项目文件, MyJumpserver,静态资源这里加载
  14. location /static {
  15. alias /opt/wwwroot/MyJumpserver/static/;
  16. }
  17.  
  18. # redirect server error pages to the static page /50x.html
  19. error_page /50x.html;
  20. location = /50x.html {
  21. root html;
  22. }
  23. }
  24. # 访问localhost: ===>192.168.10.13:(uwsgi服务提供的)

3) django的后台静态资源加载

  1. server {
  2. listen ;
  3. server_name localhost;
  4.  
  5. access_log /data/log/nginx/pvzstar_access.log main;
  6. error_log /data/log/nginx/pvzstar_error.log;
  7.  
  8. location / {
  9. uwsgi_pass 192.168.2.155:;
  10. include uwsgi_params;
  11. }
  12. # django项目文件, MyJumpserver,静态资源这里加载
  13. location /static {
  14. alias /usr/local/python3/lib/python3./site-packages/django/contrib/admin/static/;
  15. }
  16.  
  17. # redirect server error pages to the static page /50x.html
  18. error_page /50x.html;
  19. location = /50x.html {
  20. root html;
  21. }
  22. }

实质

返回nginx的80端口实质指向了uwsgi的socket连接对象

即 http:192.168.10.13  ==>socket 192.168.10.13:8888

Django+Uwsgi+Nginx项目部署文档的更多相关文章

  1. docker简单使用+django+uwsgi+nginx项目部署

    使用docker 搭建 centos7 环境: 主机环境:windows 10专业版 一.安装docker Hub.docker.com官网下载 docker for windows 安装完成后,任务 ...

  2. kettle开源项目部署文档

    kettle开源项目部署文档 1.kettle简介 kettle是一款国外开源的ETL(Extract Transform Load)工具,纯java编写,可以在Windows.Linux.Unix上 ...

  3. Diango + uwsgi + nginx 项目部署(可外网访问)

    自己通过nginx uwsgi 部署django项目,查询了很多资料,遇到了很多问题,最终完成了部署,趁着心情愉悦,写个随笔,为曾像我一样苦寻解决方案的小伙伴们提供些思路. 安装Nginx: #安装n ...

  4. 阿里云 centos7 django + uWSGI+Nginx + python3 部署攻略

    centos7+nginx+python3+django+uwsgi配置Django 项目部署   1.租的服务器(选择centos)的话,需要在阿里云后台控制台开放几个端口,克隆一下已开放的端口,t ...

  5. Django部署,Django+uWSGI+nginx+Centos部署

    说明:系统是在windows上开发的,使用django1.11.4+python3.6.3开发,需要部署在centos6.4服务器上. 第一步:在Centos6.4上安装Python3.6.2 安装请 ...

  6. django+uwsgi+nginx的部署

    1.下载与项目对应的django版本pip3 install django==1.11.16 -i https://pypi.douban.com/simple/2.用django内置的wsgi模块测 ...

  7. Django+uwsgi+Nginx安装部署

    安装 安装Nginx Nginx是最流行的高性能HTTP服务器. 安装pcre: wget https://sourceforge.net/projects/pcre/files/pcre/8.37/ ...

  8. django+uwsgi+nginx+sqlite3部署+screen

    note:可通过该命令查找文件未知 sudo find / -name filename 一:项目(github) ssh root@server ip         #  连接你的服务器 git ...

  9. centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)

     1.yum安装nginx 下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/7/noarch/RPMS/ngin ...

随机推荐

  1. 全国高校绿色计算大赛 预赛第一阶段(C++)第2关:扔桃子

    挑战任务 动物园有一只小猴子喜欢吃桃子,不过它有个很独特的习惯,每次都把找到的桃子分成相等的两份,吃掉一份,留一份.如果不能等分,小猴子就会丢掉一个然后再分.第二天再继续这个过程,直到最后剩一个桃子了 ...

  2. 三个<li>元素放一行

    <ul><li style="float:left;display:inline;">0</li><li style="floa ...

  3. [剑指Offer]45-把数组排成最小的数

    题目链接 https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993?tpId=13&tqId=11185&t ...

  4. js 定时执行

    代码: 格式例子: setInterval(方法名,1000*60); setInterval("方法名()",1000*60); setInterval(function () ...

  5. ajax POST跨域请求完美解决

    方式: js前端请求: function getOcrInfo(imageData){$.ajax({   url: 'http://localhost:8080/LSWS/ws/ocr/getWeb ...

  6. HelloWorld 基础语法

    所有内容取自菜鸟教程 public class HelloWorld {    /* 第一个Java程序     * 它将打印字符串 Hello World     */    public stat ...

  7. static 构造函数的认识

    最近,看到一道面试题,如下 class Class1 { ; static Class1() { count++; } public Class1() { count++; } } Class1 on ...

  8. Linux系统下重启Tomcat

    在Linux系统下,重启Tomcat使用命令操作的! 首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh 查看 ...

  9. FOR ALL ENTRIES的使用

    使用FOR ALL ENTRIES时注意: 1.一定要确定要有是否为空的判断 2.一定要注明两个表之间数据的关系 eg: IF GT_TJ30T[] IS NOT INITIAL.      SELE ...

  10. jQuery 向另一个页面传参,同时跳转到该页面

    为了使参数能够传递到另外一个页面,使用ajax的跳转方式 $.ajax({ type: "POST", url:"/admin/sysjgl/sysjck/sjcs&qu ...