一、基本环境搭建

1)查看服务器

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

2)安装基本的依赖包

yum -y install gcc
yum -y install gcc-c++
yum -y install glibc.i686
yum -y install dos2unix
yum -y install vsftpd
yum install -y redhat-lsb
yum -y install zlib*
yum install nss -y

二、搭建mysql,nginx,python环境

1.1)安装mysql5.6版本

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

1.2)设置mysql

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

1.3)测试连接

2.1)安装nginx

yum install -y  gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel  安装依赖包
cd /opt/
wget http://nginx.org/download/nginx-1.9.9.tar.gz
cd nginx-1.9.
useradd nginx -s /sbin/nologin -M
./configure --user=nginx --group=nginx # 编译参数
make && make install
[root@Myjumpserver nginx]# ll /usr/local/nginx/
total
drwx------ nginx root Nov : client_body_temp
drwxr-xr-x root root Nov : conf
drwx------ nginx root Nov : fastcgi_temp
drwxr-xr-x root root Nov : html
drwxr-xr-x root root Nov : logs
drwx------ nginx root Nov : proxy_temp
drwxr-xr-x root root Nov : sbin
drwx------ nginx root Nov : scgi_temp
drwx------ nginx root Nov : uwsgi_temp
[root@Myjumpserver nginx-1.9.]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2.2)常用的编译参数

./configure \
--prefix=/home/nginx \
--sbin-path=/usr/sbin/nginx \
--user=nginx \
--group=nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/home/log/nginx/error.log \
--http-log-path=/home/log/nginx/access.log \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/home/run/nginx.pid \
--with-pcre=/home/software/pcre-8.35 \
--with-zlib=/home/software/zlib-1.2. \
--with-openssl=/home/software/openssl-1.0.1i

编译参数说明

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

2.3)nginx文件夹说明

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

2.4)nginx启动命令

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

2.5)修改nginx配置文件

