アプリケーションの本番環境ではCentOSを使うことが多いです。
※CentOS8の後継は無いらしい。amazon linuxはどうなっちゃうん…?
コンテナが主流になるとalpineとかDebian系になってくんでしょうか
なので作るときもCentOSを使えると公開するときに困ることが少ないので
できればCentOSの開発環境を手近に置いておきたいのです
Windowsにlinux環境が欲しいだけなら「WSL」という選択肢もありますが
まだ安心して使える「公式なCentOS」はないようです。
Ubuntuは情報も多いし安定しているようですが、ガッツリ開発するぜ!となると
Linux
なの?などの不安を感じます。
そこでVM(Virtualbox) だと
Vagrantと一緒に入れてしまえば環境を増やすのも容易
ほとんどのLinuxディストリビューションが選択できる
多分ちゃんとしたLinux
情報は騙されるほどある
とはいえダブルクリックからポチポチポチ終わりっ!ってものではないし
環境をイチから毎回クリクリ構築するのは面倒です
なのでvagrant up
で自分好みの環境がプリッとできる手順を残しておこうと思った
用途は(主にRubyでの)アプリケーション開発がほとんど
以下のリソースが入った環境を作ります
windows: 10(Home) vagrant: Installed Version: 2.0.2
CentOS Linux release 7.5.1804 (Core) ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] zsh 5.0.2 (x86_64-redhat-linux-gnu) mysql 5.7.22 Docker 18.03.1-ce, build 9ee9f40 docker-compose 1.6.2, build 4d72027 NVIM 0.2.2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
# config.vm.box_check_update = false
# config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.network "forwarded_port", guest: 8001, host: 8001
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
# Macの場合
# home = Pathname(`echo $HOME/../`.strip)
# user = Pathname(`echo $HOME/`.strip).basename
# current = Pathname(`pwd -P`.strip)
# relative_home_path = File.join(home.relative_path_from(current).to_s, user)
# config.vm.synced_folder relative_home_path, "/home/vagrant/mac", owner: "vagrant", group: "vagrant"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "2048"
end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", privileged: false, inline: <<-SHELL
echo 'Install Docker'
sudo yum remove docker docker-common docker-selinux docker-engine
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum install -y docker-ce
sudo usermod -aG docker vagrant
sudo systemctl start docker
sudo systemctl enable docker
echo 'Install(Update) Git'
sudo yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf perl-devel readline-devel bzip2 gcc wget
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
cd ../
sudo rm -rf git
echo 'yum Update!'
sudo yum -y update
echo 'Install Zsh'
sudo yum -y install zsh
sudo chsh -s /bin/zsh vagrant
touch ~/.zprofile
echo 'Install rbenv'
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(rbenv init -)"' >> ~/.zprofile
source ~/.zprofile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'Install Ruby'
rbenv install --list | grep "^[ 0-9\.-]*$" | sort | tail -n 1 | xargs rbenv install
rbenv install --list | grep "^[ 0-9\.-]*$" | sort | tail -n 1 | xargs rbenv global
gem install bundler
gem install rails
echo 'Install MySQL(5.7)'
sudo yum -y remove mariadb-libs
sudo rm -rf /var/lib/mysql
sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
sudo yum -y install mysql-community-server
sudo systemctl enable mysqld.service
echo 'Start MySQL'
sudo systemctl start mysqld.service
echo 'Initial Password'
sudo echo `cat /var/log/mysqld.log | grep password`
echo 'Install NeoVim'
sudo yum -y install epel-release
sudo curl -o /etc/yum.repos.d/dperson-neovim-epel-7.repo https://copr.fedorainfracloud.org/coprs/dperson/neovim/repo/epel-7/dperson-neovim-epel-7.repo
sudo yum -y install neovim
mkdir -p ~/.config/nvim/colors
cd ~/.config/nvim/colors
wget https://raw.githubusercontent.com/raphamorim/lucario/master/colors/lucario.vim
echo 'export XDG_CONFIG_HOME="$HOME/.config"' >> ~/.zprofile
mkdir -p ~/.cache/dein
curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
sh ./installer.sh ~/.cache/dein
rm installer.sh
echo 'SetUp configs'
cd ~/
mkdir .share
cd .share
git clone https://github.com/tko-t/dotfiles.git
cd ~/
ln -s ~/.share/dotfiles/centos/init.vim ~/.config/nvim/init.vim
ln -s ~/.share/dotfiles/centos/zshrc ~/.zshrc
ln -s ~/.share/dotfiles/centos/tmux.conf ~/.tmux.conf
echo 'Other'
sudo yum -y install colordiff
sudo timedatectl set-timezone Asia/Tokyo
SHELL
# 終わったら mysql_secure_installation @see https://enomotodev.hatenablog.com/entry/2016/09/01/225200
# sudo yum -u update はcurlが古くてhttpでgit clone できなかったたので追加
# dockerのバージョン指定
# yum list docker-ce.x86_64 --showduplicates | grep docker-ce-stable | sort | tail -n 1 | awk '{print "docker-ce-"$2}' | xargs sudo yum install -y
# zshrcもやっちゃいたいとき
# git clone https://github.com/abgata20000/zsh.d.git ~/.zsh.d
# echo "source ~/.zsh.d/zshrc" > ~/.zshrc
# echo "source ~/.zsh.d/zshenv" > ~/.zshenv
end
コメント