Quantcast
Channel: 開発メモ@uehi » Linux
Viewing all articles
Browse latest Browse all 10

CentOS6.5のVagrant box作る

$
0
0

VirtualboxにCentOSインストール

以下参考にしてインストール

http://www.linuxmaster.jp/linux_skill/2014/03/03centos65.html

結果以下の様になって

B6cd800f1d068032ebea46c321b059e9

再起動すると、再びインストール画面になるので仮想マシンの電源OFFにしてディスク割り当てを抜いておく。

以下のようになったらおk。

450d9609ba996e8d39fdf0e153488483

とりあえずhost環境のターミナルから接続できるようにする

電源落とす

設定>ネットワーク

アダプタ2を「ホストコンピュータアダプタ」にする。

起動

起動後以下編集

# cd /etc/sysconfig/network-scripts/

# vi ifcfg-eth1

DEVICE="eth1"
HWADDR="xx:xx:xx:xx:xx:xx" #アダプタ2のMACアドレス
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.56.10
NETMASK=255.255.255.0
NETWORK=192.168.56.0

TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

# /etc/init.d/network restart

ipv6無効

これしないとyum updateで以下のエラーでたので

# yum -y update
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base
  • /etc/sysconfig/network に NETWORKING_IPV6=no の設定を追加
  • chkconfig ip6tables off
  • 再起動

iptables、selinuxなどが有効になっている場合は、今後のインストールに影響が出るので停止

# /etc/rc.d/init.d/iptables stop
iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

# vi /etc/selinux/config

SELINUX=disabledに修正

サーバ再起動後、selinuxが無効となる

yum update

# rpm --import http://ftp.riken.jp/Linux/centos/RPM-GPG-KEY-CentOS-6
# yum -y update

ntpインストール

# yum -y install ntp

# vi /etc/ntp.conf

#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp

# /etc/rc.d/init.d/ntpd start
ntpd を起動中:                                             [  OK  ]
サーバ起動時に起動するようにする
# chkconfig ntpd on 

ユーザ作る

# useradd vagrant
# passwd vagrant
# groupadd admin
# usermod -G admin -a vagrant

パスワードはvagrantに。

vagrantユーザがパス無しsudoできるようにする

# visudo

末尾に以下追加

vagrant ALL=(ALL) ALL
%admin ALL=(ALL) NOPASSWD:ALL
Defaults env_keep=”SSH_AUTH_SOCK”

また

Defaults requiretty

↓
Defaults !requiretty

にする。しておかないとvagrant upで以下のエラーになるので

sudo: sorry, you must have a tty to run sudo

[参考]http://blog.inouetakuya.info/entry/20130831/1377957334

VirtualBox Guest Additionsのインストール

ファイル共有等に必要なため。

Device>GuestAddition〜押すと以下のエラー
どうもディスク・ドライブがないようだ。

Could not insert the VirtualBox Guest Additions disk image file into the virtual machine Cent6.5_LAMP, as the machine has no CD/DVD drives. Please add a drive using the storage page of the virtual machine settings window.

shutdownして設定>ストレージでコントローラー:IDEに追加

んで起動してもう一度Device>GuestAddition〜

必要なもの入れる

yum -y install gcc kernel-devel

※以下記述するが実際はこれが必要→yum -y install kernel-devel gcc make perl

マウントとインストール

# mkdir /mnt/cdrom
# mount -r /dev/cdrom1 /mnt/cdrom
# cd /mnt/cdrom/
# sh VBoxLinuxAdditions.run

Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

# VBoxControl --version
4.3.10r93012
# VBoxService --version
VBoxService: error: VbglR3Init failed with rc=VERR_FILE_NOT_FOUND

だめだった。

ログ見ると

# cat /var/log/vboxadd-install.log
make KBUILD_VERBOSE=1 CONFIG_MODULE_SIG= -C /lib/modules/2.6.32-431.11.2.el6.x86_64/build SUBDIRS=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 modules
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (          
     echo;                                        
     echo "  ERROR: Kernel configuration is invalid.";          
     echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";     
     echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";     
     echo;                                        
     /bin/false)
