研究室のサーバを新しくする(準備)
研究室にあるサーバが3台ある。
Minecraftとwikiのサーバ、研究室生用smbサーバ、授業資料配布用smbサーバ
この3台をVMにして一台にしたい。
仮想化ソフトウェアに何を使おうかいろいろ考えたが、今回はKVMとvagrantにすることに。
とりあえず母艦になるサーバに環境を作る
[root@localhost ~]# yum install qemu-kvm libvirt libvirt-devel gcc patch -y [root@localhost ~]# modprobe kvm_intel [root@localhost ~]# systemctl restart libvirtd
とりあえずこんなもんか つぎはvagrant
[root@localhost ~]#curl -LO https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm [root@localhost ~]#rpm -ivh vagrant_2.0.2_x86_64.rpm [root@localhost ~]#vagrant plugin install vagrant-libvirt [root@localhost ~]#vagrant box add centos/7
これで準備できたはず
[root@localhost ~]# vagrant init centos/7 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. [root@localhost ~]# vagrant up Bringing machine 'default' up with 'kvm' provider... ==> default: Box 'centos/7' could not be found. Attempting to find and install... default: Box Provider: kvm default: Box Version: >= 0 ==> default: Loading metadata for box 'centos/7' default: URL: https://vagrantcloud.com/centos/7 The box you're attempting to add doesn't support the provider you requested. Please find an alternate box or use an alternate provider. Double-check your requested provider to verify you didn't simply misspell it. If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is released. Name: centos/7 Address: https://vagrantcloud.com/centos/7 Requested provider: [:kvm]
あれ、こけた プロバイダを指定しないといけないのか、、、
[root@localhost ~]# vagrant up --provider=libvirt Bringing machine 'default' up with 'libvirt' provider... ==> default: Creating image (snapshot of base box volume). Volume for domain is already created. Please run 'vagrant destroy' first.
指定して見たけどダメ。 どうやら、作成されたボリュームがあるとダメみたい。
[root@localhost ~]# virsh vol-list default 名前 パス ------------------------------------------------------------------------------ root_default.img /var/lib/libvirt/images/root_default.img [root@localhost ~]# rm /var/lib/libvirt/images/root_default.img
確認して削除
[root@localhost ~]# systemctl restart libvirtd [root@localhost ~]# vagrant up --provider=libvirt Bringing machine 'default' up with 'libvirt' provider... ==> default: Creating image (snapshot of base box volume). ==> default: Creating domain with the following settings... ==> default: -- Name: root_default ==> default: -- Domain type: kvm ==> default: -- Cpus: 1 ==> default: ==> default: -- Feature: acpi ==> default: -- Feature: apic ==> default: -- Feature: pae ==> default: -- Memory: 512M ==> default: -- Management MAC: ==> default: -- Loader: ==> default: -- Base box: centos/7 ==> default: -- Storage pool: default ==> default: -- Image: /var/lib/libvirt/images/root_default.img (41G) ==> default: -- Volume Cache: default ==> default: -- Kernel: ==> default: -- Initrd: ==> default: -- Graphics Type: vnc ==> default: -- Graphics Port: -1 ==> default: -- Graphics IP: 127.0.0.1 ==> default: -- Graphics Password: Not defined ==> default: -- Video Type: cirrus ==> default: -- Video VRAM: 9216 ==> default: -- Sound Type: ==> default: -- Keymap: en-us ==> default: -- TPM Path: ==> default: -- INPUT: type=mouse, bus=ps2 ==> default: Creating shared folders metadata... ==> default: Starting domain. ==> default: Waiting for domain to get an IP address... ==> default: Waiting for SSH to become available... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Configuring and enabling network interfaces... default: SSH address: 192.168.121.10:22 default: SSH username: vagrant default: SSH auth method: private key ==> default: Rsyncing folder: /root/ => /vagrant
あがってきた
[root@localhost ~]# vagrant ssh [vagrant@localhost ~]$
いけた。
とりあえず、今日はここまで、また時間がある時に他の設定をしよう。