Skip to content

Instantly share code, notes, and snippets.

@yasushiyy
Last active May 24, 2016 12:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasushiyy/a638a2fd905939a0eb26 to your computer and use it in GitHub Desktop.
Save yasushiyy/a638a2fd905939a0eb26 to your computer and use it in GitHub Desktop.
Oracle LinuxのDocker Image (DB12cインストール用)を作る

Oracle LinuxのDocker Image (DB12cインストール用)を作る

概要

Oracle Linux 6.5 + oracle-rdbms-server-12cR1-preinstallのRPMが入ったDocker Imageを作成する手順。CentOSイメージをConvertする手順となっている。

完成品は以下にある。(Dockerfile)

https://github.com/yasushiyy/vagrant-docker-oracle12c/blob/master/Dockerfile

前提

CentOSをOracle Linuxに変換するスクリプトが提供されている。既存CentOS6.5のイメージを変換してみることにする。

https://linux.oracle.com/switch/centos/

ここでは、以下にてセットアップしたCoreOS環境を利用している。

https://gist.github.com/yasushiyy/9923d68e4811d458fbe0

セットアップ

CentOS6.5のDocker Imageを入手する。

core@core-01 ~ $ docker pull centos
Pulling repository centos
0c752394b855: Download complete
539c0211cd76: Download complete
511136ea3c5a: Download complete
34e94e67e63a: Download complete

ore@core-01 ~ $ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             0c752394b855        2 days ago          124.1 MB
centos              latest              0c752394b855        2 days ago          124.1 MB
centos              6.4                 539c0211cd76        14 months ago       300.6 MB

ログインして確認。ここでログアウトするとコンテナが停止してしまうので注意。

core@core-01 ~ $ docker run -i -t centos:centos6 /bin/bash

bash-4.1# cat /etc/centos-release
CentOS release 6.5 (Final)

変換してみる。最後の手順で失敗しているが、これはコンテナの仕様上やむを得ないのではないかと考える。

bash-4.1# curl -O https://linux.oracle.com/switch/centos2ol.sh

bash-4.1# sh centos2ol.sh
Checking for required packages...
Checking your distribution...
  :

================================================================================
 Package           Arch           Version                 Repository       Size
================================================================================
Installing:
 yum-utils         noarch         1.1.30-17.el6_5         updates         102 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 102 k

  :

================================================================================
 Package                    Arch    Version                   Repository   Size
================================================================================
Installing:
 grub                       x86_64  1:0.97-83.0.1.el6         ol6_latest  932 k
 grubby                     x86_64  7.0.15-5.0.2.el6          ol6_latest   43 k
 initscripts                x86_64  9.03.40-2.0.1.el6_5.1     ol6_latest  940 k
 oracle-logos               noarch  60.0.14-1.0.1.el6         ol6_latest   12 M
 oraclelinux-release-notes  x86_64  6Server-11                ol6_latest   77 k
 plymouth                   x86_64  0.8.3-27.0.1.el6          ol6_latest   89 k
Updating:
 basesystem                 noarch  10.0-4.0.1.el6            ol6_latest  4.3 k
Installing for dependencies:
 ethtool                    x86_64  2:3.5-1.4.el6_5           ol6_latest  100 k
 iproute                    x86_64  2.6.32-32.el6_5           ol6_latest  364 k
 iptables                   x86_64  1.4.7-11.0.1.el6          ol6_latest  252 k
 iputils                    x86_64  20071127-17.el6_4.2       ol6_latest  120 k
 libdrm                     x86_64  2.4.45-2.el6              ol6_latest  120 k
 libpciaccess               x86_64  0.13.1-2.el6              ol6_latest   23 k
 plymouth-core-libs         x86_64  0.8.3-27.0.1.el6          ol6_latest   88 k
 plymouth-scripts           x86_64  0.8.3-27.0.1.el6          ol6_latest   30 k
 policycoreutils            x86_64  2.0.83-19.39.0.1.el6      ol6_latest  648 k
 upstart                    x86_64  0.6.5-13.el6_5.3          ol6_latest  176 k

