安装
- 语言选择英语
- 按 F4,选择”Install a minimal system”
- 按 F6,选择”Expert mode”
- 国家选择 中国
- locale 选择 en_US.UTF-8
- Additional locales 选择 zh_CN.UTF-8, zh_CN.GB18030, zh_CN.GBK
- system locale 选择 en_US.UTF-8
- 跳过 Access software for a blind person using a braille display
- 选择不自动检测键盘布局
- Country of origin for the keyboard,选择 English (US)
- Installer components to load: 不选择任何组件
- Allow login as root? 选择 Yes
- Create a normal user account now? 选择 Yes
- Full name for the new user: 输入 vagrant
- Username for your account: 使用默认的 vagrant
- 密码设置为: vagrant
- Use weak password? 选择 Yes
- Encrypt your home directory? 选择 No
- Set the clock using NTP? 选择 YES
- Partioning method: 选择 “Guided - use entire disk”
- Partioning scheme: 选择 “Separate /home partition”
- Kernel to install: 选择 “linux-generic”
- Drivers to include in the initrd: 选择 “generic: include all available drivers”
- Use a network mirror? 选择 “No”
- Services to use: 只启用 “security updates”
- How do you want to manage upgrades on this system? 选择 “No automatic updates”
- Choose software to install: 选择
- Force GRUB installation to the EFI removable media path? 选择 No
- Is the system clock set to UTC? 选择 Yes
配置
以下操作除特别说明,都是以 root 账号操作。
ssh 远程登录支持
- 选择虚拟机的网络配置,在默认的 NAT 网卡上添加端口映射 127.0.0.1:2222 => 22
- SSH 登录到虚拟机里:
ssh -p 2222 vagrant@127.0.0.1
- 运行命令 su,以切换到 root 账号
- 更改完后,重启操作系统
注: SSH 登录到虚拟机里是为了方便复制粘贴命令等操作;ubuntu 16.04 默认不允许 root 账号远程登录,故只能使用普通账号登录,再切换到 root 账号
更改 apt 源
1
| cp sources.list{,.`date +'%F'`}
|
1 2 3 4 5 6 7 8 9 10 11
| deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse # deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse #deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse #deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse #deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse #deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse #deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
|
- 安装 vim:
apt-get install -y vim-nox
- 安装 git:
1 2
| apt-get install -y git apt-get install -y git-extras
|
- 保存 sources.list 后,运行
apt-get update
命令
安装 oh my zsh
- 安装 zsh:
apt-get install zsh
- 参照官方文档安装
- 以 vagrant 账号运行如下命令:
1
| sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
|
配置 oh my zsh
- 更改 oh my zsh 主题:
vim ~/.zshrc
,把ZSH_THEME="robbyrussell"
改成 ZSH_THEME="tjkirch_mod"
- 添加插件git-extras,即把 .zshrc 文件中的
plugins=(git)
改成plugins=(git git-extras)
- 取消 oh my zsh 的自动更新: 取消 .zshrc 文件中
DISABLE_AUTO_UPDATE="true"
前的井号”#”
- 设置编辑时使用的默认编辑器:往 .zshrc 文件末尾加上:
1 2 3
| export EDITOR='vim' export SYSTEMD_EDITOR="/usr/bin/vim" export GIT_EDITOR=vim
|
1 2
| ln -s /home/vagrant/.zshrc /root/.zshrc ln -s /home/vagrant/.oh-my-zsh/ /root/.oh-my-zsh
|
- 退出账号,并重新登录,以使 shell 的设置更改生效
- vagrant 无密码 sudo 配置
命令行运行 visudo
,往文件的最末尾加上
1
| vagrant ALL=(ALL) NOPASSWD: ALL
|
安装其他软件包
1 2 3 4 5 6 7 8 9 10 11
| apt-get install -y tree silversearcher-ag ack-grep net-tools dnsutils apt-get install -y git-svn subversion npm nodejs nodejs-legacy # nodejs-legacy 用于创建 /usr/bin/node 软链接 apt-get install -y nginx mysql-client mysql-server memcached redis-server redis-tools systemctl enable nginx mysql memcached redis-server php7.0-fpm systemctl start nginx mysql memcached redis-server php7.0-fpm npm --registry=https://registry.npm.taobao.org install -g cnpm cnpm install -g bower gulp gitbook-cli apt-get install -y build-essential unzip p7zip-full p7zip-full apt-get install -y php php-cli php-fpm php-mcrypt php-mysql php-curl php-pear php-dev php-phpdbg php-mcrypt php-mbstring mkdir /usr/local/src/php7-exts # PHP 扩展安装目录
|
安装 php-redis 扩展
1 2 3 4 5 6 7 8 9 10 11 12
| pecl install redis cat > /etc/php/7.0/mods-available/redis.ini << EOF ; configuration for php common module ; priority=20 extension=redis.so EOF phpenmod redis # 等价于下面的2条命令 # ln -s /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/cli/conf.d/20-redis.ini # ln -s /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/fpm/conf.d/20-redis.ini
|
安装 memcached 扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| apt-get install -y pkg-config libmemcached-dev cd /usr/local/src/php7-exts git clone -b php7 https://github.com/php-memcached-dev/php-memcached.git memcached cd memcached phpize ./configure make && make install cat > /etc/php/7.0/mods-available/memcached.ini << EOF ; configuration for php common module ; priority=20 extension=memcached.so EOF phpenmod memcached
|
安装 msgpack 扩展
1 2 3 4 5 6 7 8 9 10 11
| pecl install msgpack-beta cat > /etc/php/7.0/mods-available/msgpack.ini << EOF ; configuration for php common module ; priority=20 extension=msgpack.so EOF phpenmod msgpack
|
安装 yar 扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| apt-get install -y libcurl4-openssl-dev cd /usr/local/src/php7-exts git clone -b php7 https://github.com/laruence/yar.git yar cd yar phpize ./configure make && make install cat > /etc/php/7.0/mods-available/yar.ini << EOF ; configuration for php common module ; priority=20 extension=yar.so EOF phpenmod yar
|
安装 composer
1 2 3 4 5 6 7
| php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');" mv composer.phar /usr/local/bin/composer # 配置使用国内的Packagist镜像,以 vagrant 账号执行: composer config -g repo.packagist composer https://packagist.phpcomposer.com
|
PHP 配置修改
使用 vim 打开文件 /etc/php/7.0/fpm/pool.d/www.conf
,然后把 listen = /run/php/php7.0-fpm.sock
改成 listen = 127.0.0.1:9000
MySQL 配置
- 安全增强,命令行下运行命令:
mysql_secure_installation
vagrant 打包 box
- 安装 VBoxAddition: 宿主机上运行
vagrant plugin install vagrant-vbguest
(vagrant-vbguest 会自动安装 VBoxAddtion)
- 在虚拟机里运行: ssh-keygen 生成公钥、私钥
- 在宿主机上执行:
vagrant package --base ubuntu_1604
, ubuntu_1604
是创建的虚拟机的名称
- Vagrantfile 使用 附件