Skip to content

Instantly share code, notes, and snippets.

@ysaotome
Last active September 30, 2016 11:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysaotome/378205689c7b6ef0a6bf to your computer and use it in GitHub Desktop.
Save ysaotome/378205689c7b6ef0a6bf to your computer and use it in GitHub Desktop.
CentOS 7.1 64bit Plain Cloud Init Script for NiftyCloud (http://cloud.nifty.com/)
#!/bin/bash
# Description:CentOS 7.1 64bit Plain Cloud Init Script for NiftyCloud (http://cloud.nifty.com/)
# 2016/09/30 @ysaotome
(
#===============================================
# Settings
#===============================================
##rootのパスワード
ROOT_PASSWORD='hoge##123'
##追加する管理ユーザ名
USER_NAME='hoge'
##管理ユーザのパスワード
USER_PASSWORD='hoge##123'
#===============================================
ARC=$(/bin/uname -m)
SALT=$(/usr/bin/uuidgen| /usr/bin/tr -d '-')
## hostname変更
HOSTNAME=$(/usr/bin/vmtoolsd --cmd 'info-get guestinfo.hostname')
/bin/hostname ${HOSTNAME}
/bin/sed -i.org -e 's/localhost.localdomain/'${HOSTNAME}'/' /etc/hostname
## ROOTパスワード設定
/usr/sbin/usermod -p $(/usr/bin/perl -e 'print crypt(${ARGV[0]}, ${ARGV[1]})' ${ROOT_PASSWORD} ${SALT}) root
## 管理ユーザ追加と設定
/usr/sbin/useradd -G 100 -p $(/usr/bin/perl -e 'print crypt(${ARGV[0]}, ${ARGV[1]})' ${USER_PASSWORD} ${SALT}) -m ${USER_NAME}
/bin/mkdir -p -m 700 /home/${USER_NAME}/.ssh
/bin/cp /root/.ssh/authorized_keys /home/${USER_NAME}/.ssh/.
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.ssh
## ssh経由でのROOTログイン禁止
/bin/sed -i.org -e 's/^PermitRootLogin .*/PermitRootLogin no/g' /etc/ssh/sshd_config
## リポジトリ追加:RPMforge
/bin/rpm --import http://ftp.riken.jp/Linux/dag/RPM-GPG-KEY.dag.txt
/bin/rpm -ivh http://ftp.riken.jp/Linux/dag/redhat/el7/en/${ARC}/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.${ARC}.rpm
/bin/sed -i.org -e "s/enabled.*=.*1/enabled=0/g" /etc/yum.repos.d/rpmforge.repo
## リポジトリ追加:EPEL
/bin/rpm --import http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL
/bin/rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/7/${ARC}/e/epel-release-7-8.noarch.rpm
/bin/sed -i.org -e "s/enabled.*=.*1/enabled=0/g" /etc/yum.repos.d/epel.repo
## リポジトリ追加:Remi
/bin/rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
/bin/rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
/bin/sed -i.org -e "s/enabled.*=.*1/enabled=0/g" /etc/yum.repos.d/remi.repo
## カーネルアップデートの制約を一時的に許可する
/bin/sed -ie 's/exclude=/#exclude=/' /etc/yum.conf
## ツールセットアップ
/usr/bin/yum --enablerepo=rpmforge,epel,remi -y install zsh.${ARC} screen.${ARC} vim-enhanced.${ARC} chrony.${ARC} git.${ARC} figlet.${ARC}
/usr/bin/yum --enablerepo=rpmforge,epel,remi -y install htop.${ARC} sysstat.${ARC} dstat.noarch java-1.8.0-openjdk.${ARC}
## zshとscreenの設定ファイル取得
/usr/bin/wget --no-check-certificate -P /home/${USER_NAME}/ 'https://gist.github.com/ysaotome/1336176/raw/8ec9767aaaaec88cbe8c2b4a4092f16d7839c77b/.screenrc'
/usr/bin/wget --no-check-certificate -P /home/${USER_NAME}/ 'https://gist.github.com/ysaotome/1336176/raw/0388bb029061783bcb2d8bbd3218b04ac4b29ba4/.zshrc'
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/.screenrc /home/${USER_NAME}/.zshrc
/bin/ln -s /home/${USER_NAME}/.screenrc /root/
/bin/ln -s /home/${USER_NAME}/.zshrc /root/
/usr/sbin/usermod -s /bin/zsh root
/usr/sbin/usermod -s /bin/zsh ${USER_NAME}
## update-motd設置
/usr/bin/wget --no-check-certificate -O /usr/local/bin/screenfetch https://raw.githubusercontent.com/KittyKatt/screenFetch/master/screenfetch-dev
/bin/chmod 755 /usr/local/bin/screenfetch
/usr/bin/wget --no-check-certificate -P /usr/local/bin/ 'https://gist.github.com/ysaotome/5997652/raw/fecdf757b348debfcdd866df00f6d567ff749623/update_motd_by_screenfetch.sh'
/bin/chmod 755 /usr/local/bin/update_motd_by_screenfetch.sh
/usr/local/bin/update_motd_by_screenfetch.sh
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd
#update-moted
*/5 * * * * root /usr/local/bin/update_motd_by_screenfetch.sh
_UPDATEMOTD_
## 時刻同期設定
/usr/bin/vmware-toolbox-cmd timesync disable
/bin/sed -i.org -e "s/^server /#server /g" /etc/chrony.conf
/bin/cat << _NTPDCONF_ >> /etc/chrony.conf
server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst
_NTPDCONF_
/usr/bin/systemctl enable chronyd
/usr/bin/systemctl restart chronyd
/usr/bin/chronyc sources
## NIFTY Cloud API Tools の設定
/usr/bin/wget -P /home/${USER_NAME}/ 'http://cloud.nifty.com/api/sdk/NIFTY_Cloud_api-tools.zip'
/usr/bin/unzip -d /home/${USER_NAME}/ /home/${USER_NAME}/NIFTY_Cloud_api-tools.zip
/bin/rm -rf /home/${USER_NAME}/NIFTY_Cloud_api-tools.zip
/bin/rm -rf /home/${USER_NAME}/NIFTY_Cloud_api-tools/bin/*.cmd
/bin/chown -R ${USER_NAME}:${USER_NAME} /home/${USER_NAME}/NIFTY_Cloud_api-tools/
/bin/chmod 755 /home/${USER_NAME}/NIFTY_Cloud_api-tools/bin/*
/bin/cat << _NCSSCONF_ >> /home/${USER_NAME}/.zshrc
## NIFTY Cloud API Settings
export NIFTY_CLOUD_HOME=/home/${USER_NAME}/NIFTY_Cloud_api-tools/
export PATH=\${PATH}:\${NIFTY_CLOUD_HOME}/bin
export JAVA_HOME=/usr/lib/jvm/jre
_NCSSCONF_
## yum update
/usr/bin/yum --enablerepo=rpmforge,epel,remi -y update
## カーネルアップデートの制約を入れる
/bin/sed -ie 's/#exclude=/exclude=/' /etc/yum.conf
## After kernel Update Reboot
/usr/bin/vmtoolsd --cmd 'info-set guestinfo.set_user_data 0'
/sbin/shutdown -r now
) 2>&1 | /usr/bin/tee /var/log/niftycloud-init.log
#!/bin/bash
/usr/bin/curl -s https://gist.githubusercontent.com/ysaotome/378205689c7b6ef0a6bf/raw/centos71_64bit_Plain_setup_script_for_niftycloud.sh | /bin/bash
@ysaotome
Copy link
Author

ysaotome commented Jul 8, 2015

サーバの新規作成時や起動時に下記画面に「起動時スクリプト.sh」の記載内容をコピー&ペーストで実行
Imgur

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