須要瞭解的基本知識:html
下載地址以下(安裝適合本身操做系統的軟件): 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
virtualboxpython
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.11mysql
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;', }, } }