Transaction Summary
================================================================================
Install      16 Package(s)
Upgrade       1 Package(s)

Total download size: 16 M

  :
 
Complete!


Updating initrd...
FATAL: Could not open '/boot/System.map-3.14.5+': No such file or directory
/sbin/new-kernel-pkg: line 304: /sbin/dracut: No such file or directory
mkinitrd failed

バージョンを確認。

bash-4.1# cat /etc/oracle-release
Oracle Linux Server release 6.5

bash-4.1# cat /etc/yum.repos.d/public-yum-ol6.repo
[ol6_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
  :

幾つか問題があるので修正。

  • MAKEDEVがないとエラーになる → MAKEDEVを入れると解消
  • locale関連でエラーになる → glibc-commonを再インストールし、/etc/environmentに追記
bash-4.1# yum upgrade
  :
ERROR with rpm_check_debug vs depsolve:
MAKEDEV >= 0:3.11 is needed by udev-147-2.51.0.3.el6.x86_64
  :

bash-4.1# yum install MAKEDEV

bash-4.1# yum upgrade

bash-4.1# yum reinstall glibc-common

bash-4.1# echo LANG=en_US.utf-8 >> /etc/environment

bash-4.1# echo LC_ALL=en_US.utf-8 >> /etc/environment

vimとoracle-rdbms-server-12cR1-preinstallパッケージを入れる。

bash-4.1# yum install vim-minimal
bash-4.1# yum install oracle-rdbms-server-12cR1-preinstall

現時点でのDockerの仕様上、コンテナ内の /etc/hosts を編集できない。これはDB側ではインストールエラーやTNSエラーの原因となるので、代わりに /tmp/hosts を見るように libnss_files ライブラリのバイナリを書き換える。

https://gist.github.com/lalyos/9525120

bash-4.1# echo 127.0.0.1 localhost localhost.localdomain > /tmp/hosts
bash-4.1# sed -i.bak 's:/etc/hosts:/tmp/hosts:g' /lib64/libnss_files.so.2

DBインストール先ディレクトリと環境変数のセットアップ。

bash-4.1#  mkdir /opt/oracle
bash-4.1#  mkdir /opt/oraInventory
bash-4.1#  mkdir /opt/datafile
bash-4.1#  chown oracle:oinstall -R /opt

bash-4.1# cat << 'EOF' >> /home/oracle/.bash_profile
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export ORACLE_SID=corcl
export PATH=$PATH:$ORACLE_HOME/bin
EOF

手順としてはここまで。この手順をDockerfile化して、Docker Hubで自動BUILDすることが可能。

コンテナなのでカーネル系(バージョン、パラメータ)はホスト次第であるため、ホストOS側もOracle Linuxにして、oracle-rdbms-server-12cR1-preinstallを入れておく必要がある。

centos2ol.shの中身(参考情報)

centos2ol.sh の中身を確認した。

#!/bin/sh

# Script to switch CentOS (or other similar distribution) to the
# Oracle Linux yum repository.
#
# Author: Tim Hill <tim.hill@oracle.com>
#
# Copyright 2012 Oracle, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

2012年時点の情報である。

set -e
unset CDPATH

yum_url=http://public-yum.oracle.com
contact_email=ksplice-support_ww@oracle.com
bad_packages="centos-release-cr libreport-plugin-rhtsupport yum-rhn-plugin"
removed_packages=“"

ksplice関連の方が作ったのだろうか。

usage() {
    echo "Usage: ${0##*/} [OPTIONS]"
    echo
    echo "OPTIONS"
    echo "-h"
    echo "        Display this help and exit"
    exit 1
} >&2

have_program() {
    hash "$1" >/dev/null 2>&1
}

dep_check() {
    if ! have_program "$1"; then
        exit_message "'${1}' command not found. Please install or add it to your PATH and try again."
    fi
}

exit_message() {
    echo "$1"
    echo "For assistance, please email <${contact_email}>."
    exit 1
} >&2

restore_repos() {
    yum remove -y $new_releases
    find . -name 'repo.*' | while read repo; do
        destination=`head -n1 "$repo"`
        if [ "$destination" ]; then
            tail -n+2 "$repo" > "$destination"
        fi
    done
    rm "${reposdir}/${repo_file}"
    if [ "$removed_packages" ]; then
        yum install -y $removed_packages
    fi
    exit_message "Could not install Oracle Linux packages.
Your repositories have been restored to your previous configuration."
}

サブルーチン。restore_reposだけ何かやってるが、これはバックアップ戻し用なので、特に確認不要か。

## Start of script

while getopts "h" option; do
    case "$option" in
        h) usage ;;
        *) usage ;;
    esac
