Last active
May 13, 2016 01:29
-
-
Save ysaotome/5790851 to your computer and use it in GitHub Desktop.
CentOS 6.6 64bit Plain setup script for NiftyCloud (http://cloud.nifty.com/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Description:CentOS 6.6 64bit Plain setup script for NiftyCloud (http://cloud.nifty.com/) | |
# File:centos66_64bit_Plain_setup_script_for_niftycloud.sh | |
# 2016/05/01 @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/sbin/vmtoolsd --cmd 'info-get guestinfo.hostname') | |
/bin/hostname ${HOSTNAME} | |
/bin/sed -i.org -e 's/HOSTNAME=.*/HOSTNAME='${HOSTNAME}'/' /etc/sysconfig/network | |
## 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/el6/en/${ARC}/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.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/6/${ARC}/epel-release-6-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-6.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 | |
## ツールセットアップ zsh,screen,ntp,sysstat,net-snmpをセットアップする | |
/usr/bin/yum --enablerepo=rpmforge,epel,remi -y install zsh.${ARC} screen.${ARC} ntp.${ARC} sysstat.${ARC} dstat.noarch net-snmp.${ARC} java-1.6.0-openjdk.${ARC} git.${ARC} figlet.${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 -P /usr/local/bin/ 'https://gist.github.com/ysaotome/5997652/raw/05a680fc5a1df75469d5c26f505f217f727e0af6/update_motd_for_centos.sh' | |
/bin/chmod 755 /usr/local/bin/update_motd_for_centos.sh | |
/usr/local/bin/update_motd_for_centos.sh | |
/bin/cat << _UPDATEMOTD_ > /etc/cron.d/update-motd | |
#update-moted | |
*/5 * * * * root /usr/local/bin/update_motd_for_centos.sh | |
_UPDATEMOTD_ | |
## ntpdの設定ファイル | |
/usr/bin/vmware-toolbox-cmd timesync disable | |
/bin/sed -i.org -e "s/^server /#server /g" /etc/ntp.conf | |
/bin/cat << _NTPDCONF_ >> /etc/ntp.conf | |
server -4 ntp.nict.jp iburst | |
server -4 ntp.nict.jp iburst | |
server -4 ntp.nict.jp iburst | |
server -4 ntp1.jst.mfeed.ad.jp | |
server -4 ntp2.jst.mfeed.ad.jp | |
server -4 ntp3.jst.mfeed.ad.jp | |
_NTPDCONF_ | |
/sbin/chkconfig ntpd on | |
/etc/init.d/ntpd start | |
## 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 | |
## yum update後のkernelにドライバ適用 | |
/bin/cat << _RCLOCAL_VM_TOOLS_UPGRADAR_ > /etc/rc.d/rc3.d/S90vmware-tools-upgrader | |
#!/bin/sh | |
/bin/rm -rf /etc/rc.d/rc3.d/S90vmware-tools-upgrader | |
/usr/sbin/vmware-tools-upgrader -p "-d" | |
/sbin/shutdown -r now | |
_RCLOCAL_VM_TOOLS_UPGRADAR_ | |
/bin/chmod 755 /etc/rc.d/rc3.d/S90vmware-tools-upgrader | |
## After kernel Update Reboot | |
/sbin/shutdown -r now | |
) 2>&1 | /usr/bin/tee /var/log/centos66_64bit_Plain_setup_script_for_niftycloud-installer.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
/bin/cp -p /etc/rc.d/rc.local{,.org} ; /bin/echo -e '#!/bin/bash\n/bin/mv /etc/rc.d/rc.local.org /etc/rc.d/rc.local ; /usr/bin/curl -s https://gist.github.com/ysaotome/5790851/raw/centos66_64bit_Plain_setup_script_for_niftycloud.sh | /bin/bash' > /etc/rc.d/rc.local |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
サーバの新規作成時や起動時に下記画面に「起動時スクリプト.sh」の記載内容をコピー&ペーストで実行
