openstack cloud init set password
设置代理和password
#!/bin/bash # passwd centos << EOF passwd ubuntu << EOF 123456 123456 EOF if [ $? -ne 0 ]; then passwd centos << EOF 123456 123456 EOF fi passwd root << EOF 123456 123456 EOF sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config service sshd restart cd /home/ubuntu if [ $? -ne 0 ]; then cd /home/centos fi wget otcloud-gateway.bj.intel.com/script.tar.gz if [ $? -ne 0 ]; then curl -O otcloud-gateway.bj.intel.com/script.tar.gz fi tar xzvf script.tar.gz cd script # sed -i '/enable_service n-novnc/a enable_plugin cyborg git://git.openstack.org/openstack/cyborg\nOPAE_INSTALL_ENABLE=false' gen-localconf.sh ./vm-setup.sh
bug fix:
cd ~/script sed -i -e 's/^\(.*\)CTRL_IP=.*ip route get.*/\1CTRL_IP=$(ip route get 1 | awk \x27{match($0, \/.+src\\s([.0-9]+)\/, a);print a[1];exit}\x27)/' environment.inc sed -i -e 's/^\(.*\)MY_IP=.*ip route get.*/\MY_IP=$(ip route get 1 | awk \x27{match($0, \/.+src\\s([.0-9]+)\/, a);print a[1];exit}\x27)/' gen-localconf.sh sed -i -e 's/^\(.*\)MY_IP=.*ip route get.*/\MY_IP=$(ip route get 1 | awk \x27{match($0, \/.+src\\s([.0-9]+)\/, a);print a[1];exit}\x27)/' lm-prep.sh
sed -i -e '/^\(.*\)CTRL_IP=.*ip route get.*/a\date ; read -t 10 -p "Input service IP then hit ENTER or wait ten seconds: " SERVICE_HOST; echo $SERVICE_HOST; date\nCTRL_IP=${SERVICE_HOST:-$CTRL_IP}\n' environment.inc
安装docker
wget -O- https://get.docker.com/ |bash # sudo usermod -aG docker $USER sudo usermod -aG docker ubuntu
整个安装k8s脚本和devstack脚本(init_cloud中)
go install https://github.com/udhos/update-golang
#!/bin/bash cd /home/ubuntu wget otcloud-gateway.bj.intel.com/script.tar.gz if [ $? -ne 0 ]; then curl -O otcloud-gateway.bj.intel.com/script.tar.gz fi tar xzvf script.tar.gz cd script source environment.inc
sed -i '/enable_service n-novnc/a enable_plugin cyborg git://git.openstack.org/openstack/cyborg\nOPAE_INSTALL_ENABLE=false' gen-localconf.sh ./vm-setup.sh ./prep.sh UNAME=/home/ubuntu UHOME=/home/ubuntu USERN=ubuntu # passwd centos << EOF passwd ubuntu << EOF 123456 123456 EOF if [ $? -ne 0 ]; then UHOME=/home/centos UNAME=/home/centos USERN=centos passwd centos << EOF 123456 123456 EOF fi passwd root << EOF 123456 123456 EOF # Clone the latest devstack cd $UNAME git clone /opt/git/openstack-dev/devstack.git cd $UNAME/devstack # generate local.conf $TOPDIR/gen-localconf.sh mkdir files cp /opt/git/images/get-pip.py files/ # ./stack.sh # please run stack manually sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config service ssh restart # install docker wget -O- https://get.docker.com/ |bash sudo usermod -aG docker $USERN # $USER # ~/.profile # install go GOVER=1.10 GOLATEST=1.10.2 sudo add-apt-repository ppa:gophers/archive sudo apt update # UHOME=/home/ubuntu # UHOME=~ ENV_SCRIPT=.profile GO_ROOT=/usr/lib/go-$GOVER/bin GO_ROOT=/usr/lib/go-latest/bin GO=go # echo "PATH=\$PATH:$GO_ROOT:/usr/local/go/bin" >> $UHOME/$ENV_SCRIPT echo "PATH=\$PATH:$UHOME/go/bin" >> $UHOME/$ENV_SCRIPT # sudo apt-get -y install golang-$GOVER-go # sudo ln -s /usr/lib/go-$GOVER /usr/lib/go-latest # wget https://dl.google.com/go/go$GOLATEST.linux-amd64.tar.gz OS=linux ARCH=amd64 # sudo tar -C /usr/local -xzf go$GOLATEST.$OS-$ARCH.tar.gz echo "PATH=\$PATH:/usr/local/go/bin" >> $UHOME/$ENV_SCRIPT wget -O- https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh | sudo bash # install cfssl GOPATH=$UHOME/go $GO_ROOT/go get -u github.com/cloudflare/cfssl/cmd/... # root user # install k8s code git clone https://github.com/kubernetes/kubernetes.git $UHOME/kubernetes cd $UHOME/kubernetes # install etcd hack/install-etcd.sh # Installs in ./third_party/etcd echo "export PATH=\"\$PATH:$(pwd)/third_party/etcd\"" >> $UHOME/$ENV_SCRIPT # Add to PATH chown -R $USERN:$USERN /home/$USERN cat > /usr/bin/kubectl <<<'#!/bin/bash /home/$USERN/kubernetes/cluster/kubectl.sh $@' chmod a+x /usr/bin/kubectl
对于K8s登陆机器, 手动执行以下指令,已经放在了cloud init中,可以忽略。
# into VM rum manually UHOME=/home/ubuntu # UHOME=~ ENV_SCRIPT=.profile
GOLATEST=1.10.2
GOVER=1.10
GO_ROOT=/usr/lib/go-$GOVER/bin
GO_ROOT=/usr/lib/go-latest/bin
GO=go
# echo "PATH=\$PATH:$GO_ROOT" >> $UHOME/$ENV_SCRIPT
# sudo apt-get -y install golang-$GOVER-go
# sudo ln -s /usr/lib/go-$GOVER /usr/lib/go-latest
# wget https://dl.google.com/go/go$GOLATEST.linux-amd64.tar.gz
OS=linux
ARCH=amd64
# sudo tar -C /usr/local -xzf go$GOLATEST.$OS-$ARCH.tar.gz
wget -O- https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh | sudo bash
echo "PATH=\$PATH:/usr/local/go/bin" >> $UHOME/$ENV_SCRIPT
source $UHOME/$ENV_SCRIPT
cat >> $UHOME/$ENV_SCRIPT <<<' GOROOT=`go env |grep "GOROOT" |cut -d "=" -f2` GOROOT=${GOROOT#\"} GOROOT=${GOROOT%\"} GOPATH=`go env |grep GOPATH |cut -d "=" -f 2` GOPATH=${GOPATH%\"} GOPATH=${GOPATH#\"} export PATH="$PATH:$GOPATH/bin"' source $UHOME/$ENV_SCRIPT # install cfssl # GOPATH=$UHOME/go $GO_ROOT/go get -u github.com/cloudflare/cfssl/cmd/... # root user
go get -u github.com/cloudflare/cfssl/cmd/... # ubuntu user
# install k8s code
git clone https://github.com/kubernetes/kubernetes.git $UHOME/kubernetes
cd $UHOME/kubernetes
# install etcd
hack/install-etcd.sh # Installs in ./third_party/etcd
echo "export PATH=\"\$PATH:$(pwd)/third_party/etcd\"" >> $UHOME/$ENV_SCRIPT # Add to PATH
对于devstack,登陆机器, 手动执行以下指令,不知道为啥不能放在cloud init中, 是source environment.inc 执行太晚了, 这个也可以忽略了。
UHOME=~ cd /home/ubuntu/script source environment.inc sudo mount -t nfs $gitcache:/data/git /opt/git # Clone the latest devstack cd $UHOME git clone /opt/git/openstack-dev/devstack.git cd $UHOME/devstack # generate local.conf
sed -i '/enable_service n-novnc/a enable_plugin cyborg git://git.openstack.org/openstack/cyborg\nOPAE_INSTALL_ENABLE=false' $TOPDIR/gen-localconf.sh $TOPDIR/gen-localconf.sh sudo cp /opt/git/images/get-pip.py files/
登陆host机器 执行
wget http://otcloud-gateway.bj.intel.com/id_rsa.team -O ~/.ssh/id_rsa.team chmod 600 ~/.ssh/id_rsa.team
进入 kubernetes 运行一下命令。
cd ~/kubernetes
hack/local-up-cluster.sh
进入devstack 运行一下命令
cd ~/devstack
source ~/script/environment.inc
TOPDIR=/home/ubuntu/script
# generate local.conf
$TOPDIR/gen-localconf.sh
./stack.sh
$ cat ~/.ssh/config
cat >> ~/.ssh/config <<<'
Host review.openstack.org HostName review.openstack.org User shaohefeng Port 29418 IdentityFile ~/.ssh/id_rsa.team Host public HostName 10.238.153.33 User team IdentityFile ~/.ssh/id_rsa.team Host k8s-dev HostName 10.0.0.28 User ubuntu IdentityFile ~/.ssh/id_rsa.team ProxyCommand ssh public nc %h %p'
set DNS
sudo su cat > /etc/docker/daemon.json <<<'{ "dns": ["10.239.27.228"] }' exit sudo systemctl restart docker