done

if [ `id -u` -ne 0 ]; then
    echo "You must run this script as root."
    if [ -x /usr/bin/sudo ]; then
        echo "Try running 'sudo ${0}'."
    fi
    exit 1
fi >&2

スクリプト関連の確認のみ。

echo "Checking for required packages..."
for pkg in rpm yum python curl; do
    dep_check "$pkg"
done

(1) rpm, yum, python, curl コマンドが実行可能であることを確認。

echo "Checking your distribution..."
if ! old_release=`rpm -q --whatprovides redhat-release`; then
    exit_message "You appear to be running an unsupported distribution."
fi

if [ `echo "$old_release" | wc -l` -ne 1 ]; then
    exit_message "Could not determine your distribution because multiple
packages are providing redhat-release:
$old_release
"
fi

case "$old_release" in
    redhat-release*) ;;
    centos-release*) ;;
    sl-release*) ;;
    oraclelinux-release*|enterprise-release*)
        exit_message "You appear to be already running Oracle Linux."
        ;;
    *) exit_message "You appear to be running an unsupported distribution." ;;
esac

RHEL/CentOS/Scientific Linuxであることを確認。

rhel_version=`rpm -q "$old_release" --qf "%{version}"`
base_packages='basesystem initscripts oracle-logos'
case "$rhel_version" in
    6*)
        repo_file=public-yum-ol6.repo
        repo_name=ol6_latest
        new_releases="oraclelinux-release redhat-release-server"
        base_packages="$base_packages oraclelinux-release-notes plymouth grub grubby"
        ;;
    5*)
        repo_file=public-yum-el5.repo
        repo_name=el5_latest
        new_releases="oraclelinux-release enterprise-release"
        base_packages="$base_packages enterprise-release-notes"
        ;;
    4*)
        exit_message "Support for this version of your distribution is still in progress."
        repo_file=public-yum-el4.repo
        repo_name=el4_latest
        new_releases=enterprise-release
        ;;
    *) exit_message "You appear to be running an unsupported distribution." ;;
esac

4.x/5.x/6.xによって、yum repository先と必須パッケージが変わる。

echo "Looking for yumdownloader..."
if ! have_program yumdownloader; then
    yum -y install yum-utils || true
    dep_check yumdownloader
fi

(2) yum-utilsがなければインストール。

echo "Finding your repository directory..."
tempdir=`mktemp -d`
cd "$tempdir”

一時ディレクトリを作成。

python > reposdir_list <<EOF
import yum

for dir in yum.YumBase().doConfigSetup(init_plugins=False).reposdir:
    print dir
EOF
while read reposdir; do
    if [ -d "$reposdir" ]; then
        cd "$reposdir"
        break;
    fi
done < reposdir_list

if [ "$PWD" = "$tempdir" ]; then
    exit_message "Could not locate your repository directory.
Tried the following:
`cat reposdir_list`
"
fi

yumレポジトリの一覧を作成。

echo "Downloading Oracle Linux yum repository file..."
if ! curl -O "${yum_url}/${repo_file}"; then
    exit_message "Could not download $repo_file from $yum_url.
