1.登录root用户在系统下新建用户
useradd -m zhaozhao
2. 为新用户(zhaozhao
)添加密码(默认创建的用户没有密码)
passwd zhaozhao
3.为新用户添加sudo权限
usermod -a -G adm zhaozhao usermod -a -G sudo zhaozhao
4.退出root用户,用新账户重新登录Linux
exitssh zhaozhao@主机ip地址
5.在用户根目录下新建项目目录(如果登录后控制键乱码,输入bash,然后回车即可!)
mkdir ~/data mkdir ~/data/{backup,code,logs,server,soft,virtual}
支持中文
sudo locale-gen zh_CN.UTF-8
6.安装python环境(大多数ubuntu自带,python环境,无需安装),本步骤可跳过
sudo apt install python3
为当前用户添加远程认证(可选)
ssh-keygen -t rsa # 生成加密算法为 rsa的秘钥ssh-copy-id zhaozhao@远程ip #将公钥拷贝到服务器端(公钥可多次使用,私钥相当于一卡通!)
7.将本地项目压缩,并通过scp, 传输到~/data/code
tar -zcvf fangyuanxiaozhan.tar.gz fangyuanxiaozhan
scp fangyuanxiaozhan.tar.gz zhaozhao@远程ip:~/data/code/fangyuanxiaozhan.tar.gz
8.将本地配置导出到文件,并将文件传输到服务端
pip freeze > requirements.txt
scp requirements.txt zhaozhao@远程ip:~/data/soft/requirements.txt
9.安装虚拟环境软件,并将virtualenvwrapper.sh配置到shell环境中
sudo apt install python-pip sudo pip install virtualenv sudo pip install virtualenvwrapper
virtualenvwrapper.sh
# 添加pytho虚拟环境配置vim ~/.bashrcexport WORKON_HOME=$HOME/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh
10. 创建虚拟环境,安装依赖包
# 创建虚拟环境mkvirtualenv dj_py3 --python="/usr/bin/python3"# 安装依赖包pip install -r ~/data/soft/requirements.txt
出现错误:Python.h: No such file or directory
解决方式:sudo apt-get install python3-dev
11.安装Nginx
1.上传软件包到指定目录
scp nginx-1.10.3.tar.gz zhaozhao@远程ip:~/data/soft/nginx-1.10.3.tar.gz scp openssl-1.0.2l.tar.gz zhaozhao@远程ip:~/data/soft/openssl-1.0.2l.tar.gz scp zlib-1.2.11.tar.gz zhaozhao@远程ip:~/data/soft/zlib-1.2.11.tar.gz
2.安装pcre(nginx正则匹配依赖)
sudo apt-get install libpcre3 libpcre3-dev
3.安装zlib
tar -zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11 ./configure make sudo make installcd ..
4.安装openssl(解压即可,目录~/data/soft/openssl-1.0.2l
)
tar -zxvf openssl-1.0.2l.tar.gz
5.安装nginx
# 解压nginxtar -zxvf nginx-1.10.3.tar.gz# 进入nginx安装目录cd nginx-1.10.3# 在指定位置安装nginx./configure --prefix=/opt/nginx/ --with-openssl=~/data/soft/openssl-1.0.2l# 编译make# 安装sudo make install# 启动cd /opt/nginx/sbin sudo ./nginx# 查看ps ajx | grep nginx
12.安装mysql(一定要设置密码,会避免很多麻烦)
sudo apt-get install mysql-server
13.配置uwsgi
在项目目录的同名模块下,新建配置文件
uwsgi.ini
uwsgi.ini
2.在配置文件中加入以下内容
[uwsgi]# 配置nginxsocket = 127.0.0.1:3309# 配置项目目录chdir = /home/zhaozhao/data/code/fangyuanxiaozhan# 配置入口模块wsgi-file = fangyuanxiaozhan/wsgi.py# 开启master, 将会多开一个管理进程, 管理其他服务进程master = True# 服务器开启的进程数量processes = 2# 服务器进程开启的线程数量threads = 4# 以守护进程方式提供服, 输出信息将会打印到log中# daemonize = wsgi.log# 退出的时候清空环境变量vacuum = true# 进程pidpidfile=uwsgi.pid
3.以配置好的文件 uwsgi.ini启动uwsgi
uwsgi --ini uwsgi.ini
14.配置启动nginx的文件
nginx.conf
nginx.conf
配置内容
#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; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} location / { # 将nginx所有请求转到uwsgi include uwsgi_params; # uwsgi的ip与端口 uwsgi_pass 127.0.0.1:3309; } location /static { alias /home/zhaozhao/data/code/fangyuanxiaozhan/static; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
2.重启
nginx
cd /opt/nginx/sbin sudo ./nginx -s stop sudo ./nginx
重启服务
ps ajx | grep uwsgikill -9 2844
部署完成
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