user nginx;
worker_processes ;
worker_cpu_affinity ;
worker_rlimit_nofile ; pid /var/run/nginx.pid; events {
worker_connections ;
use epoll;
multi_accept off;
} http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream; log_format main '$remote_addr --- $remote_user --- [$time_local] --- $request --- '
'"$status" --- $body_bytes_sent --- "$http_referer" --- '
'"$http_user_agent" --- "$http_x_forwarded_for"';
log_format mtr '$remote_addr [$time_local] "$request_uri" '
'$status "$http_referer" '
'"$http_user_agent" "$host"'; sendfile on; keepalive_timeout ;
client_header_timeout ;
client_body_timeout ;
server_tokens off;
tcp_nodelay on; gzip on; include /usr/local/nginx/conf/vhost/*.conf; fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
#fastcgi_buffer_size 16k;
#fastcgi_buffers 16 16k;
#fastcgi_busy_buffers_size 16k;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k; server_names_hash_bucket_size 128;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
client_max_body_size 100k;
open_file_cache max=51200 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
}

nginx.conf

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

[root@Myjumpserver vhost]# cat jumpserver.conf
server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
access_log /data/log/nginx/myjumpserver_access.log main;
error_log /data/log/nginx/myjumpserver_error.log; location / {
uwsgi_pass 192.168.10.13:;
include uwsgi_params;
} location /static {
alias /opt/wwwroot/MyJumpserver/static/;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

jumpserver.conf

语法测试

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

关于jumpserver.conf配置文件说明

[root@Myjumpserver vhost]# cat jumpserver.conf
server {
listen ;
server_name localhost; access_log /data/log/nginx/myjumpserver_access.log main;
error_log /data/log/nginx/myjumpserver_error.log; location / {
uwsgi_pass 192.168.10.13:;
include uwsgi_params;
}
# django项目文件, MyJumpserver,静态资源这里加载
location /static {
alias /opt/wwwroot/MyJumpserver/static/;
} # redirect server error pages to the static page /50x.html
error_page /50x.html;
location = /50x.html {
root html;
}
}
# 访问localhost: ===>192.168.10.13:(uwsgi服务提供的)

3.1)python3环境的安装

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

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

3.2)python3模块安装

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

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

1)python测试

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

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

[root@Myjumpserver MyJumpserver]# ls
backup manage.py MyJumpserver static static_time.py templates test.py uwsgi.ini uwsgi.log uwsgi.pid web01
[root@Myjumpserver MyJumpserver]# vim uwsgi.ini
[root@Myjumpserver MyJumpserver]# pwd
/opt/wwwroot/MyJumpserver
[root@Myjumpserver MyJumpserver]# ls
backup manage.py MyJumpserver static static_time.py templates test.py uwsgi.ini uwsgi.log uwsgi.pid web01
[root@Myjumpserver MyJumpserver]# cat uwsgi.ini
[uwsgi]
# 使用nginx 连接时使用
# socket=192.168.10.13: # 直接做web服务器使用
http=192.168.10.13:
# 项目目录
chdir=/opt/wwwroot/MyJumpserver # 项目中wsgi.py 文件的目录,相对于项目目录
wsgi-file=MyJumpserver/wsgi.py
processes=
threads=
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

启动命令

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

启动程序

[root@Myjumpserver MyJumpserver]# uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
[root@Myjumpserver MyJumpserver]# ps -ef|grep uwsgi
root : ? :: uwsgi --ini uwsgi.ini
root : ? :: uwsgi --ini uwsgi.ini
root : ? :: uwsgi --ini uwsgi.ini
root : ? :: uwsgi --ini uwsgi.ini
root : ? :: uwsgi --ini uwsgi.ini
root : pts/ :: grep uwsgi

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

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

访问网页

四、重点总结

1)uwsgi.ini文件

[root@Myjumpserver MyJumpserver]# cat uwsgi.ini
[uwsgi]
# 使用nginx 连接时使用
socket=192.168.10.13: # 直接做web服务器使用
#http=192.168.10.13:
# 项目目录
chdir=/opt/wwwroot/MyJumpserver # 项目中wsgi.py 文件的目录,相对于项目目录
wsgi-file=MyJumpserver/wsgi.py
processes=
threads=
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

2)nginx的配置文件,

[root@Myjumpserver vhost]# cat jumpserver.conf
server {
listen ;
server_name localhost; access_log /data/log/nginx/myjumpserver_access.log main;
error_log /data/log/nginx/myjumpserver_error.log; location / {
uwsgi_pass 192.168.10.13:;
include uwsgi_params;
}
# django项目文件, MyJumpserver,静态资源这里加载
location /static {
alias /opt/wwwroot/MyJumpserver/static/;
} # redirect server error pages to the static page /50x.html
error_page /50x.html;
location = /50x.html {
root html;
}
}
# 访问localhost: ===>192.168.10.13:(uwsgi服务提供的)

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

server {
listen ;
server_name localhost; access_log /data/log/nginx/pvzstar_access.log main;
error_log /data/log/nginx/pvzstar_error.log; location / {
uwsgi_pass 192.168.2.155:;
include uwsgi_params;
}
# django项目文件, MyJumpserver,静态资源这里加载
location /static {
alias /usr/local/python3/lib/python3./site-packages/django/contrib/admin/static/;
} # redirect server error pages to the static page /50x.html
error_page /50x.html;
location = /50x.html {
root html;
}
}

实质

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

即 http:192.168.10.13  ==>socket 192.168.10.13:8888

最新文章

  1. CXF:根据werservice代码生成WSDL(转)
  2. mysqlbinlog抽取某个表的信息
  3. 【转】博弈—SG函数
  4. python基础第四天(1)
  5. Android 数据存储之 SharedPreferences储存
  6. mount: can&#39;t find cdrom in /etc /fstab or /etc/mtab
  7. LNMP wget 记录
  8. Unix 主机认证配置
  9. 前后端分离Web项目中,RBAC实现的研究
  10. JVM基础01-内存分配
  11. head first python菜鸟学习笔记(第六章)
  12. c#基础(一)
  13. [BZOJ]1046 上升序列(HAOI2007)
  14. Harbor配置https认证
  15. Solr 16 - 增删改Solr中索引数据的几种方式 (在URL上或Web页面中操作)
  16. zookeeper启动时报Cannot open channel to X at election address Error contacting service. It is probably not running.
  17. Catogory如何添加属性
  18. poj 2449 Remmarguts&#39; Date(K短路,A*算法)
  19. Java虚拟机(一):JVM简介
  20. HTML meta标签总结,HTML5 head meta属性整理

热门文章

  1. git config --global user.email
  2. Android 单元测试四大组件Activity,Service,Content Provider , Broadcast Receiver
  3. 十个前端UI优秀框架
  4. JS参数转发
  5. [剑指Offer]53-在排序数组中查找数字(二分查找)
  6. f5健康检查
  7. django的 信号
  8. Compile、Make和Build的区别
  9. java_5.1 for循环
  10. linux命令学习之:netstat