服务器准备
操作系统 | 内核 | IP |
CentOS Linux 7 | 3.10 | 192.168.1.108 |
升级sqlite3
由于centos7默认sqlite3版本比较低,启动项目会因为sqlite3版本过低无法启动
- 检查sqlite3默认版本
- 下载高版本sqlite3
wget --no-check-certificate https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
- 解压
tar xf sqlite-autoconf-3270200.tar.gz
- 编译安装
cd sqlite-autoconf-3270200
./configure --prefix=/usr/local
make && make install
- 替换旧版本sqlite3
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
- 设置开机自动加载
vim ~/.bashrc
export LD_LIBRARY_PATH="/usr/local/lib" #增加
- 重启服务器
reboot
安装Python3
- 安装依赖包
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
- 下载python3 压缩包
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
- 编译安装
mkdir /usr/local/python3
tar xf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
创建虚拟环境
#安装virtualenv
pip3 install virtualenv -i https://mirrors.aliyun.com/pypi/simple/
ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
#创建虚拟目录
[root@k8s-node02 ~]# virtualenv web
#切换到虚拟环境
[root@k8s-node02 ~]# source web/bin/activate
在虚拟环境中安装ipython
(web) [root@k8s-node02 ~]# pip install ipython -i https://mirrors.aliyun.com/pypi/simple/
在虚拟环境中安装django
- 查看安装列表
- 安装django3
(web) [root@k8s-node02 ~]# pip install django -i https://mirrors.aliyun.com/pypi/simple/
创建项目(工程)
(web) [root@k8s-node02 ~]# django-admin startproject myweb
运行项目
访问项目
修改settings.py配置文件 ALLOWED_HOSTS = ["*"]
再次访问:
创建cmdb应用
(web) [root@k8s-node02 myweb]# django-admin startapp cmdb
生成迁移文件
(web) [root@k8s-node02 myweb]# python manage.py migrate
下节继续分享,喜欢的朋友可以给个关注