Are you behind a proxy? If so, make sure the 'http_proxy' environment
variable is set with your proxy address."
fi

(3) .repoファイルのダウンロード。

trap restore_repos ERR

異常時のロールバック用。

# Bad packages
echo "Removing unsupported packages..."
for bad_package in $bad_packages; do
    if rpm -q $bad_package >/dev/null 2>&1; then
        removed_packages="$removed_packages $bad_package"
        yum remove $bad_package
    fi
done

(4) 不必要なcentos-release-cr libreport-plugin-rhtsupport yum-rhn-pluginパッケージのyum remove。

cd "$tempdir"

echo "Backing up and removing old repository files..."
rpm -ql "$old_release" | grep '\.repo$' > repo_files
while read repo; do
    if [ -f "$repo" ]; then
        cat - "$repo" > "$repo".disabled <<EOF
# This is a yum repository file that was disabled by
# ${0##*/}, a script to convert CentOS to Oracle Linux.
# Please see $yum_url for more information.

EOF
        tmpfile=`mktemp repo.XXXXX`
        echo "$repo" | cat - "$repo" > "$tmpfile"
        rm "$repo"
    fi
done < repo_files

(5) 古いレポジトリのdisable化。

echo "Downloading Oracle Linux release package..."
if ! yumdownloader $new_releases; then
    {
        echo "Could not download the following packages from $yum_url:"
        echo "$new_releases"
        echo
        echo "Are you behind a proxy? If so, make sure the 'http_proxy' environment"
        echo "variable is set with your proxy address."
    } >&2
    restore_repos
fi

echo "Switching old release package with Oracle Linux..."
rpm -i --force *.rpm
rpm -e --nodeps "$old_release"

# At this point, the switch is completed.
trap - ERR

(6) パッケージの入れ替え。

  • rpm -i --force対象
    • 5.x oraclelinux-release enterprise-release
    • 6.x oraclelinux-release redhat-release-server
  • rpm -e --nodeps centos-release
echo "Installing base packages for Oracle Linux..."
if ! yum -y install $base_packages; then
    exit_message "Could not install base packages.
Run 'yum upgrade' to manually install them."
fi

(7) 以下のパッケージインストール。

  • 5.x

    • basesystem
    • initscripts
    • oracle-logos
    • enterprise-release-notes
  • 6.x

    • basesystem
    • initscripts
    • oracle-logos
    • oraclelinux-release-notes
    • plymouth
    • grub
    • grubby
if [ -x /usr/libexec/plymouth/plymouth-update-initrd ]; then
    echo "Updating initrd..."
    /usr/libexec/plymouth/plymouth-update-initrd
fi

(8) /usr/libexec/plymouth/plymouth-update-initrd の実行

echo "Installation successful!"
echo "Run 'yum upgrade' to synchronize your installed packages"
echo "with the Oracle Linux repository.” 

(9) 最後にyum upgradeすることを推奨。

まとめ

6.0系においては、まとめると以下となる。

#!/bin/sh

yum install -y curl yum-utils
yum remove -y centos-release-cr libreport-plugin-rhtsupport yum-rhn-plugin

ls -1 /etc/yum.repos.d | while read f
do
  mv /etc/yum.repos.d/$f /etc/yum.repos.d/$f.disabled
done

curl -O http://public-yum.oracle.com/public-yum-ol6.repo
mv *.repo /etc/yum.repos.d/

yumdownloader oraclelinux-release redhat-release-server
rpm -i --force *.rpm
rpm -e --nodeps centos-release
rm *.rpm

yum install -y basesystem initscripts oracle-logos oraclelinux-release-notes plymouth grub grubby

/usr/libexec/plymouth/plymouth-update-initrd

yum upgrade -y

でもやはりDocker Hub上のcentos上だとyum upgradeでこけるので、直前にyum install MAKEDEVがあったほうがいい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment