环境安装
前戏
需要了解的基本知识:
需要的软件&镜像
- VirtualBox :号称是最强的免费虚拟机软件
下载地址如下(安装适合自己操作系统的软件):
https://www.virtualbox.org/wiki/Downloads
- Vagrant :也就是我们要创建和管理虚拟机的工具
下载地址如下(安装适合自己操作系统的软件):
http://downloads.vagrantup.com/
- 系统镜像:提供给vagrant去创建(我理解这个是专用的,因为文件下载之后的尾缀是
.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](https://www.vagrantup.com/downloads.html))
virtualbox](https://www.vagrantup.com/downloads.html))
目录准备
软件安装路径
开发环境配置路径
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配置文件
修改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
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
安装Python
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
修改pip配置
# tee /etc/pip.conf <<EOF
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
[list]
format=columns
EOF
安装virtualenv并初始化环境
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;"
- Django数据库配置
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;',
},
}
}