LoginSignup
5
5

More than 5 years have passed since last update.

LinuxOSにバンドルされていないパッケージを、OSインストール時に自動インストールする 〜 非構成管理編 〜

Last updated at Posted at 2015-12-19

本記事のターゲット

Linuxで、完全クローズドな環境で楽に追加パッケージをインストールしたいと思われる方をターゲットにしています。

なぜ書いたのか

構成管理ツールを使用しての自動インストールは当たり前になりつつありますが、お客様環境などによっては

  • サーバキッティング会社とソフトウェア組込み会社が分かれており、キッティング会社が初期状態でzabbix-agentをインストールしておかなければいけない。

  • システムの重要性から、インターネット接続は納品するまで絶対に行ってはいけない。

という事があります。そうとう少ないですが。

本投稿では、モデルをzabbix-agentとしています。
私がこれを書いた理由は上記の問題と少し違っていて、元々はデータセンタのIPMI監視をサーバをラッキングして直ぐに始めたいという事があって作りました。
IPMI監視にzabbix-agentは不要なんじゃない?というご意見もあると思いますが、オートディスカバリでzabbix-serverへ自動登録させるのが目的になります。

Chef, Ansible, Puppetでは駄目なのか?

前途で挙げたような環境ですと、システムに不必要なツール・言語・ポートは使用してはいけないというルールも存在します。勿論22/TCPもこれに該当する可能性はあります。

今回作成した構成

  • Ubunut server 14.04 isoイメージ
  • ISOイメージ作成用Linux(仮想環境でもOKで、上記のisoイメージからインストールしたOS)
  • インターネット接続が可能な環境

事前準備

ISOイメージを作成する為のOSを事前に用意します。
可能であれば同じisoイメージからインストールされたものが良いですが、同じディストリビューション・バージョンが合っていれば問題は無いと思います。

カスタムUbuntu作成

  • 構築用Ubuntuサーバログイン
$ ssh -l user 192.168.xxx.xxx
user@ubuntu:~$
  • isoイメージ展開・コピー
$ pwd
/home/user
$ mkdir work
$ cd work/
work$ mkdir iso original-iso custom-iso
work$ cd iso/
work/iso$ wget http://releases.ubuntu.com/14.04.3/ubuntu-14.04.3-server-amd64.iso

