zhuifengtjy 2019-06-28
需要了解的基本知识:
下载地址如下(安装适合自己操作系统的软件): https://www.virtualbox.org/wiki/Downloads
下载地址如下(安装适合自己操作系统的软件): http://downloads.vagrantup.com/
.box
而不是.iso
)http://www.vagrantbox.es/ 挑选一个自己想要的系统镜像,比方说我用centos7.2纯净版的,然后将如下地址站到迅雷或者直接浏览器下载即可 https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.2/vagrant-centos-7.2.box
windows下安装这两个程序:
vagrant
virtualbox
D:\>cd study D:\study>cd devops-8 D:\study\devops-8>cd data D:\study\devops-8\data>vagrant box list centos7-dev (virtualbox, 0) centosbox (virtualbox, 0) D:\study\devops-8\data>vagrant init centos7-dev #初始化环境路径,并生成Vagrantfile配置文件
#将端口映射改成8000 config.vm.network "forwarded_port", guest: 80, host: 8000
D:\study\devops-8\data>vagrant up 镜像存在位置: C:\Users\wanghui\.vagrant.d\boxes\centos7-dev\0
user:vagrant pass:vagrant host:127.0.0.1 port:2222
==> default: Mounting shared folders... default: /vagrant => D:/study/devops-8/data
django支持版本:1.11
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ,时区设置; timedatectl status ,查看时间同步状态; yum install ntp -y timedatectl set-ntp true ,开启网络时间同步;
yum -y install gcc gcc-c++ openssl openssl-devel vim net-tools wget zip unzip lrzsz mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install openssl-devel readline-devel unzip #解决依赖 wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz tar xf Python3.6.6.tgz cd Pyrthon3.6.6 # configure ./configure --enable-optimizations # vim Modules/Setup 放开如下的配置 _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto #安装 make altinstall
# tee /etc/pip.conf <<EOF [global] index-url = http://pypi.douban.com/simple trusted-host = pypi.douban.com [list] format=columns EOF
pip3.6 install virtualenv su - vagrant cd /home/vagrant virtualenv -p /usrlocal/bin/python3.6 venv3 source venv3/bin/activite pip3 install "django>=1.11,<2.0"
yum -y install mariadb mariadb-server mariadb-devel # vim /etc/my.cnf 配置 [mysqld] port = 3306 default-storage-engine = innodb innodb_file_per_table collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 [mysql] default-character-set=utf8 -----服务启动----- systemctl start mariadb systemctl enable mariadb -----初始化配置----- mysql_secure_installation #密码设置成123456 ------安装python-mysql插件------ [vagrant@localhost ~]$ source /home/vagrant/venv3/bin/activate pip3 install mysqlclient ------创建数据库------- mysql -uroot -p123456 -e "create database devops CHARACTER SET utf8;"
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django', 'USER': 'root', 'PASSWORD': '123456', 'HOST': '127.0.0.1', 'PORT': 3306, 'OPTIONS':{ 'init_command': 'SET default_storage_engine=INNODB;', }, } }