mkdir -p /tmp/vbox.0/.tmp_versions ; rm -f /tmp/vbox.0/.tmp_versions/*
make -f scripts/Makefile.build obj=/tmp/vbox.0
  gcc -Wp,-MD,/tmp/vbox.0/.VBoxGuest-linux.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include -Iinclude  -I/usr/src/kernels/2.6.32-431.11.2.el6.x86_64/include/uapi -I/usr/src/kernels/2.6.32-431.11.2.el6.x86_64/arch/x86/include -include /usr/src/kernels/2.6.32-431.11.2.el6.x86_64/include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_AVX=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=2048 -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -include /tmp/vbox.0/include/VBox/VBoxGuestMangling.h -I/lib/modules/2.6.32-431.11.2.el6.x86_64/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -I/tmp/vbox.0/vboxguest/ -I/tmp/vbox.0/vboxguest/include -I/tmp/vbox.0/vboxguest/r0drv/linux -D__KERNEL__ -DMODULE -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(VBoxGuest_linux)"  -D"KBUILD_MODNAME=KBUILD_STR(vboxguest)" -D"DEBUG_HASH=24" -D"DEBUG_HASH2=60" -c -o /tmp/vbox.0/.tmp_VBoxGuest-linux.o /tmp/vbox.0/VBoxGuest-linux.c
  set -e ; perl /usr/src/kernels/2.6.32-431.11.2.el6.x86_64/scripts/recordmcount.pl "x86_64" "64" "objdump" "objcopy" "gcc" "ld" "nm" "" "" "1" "/tmp/vbox.0/VBoxGuest-linux.o";
/bin/sh: perl: コマンドが見つかりません
make[2]: *** [/tmp/vbox.0/VBoxGuest-linux.o] エラー 127
make[1]: *** [_module_/tmp/vbox.0] エラー 2
make: *** [vboxguest] エラー 2
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

perlがない模様。

調べるとインストールにはkernel-devel gcc make perlが必要らしいので足りないぶんをインストール

# yum -y install make perl

参考

きをとりなおしてもう一度

# sh VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.10 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Building the OpenGL support module                         [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
Starting the VirtualBox Guest Additions                    [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

# VBoxControl --version
4.3.10r93012
# VBoxService --version
4.3.10r93012

ok

念のためyumのリポジトリ追加(しなくてもいいぽいが…)

wgetがないのでインストール

# yum -y install wget

現状インストールされているもの

# rpm -qa | grep release
centos-release-6-5.el6.centos.11.2.x86_64

epel, remi, romforgeをインストールする

# cd /usr/local/src/
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

以下が参考になりました。

参考
- 注意:epelファイルが存在しないとか古い場合は、以下のリンクから「epel-release」で始まるファイルを探すといいです。 http://dl.fedoraproject.org/pub/epel/6/x86_64/
- remiファイルが存在しないとか古い場合は、以下のリンクから「repository auto-configuration package : remi-release-6.rpm」で始まるファイルを探すといいです。 http://rpms.famillecollet.com/
- rpmforgeファイルが存在しないとか古い場合は、以下のリンクから「rpmforge-release-*.x86_64.rpm」で始まるファイルを探すといいです。 http://pkgs.repoforge.org/rpmforge-release/

インストール

# rpm --upgrade --verbose --hash epel-release-6-8.noarch.rpm remi-release-6.rpm rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

# rpm -qa | grep release
remi-release-6.5-1.el6.remi.noarch
epel-release-6-8.noarch
rpmforge-release-0.5.3-1.el6.rf.x86_64
centos-release-6-5.el6.centos.11.2.x86_64

デフォルトで読み込まれないようにする
以下を編集し、enabled=1とかいてあるところは全てenabled=0にする

# vi /etc/yum.repos.d/epel.repo
# vi /etc/yum.repos.d/remi.repo
# vi /etc/yum.repos.d/rpmforge.repo

Chefインストール

Chefを利用するにはRuby(&Rubygems)が必要なのでインストール

Ruby

yumのRubyが1.8.7と古すぎるので、rpmで入れる。

まず必要なもの入れておく(最初にやっとけばよかた・・・)

# yum -y groupinstall "Development Tools”
# yum --enablerepo=epel -y install libyaml libyaml-devel readline-devel ncurses-devel gdbm-devel tcl-devel openssl-devel db4-devel libffi-devel

ここで最近あったopensslのHeartbleed脆弱性バージョンの可能性があるのでチェック

# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013

見事に脆弱性バージョンだが、

# yum update openssl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: mirrors.neusoft.edu.cn
Setting up Update Process
No Packages marked for Update
# yum list installed|grep openssl
openssl.x86_64          1.0.1e-16.el6_5.7
openssl-devel.x86_64    1.0.1e-16.el6_5.7

アップデートはなし。

どうもこれは脆弱性の回避バージョンらしい(openssl-1.0.1e-16.el6_5.7以上)。

参考

Rubyインストールに話を戻す。

ソース取得

rootのホームディレクトリで作業する

# cd ~
# wget http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p545.tar.gz -P rpmbuild/SOURCES

SPEC取得(rpmつくるのに必要)

# wget https://raw.github.com/imeyer/ruby-1.9.3-rpm/master/ruby19.spec -P rpmbuild/SPECS

SPECファイル編集
自分がインストールするバージョンに変更

# vi rpmbuild/SPECS/ruby19.spec

%define rubyminorver    p484

↓

%define rubyminorver    p545

ビルド

# rpmbuild -bb rpmbuild/SPECS/ruby19.spec

インストール

# rpm -Uvh rpmbuild/RPMS/x86_64/ruby-1.9.3p545-1.el6.x86_64.rpm
# ruby -v
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]
# gem -v
1.8.23.2

ok

rpmbuildは重いので軽量化のため削除

# rm -rf rpmbuild

ついにChefインストール

# gem install chef --no-ri --no-rdoc

SSH設定

# su - vagrant
# mkdir .ssh
# cd .ssh
# curl 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' > authorized_keys
# cd ..
# chmod 755 .ssh/
# chmod 644 .ssh/authorized_keys

さらにrootで以下

# echo 'UseDNS no' >> /etc/ssh/sshd_config

整理

軽量化をなるだけ目指す。

# yum -y install yum-utils
# package-cleanup --dupes
# package-cleanup --cleandupes
# package-cleanup --oldkernels
# package-cleanup --problems
# yum clean all
# rm -rf /usr/share/doc
# find /var/cache -type f -exec rm -rf {} ;
# rm -rf /usr/share/locale/{af,am,ar,as,ast,az,bal,be,bg,bn,bn_IN,br,bs,byn,ca,cr,cs,csb,cy,da,de,de_AT,dz,el,en_AU,en_CA,eo,es,et,et_EE,eu,fa,fi,fo,fr,fur,ga,gez,gl,gu,haw,he,hi,hr,hu,hy,id,is,it,ja,ka,kk,km,kn,ko,kok,ku,ky,lg,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,nl,nn,no,nso,oc,or,pa,pl,ps,pt,pt_BR,qu,ro,ru,rw,si,sk,sl,so,sq,sr,sr*latin,sv,sw,ta,te,th,ti,tig,tk,tl,tr,tt,ur,urd,ve,vi,wa,wal,wo,xh,zh,zh_HK,zh_CN,zh_TW,zu}
# rm -rf /tmp/*
# rm -f /var/log/wtmp /var/log/btmp
# history -c

参考

参考

boxつくるためにシャットダウン

# shutdown -h now

自分のMacのvagrantが古すぎるので思い切って再インストール

現状

$ vagrant -v
Vagrant version 1.2.4

アンインストール

$ rm -rf /Applications/Vagrant
$ rm -rf /usr/bin/vagrant
$ rm -rf ~/.vagrant.d // これはルートとユーザ両方でやる

インストール

http://www.vagrantup.com/downloads.html

dmgを展開してインストール

$ vagrant -v
Vagrant 1.5.4

box作成

$ vagrant package --base /Users/uehi/VirtualBox VMs/Cent6.5/Cent6.5.vbox --output /Users/uehi/Desktop/cent65.box

使ってみる

$ vagrant box add cent65_box cent65.box
$ mkdir vagrant_cent65_box
$ cd vagrant_cent65_box/
$ vagrant init cent65_box
$ vagrant up
$ vagrant ssh

以下簡単なコマンド。

VMを削除する

$ vagrant destroy

vagrantに登録されたboxの一覧を見る

$ vagrant box list

boxのリストから削除

$ vagrant box remove Box名

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images