django项目部署
步骤
1.github建立新仓库
[email protected]:yc913344706/learning_log.git
2.本地安装git
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log
$ git --version
git version 2.16.0.windows.2
3. 创建.gitignore并编辑
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ touch .gitignore
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ cat .gitignore
ll_env/
__pycache__/
*.pyc
*.sqlite3
4. 建立本地仓库
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ git init
Initialized empty Git repository in E:/yc_study/python/django/sys/workspace/learning_log/.git/
5. 添加文件
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log (master)
$ git add .
6. 提交到本地仓库
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log/ll_env (master)
$ git commit -am "Initialize the project"
-- snip --
7. 关联github远程仓库
[email protected] MINGW64 /e/yc_study/python/django/sys/workspace/learning_log/ll_env (master)
$ git remote add origin [email protected]:yc913344706/learning_log.git
8. push代码
如果在github的代码仓里原本有文件,则需要先pull
但是由于本地仓库和远程仓库有不同祖先,所以需要“合并不同版本的历史”
然后再次push即可
9. 服务器获取代码
9.1 服务器安装git
9.2 服务器生成公私钥
[[email protected] ~]$ ssh-keygen -t rsa -C "[email protected]"
9.3添加公钥到github
9.4 验证服务器git是否OK
[[email protected] .ssh]$ ssh -T [email protected]
9.5 配置服务器的git全局信息
[[email protected] .ssh]$ git config --global user.name "rhel_7"
[[email protected] .ssh]$ git config --global user.email "[email protected]"
9.6 拉取代码
[[email protected] py_web_project]$ pwd
/data01/py_web_project
[[email protected] py_web_project]$ git clone [email protected]:yc913344706/learning_log.git
10 开发服务器测试代码是否可用
10.1安装python
[[email protected] tools]$ wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
[[email protected] tools]$ tar -xf Python-3.6.3.tgz
[[email protected] tools]$ cd Python-3.6.3/
[[email protected] Python-3.6.3]$ sudo yum -y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel python-devel libyaml unzip libffi-devel
[[email protected] Python-3.6.3]$ sudo ./configure --prefix=/usr/local
[[email protected] Python-3.6.3]$ sudo make -j
[[email protected] Python-3.6.3]$ sudo make install
[[email protected] Python-3.6.3]$ sudo mv /usr/bin/python /usr/bin/python_2_7_old
[[email protected] Python-3.6.3]$ sudo ln -s /usr/local/bin/python3.6 /usr/bin/python
[[email protected] Python-3.6.3]$ python --version
Python 3.6.3
10.2 安装pip
[[email protected] tools ]$ wget https://bootstrap.pypa.io/get-pip.py
[[email protected] tools]$ sudo python get-pip.py
[[email protected] tools]$ pip --version
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
10.3 安装virtualenv
[[email protected] tools]$ pip install --user virtualenv
10.4 创建虚拟环境
[[email protected] tools]$ cd /data01/py_web_project/learning_log
[[email protected] learning_log]$ virtualenv ll_env
[[email protected] learning_log]$ ls
learning_log learning_logs ll_env manage.py README.md
10.5 激活虚拟环境
[[email protected] learning_log]$ source ll_env/bin/activate
(ll_env) [[email protected] learning_log]$
10.6 虚拟环境中安装依赖环境
(ll_env) [[email protected] learning_log]$ pip install -r requirements.txt
10.7 迁移数据库
(ll_env) [[email protected] learning_log]$ python manage.py migrate
10.8 创建超级管理员
(ll_env) [[email protected] learning_log]$ python manage.py createsuperuser
10.9 开发服务器启动服务器并测试
(ll_env) [[email protected] learning_log]$ python manage.py runserver 0.0.0.08080
[[email protected] ~]$ curl 127.0.0.1:8080 <p> <a href="/">Learning Logs</a> - <a href="/topics/">Topics</a> </p> <p>YC‘s Learning Logs</p> [[email protected] ~]$ curl 192.168.0.101:8080 curl: (7) Failed connect to 192.168.0.101:8080; Connection refused [[email protected] ~]$ sudo firewall-cmd --state running [[email protected] ~]$ sudo firewall-cmd --get-active-zones public interfaces: ens33 [[email protected] ~]$ sudo firewall-cmd --permanent --zone=home --change-interface=ens33 The interface is under control of NetworkManager, setting zone to ‘home‘. success [[email protected] ~]$ sudo firewall-cmd --get-active-zones home interfaces: ens33 [[email protected] ~]$ sudo firewall-cmd --permanent --zone=home --add-port=8080/tcp success [[email protected] ~]$ sudo firewall-cmd --reload success [[email protected] ~]$ sudo firewall-cmd --zone=home --list-all home (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: ssh mdns samba-client dhcpv6-client ports: 8080/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [[email protected] ~]$ curl yc.test.com:8080 <p> <a href="/">Learning Logs</a> - <a href="/topics/">Topics</a> </p> <p>YC‘s Learning Logs</p>
xshell中新开虚拟终端进行调试
11 nginx+wsgi
TODO:待添加操作步骤
参考资料
tortoisegit管理密钥问题
https://www.cnblogs.com/cglNet/p/3706860.html
git无法pull仓库refusing to merge unrelated histories
https://blog.csdn.net/lindexi_gd/article/details/52554159
Django 部署(Nginx)
https://code.ziqiangxuetang.com/django/django-nginx-deploy.html
原文地址:https://www.cnblogs.com/yc913344706/p/9131366.html