work/iso$ cd ..
work$ sudo mount -o loop iso/ubuntu-14.04.3-server-amd64.iso ./original-iso/
mount: block device /home/user/work/iso/ubuntu-14.04.3-server-amd64.iso is write-
protected, mounting read-only
work$ sudo cp -r ./original-iso/* ./custom-iso/
work$ sudo cp -r ./original-iso/.disk/ ./custom-iso/
work$ sudo umount ./original-iso
  • カスタム kickstart(seed) 作成
$ sudo apt-get update
$ sudo apt-get install system-config-kickstart
$ cd ~/work/custom-iso/isolinux/
$ sudo vi txt.cfg

一番上に[default zabbix-custom] と 一番下に[label zabbix-custom...]を追記する

default zabbix-custom   ## ここ追記
label install
  menu label ^Install Ubuntu Server
  kernel /install/vmlinuz
  append file=/cdrom/preseed/ubuntu-server.seed vga=788 initrd=/install/initrd.gz quiet --
label cloud
  menu label ^Multiple server install with MAAS
  kernel /install/vmlinuz
  append modules=maas-enlist-udeb vga=788 initrd=/install/initrd.gz quiet --
label check
  menu label ^Check disc for defects
  kernel /install/vmlinuz
  append MENU=/bin/cdrom-checker-menu vga=788 initrd=/install/initrd.gz quiet --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80
label zabbix-custom ##ここから追記
  menu label ^OCP Custom Install Ubuntu Server
  kernel /install/vmlinuz
  append file=/cdrom/preseed/ubuntu-ocp.seed initrd=/install/initrd.gz quiet --  ##ここまで追記
$ work/custom-iso/isolinux$ cd ..
$ work/custom-iso$ cd preseed/
$ work/custom-iso/preseed$ sudo vi ubuntu-zabbix.seed

下記、kickstart用ファイルはインストールしたい言語・キーボード等を環境によって変えてください。
参考URL: https://help.ubuntu.com/community/InstallCDCustomization/PreseedExamples

########################################################################
#### Custom Preseed Amlin Europe using Ubiquity
### By Kelly Crabb テゥ for Amlin Europe
### Tested on Ubuntu Trusty Thral 14.04 LTS
####################################################################
# General
####################################################################
# Once installation is complete, automatically power off.
d-i finish-install/reboot_in_progress note
d-i ubiquity/summary note
ubiquity ubiquity/reboot boolean true
ubiquity ubiquity/poweroff boolean false# Automatically download and install stable updates?
unattended-upgrades unattended-upgrades/enable_auto_updates boolean false
####################################################################
# Installation Sources
####################################################################
# Configure the sources.list
d-i mirror/country string JP
#d-i mirror/http/hostname string archive.ubuntu.com
#d-i mirror/http/directory string /ubuntu/
#d-i apt-setup/use_mirror boolean true
#d-i apt-setup/mirror/error select Change mirror
#d-i apt-setup/multiverse boolean true
#d-i apt-setup/restricted boolean true
#d-i apt-setup/universe boolean true
#d-i apt-setup/partner boolean true
####################################################################
# Networking
####################################################################
# Network Configuration
d-i netcfg/enable boolean true
d-i netcfg/choose_interface select eth0
#d-i netcfg/disable_dhcp boolean false
####################################################################
# Disk Partitioning / Boot loader
####################################################################
### Disk Partitioning ###
# Configure auto partitioner
ubiquity partman-auto/init_automatically_partition select Guided - use entire disk
ubiquity partman-auto/disk string /dev/sda
ubiquity partman-auto/method string regular
ubiquity partman-auto/choose_recipe select All files in one partition (recommended for new
users)
ubiquity partman/confirm_write_new_label boolean true
ubiquity partman/choose_partition select Finish partitioning and write changes to disk
ubiquity partman/confirm boolean true
####################################################################
# Localizations / Timezone
####################################################################
### Keyboard selection ###
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/variantcode string
### Locale ###
d-i debian-installer/locale string en_US
### Timezone ###
d-i time/zone select Asia/Tokyod-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean false
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
#d-i localechooser/supported-locales multiselect nl_NL, nl_BE, fr_BE
### OEM-Config
d-i oem-config/enable boolean true
d-i oem-config/remove boolean true
d-i oem-config/remove_extras boolean false
d-i oem-config/install-language-support boolean true
d-i ubiquity/only-show-installable-languages boolean true
####################################################################
# User Creation
####################################################################
# Root User
d-i passwd/root-login boolean true
# Mortal User
d-i passwd/auto-login boolean true
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password password
d-i passwd/root-password-again password password
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
####################################################################
# Some extras
####################################################################
tasksel tasksel/force-tasks string server
tasksel tasksel/first multiselect zabbix-custom
# installing languages
# Language pack selection
d-i pkgsel/language-packs multiselect en, jp
# installing services
# d-i pkgsel/include string openssh-server
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
d-i pkgsel/upgrade select none
# Policy for applying updates. May be "none" (no automatic updates),
#d-i pkgsel/update-policy select unattended-upgrades
# By default, the system's locate database will be updated after the
# installer has finished installing most packages. This may take a while, so
# if you don't want it, you can set this to "false" to turn it off.
#d-i pkgsel/updatedb boolean true
# This command is run just before the install finishes, but when there is
# still a usable /target directory. You can chroot to /target and use it
# directly, or use the apt-install and in-target commands to easily install
# packages and run commands in the target system.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh# And now we REALLY run with it!!
# deb install
d-i preseed/late_command string in-target /bin/bash /media/cdrom/pool/extras/custom_install.sh
  • インストールするdebパッケージの収集
    • ローカルのアーカイブ削除
$ sudo rm -rf /var/cache/apt/archives/
  • zabbix-agentリポジトリ登録
$ wget http://repo.zabbix.com/zabbix/2.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.2-1+trusty_all.deb
$ sudo dpkg -i zabbix-release_2.2-1+trusty_all.deb
  • インストール(debパッケージ収集)
$ sudo apt-get update
$ sudo apt-get -y install zabbix-agent
  • debパッケージ格納
$ cd work/custom-iso/pool/
work/custom-iso/pool$ sudo mkdir extras
work/custom-iso/pool$ sudo cp -rp /var/cache/apt/archives/*.deb ./extras/
work/custom-iso/pool$ sudo vi extras/custom_install.sh

zabbix-agentを自動でインストールするスクリプトを作成します。
必要に応じて、Server=XXXX/ServerActive=XXXXを組み替えると良いと思います。

#!/bin/bash
/usr/bin/dpkg -i /media/cdrom/pool/extras/*.deb
modprobe mei
modprobe dcmi
sed -i".org" \
-e 's/# EnableRemoteCommands=0/EnableRemoteCommands=1/g' \
-e 's/^Server=127.0.0.1/Server=zabbix-server/g' \
-e 's/^ServerActive=127.0.0.1/ServerActive=zabbix-server/g' \
-e 's/^Hostname=/# Hostname=/g' \
-e 's/# HostnameItem=/HostnameItem=/g' \
-e 's/# HostMetadata=/HostMetadata=Agent STARTER/g' \
/etc/zabbix/zabbix_agentd.conf
work/custom-iso/pool$ sudo chmod g+x extras/custom_install.sh
work/custom-iso/pool$ cd ../..
work$ sudo mkdir -p custom-iso/dists/stable/extras/binary-amd64
work/custom-iso/pool$ sudo su -
# cd /home/user/work/
home/user/work/custom-iso# pushd custom-iso
home/user/work/custom-iso# apt-ftparchive packages ./pool/extras/ > dists/stable/extras/binary-amd64/Packages
home/user/work/custom-iso# gzip -c ./dists/stable/extras/binary-amd64/Packages | tee ./dists/stable/extras/binary-amd64/Packages.gz > /dev/null
home/user/work/custom-iso# popd
home/user/work/custom-iso# exit
  • ISOイメージ作成
work$ sudo apt-get install mkisofs
work$ sudo mkisofs -J -l -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-
table -z -iso-level 4 -c isolinux/isolinux.cat -o ./ubuntu-zabbix-custom-amd64.iso custom-iso/
work$ ls
custom-iso iso original-iso ubuntu-zabbix-custom-amd64.iso

完成した「ubuntu-zabbix-custom-amd64.iso」を使用する事でzabbix-agentが自動インストールされるようになります。

おまけ

OCPについて

OCPとは、Open Compute Projectの略称で2011年4月にFacebook社が提唱したプロジェクトです。
データセンター仕様をオープンに公開し、全体のアイデアやスペック等の知的財産を共有しています。
これにより、サーバ・ストレージ・データセンター・ラック・ネットワークスイッチ等の設計が公開される事で高効率なデータセンターが出来上がり、省エネ・コストダウンが図れるとされています。
この記事を書いたきっかけがOCPによるものです。
興味ありましたら下記スライドを参照ください。

cobblerでも出来ます

いちいちisoを作成するのが面倒という思いもあるでしょう。
そういった場合はPXEブートインストールも手段の一つです。
cobblerはPXEインストールに必要な情報を一括で管理する事が可能なので、是非チャレンジしてみて下さい。
http://cobbler.github.io/

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5