Signed-off-by: Luan Shengde shdluan@163.com --- tests/ceph-init | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 tests/ceph-init
diff --git a/tests/ceph-init b/tests/ceph-init new file mode 100755 index 000000000..59398d1bd --- /dev/null +++ b/tests/ceph-init @@ -0,0 +1,155 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# - cephuser_password +# - cephuser + +: "${cephuser:=cephuser}" +: "${cephuser_password:=cephuser_password}" + +### ===== on each node ===== +# stop firewalld and disable selinx +systemctl stop firewalld +systemctl disable firewalld + +sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux + +until [[ -n $node_roles ]]; do + sleep 1 +done + +hosts=(node1 node2 node3) + +[[ $node_roles == node1 ]] && { + hostnamectl set-hostname node1 +} + +[[ $node_roles == node2 ]] && { + hostnamectl set-hostname node2 +} + +[[ $node_roles == node3 ]] && { + hostnamectl set-hostname node3 +} + +yum update && { + yum install ntp wget gcc make ceph lvm2 python3 -y +} + +# add user and set sudo permissions +useradd -d /home/$cephuser -m $cephuser && { + echo $cephuser:$cephuser_password | chpasswd +} + +cat >> /etc/sudoers <<-EOF +$cephuser ALL=(ALL) NOPASSWD:ALL +EOF + +# check and install pip +[[ $(command -v pip) ]] || { + until wget https://bootstrap.pypa.io/get-pip.py; do + sleep 2 + done + python get-pip.py +} + +pip install prettytable + +### ===== on ceph-deploy node ===== +# get node IPs is first +[[ $node_roles == node1 ]] || exit 0 + +until [[ -n $node1 ]]; do + sleep 1 +done + +until [[ -n $node2 ]]; do + sleep 1 +done + +until [[ -n $node3 ]]; do + sleep 1 +done + +# config hosts and set default ssh users +cat >> /etc/hosts <<-EOF +$node1 node1 node1 +$node2 node2 node2 +$node3 node3 node3 +EOF + +for host in "${hosts[@]}"; do + cat >> "$HOME/.ssh/config" <<-EOF + Host $host + Hostname $host + User $cephuser + EOF +done + +chmod 0600 "$HOME/.ssh/config" + +network=$(ip route | grep default | awk '{print $3}' | awk -F'.' '{print $1"."$2}') +net_mask=$(ip route | grep "^$network" | awk '{print $1}') + +# do the deploy until all the servers are up +# for host in "${host[@]}"; do +# until ping -c 1 -W 1 172.168.131.100> /dev/null; do +# sleep 2 +# done +# done + +# set server trust +[[ $(command -v sshpass) ]] || { + until wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz; do + sleep 2 + done +} + +tar xzvf sshpass.tar.gz && { + cd sshpass-1.08 || exit 1 + ./configure + make + make install +} + +rm -rf "$HOME/.ssh/id_rsa" "$HOME/.ssh/id_rsa.pub" && { + ssh-keygen -f "$HOME/.ssh/id_rsa" -t rsa -N '' +} + +sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config +for host in "${hosts[@]}"; do +{ + sshpass -p $cephuser_password ssh-copy-id "$cephuser"@"$host" &> /dev/null +}& +done +wait + +# install +pip install ceph-deploy + +pip_dir=$(pip show ceph-deploy | awk '/^Location/ {print $NF}') +ceph_init_file="${pip_dir}/ceph_deploy/hosts/__init__.py" +[[ -f $ceph_init_file ]]&& { + sed -i "/distributions = {/a 'openeuler': fedora," "$ceph_init_file" +} + +# deploy ceph cluster +disk_name=$(sed -e '1d' -e '/^$/d' /proc/partitions | grep " .da" | awk '{print $NF}') +disk_device="/dev/${disk_name}" + +[[ -d "$HOME/ceph-deploy" ]] || { + mkdir -p "$HOME/ceph-deploy" +} + +cd "$HOME/ceph-deploy" && { + ceph-deploy new "${hosts[@]}" + echo "public_network = ${net_mask}" >> "$HOME/ceph-deploy/ceph.conf" + ceph-deploy mon create-initial + ceph-deploy --overwrite-conf admin "${hosts[@]}" + ceph-deploy mgr create "${hosts[@]}" + for host in "${hosts[@]}"; do + ceph-deploy osd create --data "$disk_device" "$host" + done + wait + ceph osd pool create ceph-osd-pool 128 +}
On Wed, Apr 14, 2021 at 06:26:35PM +0800, Luan Shengde wrote:
Signed-off-by: Luan Shengde shdluan@163.com
tests/ceph-init | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 tests/ceph-init
diff --git a/tests/ceph-init b/tests/ceph-init new file mode 100755 index 000000000..59398d1bd --- /dev/null +++ b/tests/ceph-init @@ -0,0 +1,155 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# - cephuser_password +# - cephuser
+: "${cephuser:=cephuser}" +: "${cephuser_password:=cephuser_password}"
+### ===== on each node ===== +# stop firewalld and disable selinx +systemctl stop firewalld +systemctl disable firewalld
+sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
+until [[ -n $node_roles ]]; do
sleep 1
+done
+hosts=(node1 node2 node3)
+[[ $node_roles == node1 ]] && {
hostnamectl set-hostname node1
+}
+[[ $node_roles == node2 ]] && {
hostnamectl set-hostname node2
+}
+[[ $node_roles == node3 ]] && {
hostnamectl set-hostname node3
+}
perhaps you should be like this:
for i in "${hosts[@]}" do [[ $node_roles == ${i} ]] && { hostnamectl set-hostname "${i}" }
done
+yum update && {
yum install ntp wget gcc make ceph lvm2 python3 -y
+}
+# add user and set sudo permissions +useradd -d /home/$cephuser -m $cephuser && {
echo $cephuser:$cephuser_password | chpasswd
+}
+cat >> /etc/sudoers <<-EOF +$cephuser ALL=(ALL) NOPASSWD:ALL +EOF
+# check and install pip +[[ $(command -v pip) ]] || {
until wget https://bootstrap.pypa.io/get-pip.py; do
sleep 2
done
python get-pip.py
+}
+pip install prettytable
+### ===== on ceph-deploy node ===== +# get node IPs is first +[[ $node_roles == node1 ]] || exit 0
+until [[ -n $node1 ]]; do
sleep 1
+done
+until [[ -n $node2 ]]; do
sleep 1
+done
+until [[ -n $node3 ]]; do
sleep 1
+done
+# config hosts and set default ssh users +cat >> /etc/hosts <<-EOF +$node1 node1 node1 +$node2 node2 node2 +$node3 node3 node3 +EOF
+for host in "${hosts[@]}"; do
cat >> "$HOME/.ssh/config" <<-EOF
Host $host
Hostname $host
User $cephuser
EOF
+done
+chmod 0600 "$HOME/.ssh/config"
+network=$(ip route | grep default | awk '{print $3}' | awk -F'.' '{print $1"."$2}') +net_mask=$(ip route | grep "^$network" | awk '{print $1}')
+# do the deploy until all the servers are up +# for host in "${host[@]}"; do +# until ping -c 1 -W 1 172.168.131.100> /dev/null; do +# sleep 2 +# done +# done
+# set server trust +[[ $(command -v sshpass) ]] || {
until wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz; do
sleep 2
done
+}
+tar xzvf sshpass.tar.gz && {
cd sshpass-1.08 || exit 1
./configure
make
make install
+}
+rm -rf "$HOME/.ssh/id_rsa" "$HOME/.ssh/id_rsa.pub" && {
ssh-keygen -f "$HOME/.ssh/id_rsa" -t rsa -N ''
+}
+sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config +for host in "${hosts[@]}"; do +{
sshpass -p $cephuser_password ssh-copy-id "$cephuser"@"$host" &> /dev/null
+}& +done +wait
+# install +pip install ceph-deploy
+pip_dir=$(pip show ceph-deploy | awk '/^Location/ {print $NF}') +ceph_init_file="${pip_dir}/ceph_deploy/hosts/__init__.py" +[[ -f $ceph_init_file ]]&& {
sed -i "/distributions = {/a 'openeuler': fedora," "$ceph_init_file"
+}
+# deploy ceph cluster +disk_name=$(sed -e '1d' -e '/^$/d' /proc/partitions | grep " .da" | awk '{print $NF}') +disk_device="/dev/${disk_name}"
+[[ -d "$HOME/ceph-deploy" ]] || {
mkdir -p "$HOME/ceph-deploy"
+}
+cd "$HOME/ceph-deploy" && {
ceph-deploy new "${hosts[@]}"
echo "public_network = ${net_mask}" >> "$HOME/ceph-deploy/ceph.conf"
ceph-deploy mon create-initial
ceph-deploy --overwrite-conf admin "${hosts[@]}"
ceph-deploy mgr create "${hosts[@]}"
for host in "${hosts[@]}"; do
ceph-deploy osd create --data "$disk_device" "$host"
done
wait
ceph osd pool create ceph-osd-pool 128
+}
maybe you should encapsulate above modules as function, call these functions, it is clear.
Thanks, Liushaofei
-- 2.23.0
On Wed, Apr 14, 2021 at 06:44:52PM +0800, Liu Shaofei wrote:
On Wed, Apr 14, 2021 at 06:26:35PM +0800, Luan Shengde wrote:
Signed-off-by: Luan Shengde shdluan@163.com
tests/ceph-init | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 tests/ceph-init
diff --git a/tests/ceph-init b/tests/ceph-init new file mode 100755 index 000000000..59398d1bd --- /dev/null +++ b/tests/ceph-init @@ -0,0 +1,155 @@ +#!/bin/bash +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# - cephuser_password +# - cephuser
+: "${cephuser:=cephuser}" +: "${cephuser_password:=cephuser_password}"
+### ===== on each node ===== +# stop firewalld and disable selinx +systemctl stop firewalld +systemctl disable firewalld
+sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
+until [[ -n $node_roles ]]; do
sleep 1
+done
+hosts=(node1 node2 node3)
+[[ $node_roles == node1 ]] && {
hostnamectl set-hostname node1
+}
+[[ $node_roles == node2 ]] && {
hostnamectl set-hostname node2
+}
+[[ $node_roles == node3 ]] && {
hostnamectl set-hostname node3
+}
perhaps you should be like this:
for i in "${hosts[@]}" do [[ $node_roles == ${i} ]] && { hostnamectl set-hostname "${i}" }
ok, I will optimize it.
Thanks, Luan Shengde
done
+yum update && {
yum install ntp wget gcc make ceph lvm2 python3 -y
+}
+# add user and set sudo permissions +useradd -d /home/$cephuser -m $cephuser && {
echo $cephuser:$cephuser_password | chpasswd
+}
+cat >> /etc/sudoers <<-EOF +$cephuser ALL=(ALL) NOPASSWD:ALL +EOF
+# check and install pip +[[ $(command -v pip) ]] || {
until wget https://bootstrap.pypa.io/get-pip.py; do
sleep 2
done
python get-pip.py
+}
+pip install prettytable
+### ===== on ceph-deploy node ===== +# get node IPs is first +[[ $node_roles == node1 ]] || exit 0
+until [[ -n $node1 ]]; do
sleep 1
+done
+until [[ -n $node2 ]]; do
sleep 1
+done
+until [[ -n $node3 ]]; do
sleep 1
+done
+# config hosts and set default ssh users +cat >> /etc/hosts <<-EOF +$node1 node1 node1 +$node2 node2 node2 +$node3 node3 node3 +EOF
+for host in "${hosts[@]}"; do
cat >> "$HOME/.ssh/config" <<-EOF
Host $host
Hostname $host
User $cephuser
EOF
+done
+chmod 0600 "$HOME/.ssh/config"
+network=$(ip route | grep default | awk '{print $3}' | awk -F'.' '{print $1"."$2}') +net_mask=$(ip route | grep "^$network" | awk '{print $1}')
+# do the deploy until all the servers are up +# for host in "${host[@]}"; do +# until ping -c 1 -W 1 172.168.131.100> /dev/null; do +# sleep 2 +# done +# done
+# set server trust +[[ $(command -v sshpass) ]] || {
until wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz; do
sleep 2
done
+}
+tar xzvf sshpass.tar.gz && {
cd sshpass-1.08 || exit 1
./configure
make
make install
+}
+rm -rf "$HOME/.ssh/id_rsa" "$HOME/.ssh/id_rsa.pub" && {
ssh-keygen -f "$HOME/.ssh/id_rsa" -t rsa -N ''
+}
+sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config +for host in "${hosts[@]}"; do +{
sshpass -p $cephuser_password ssh-copy-id "$cephuser"@"$host" &> /dev/null
+}& +done +wait
+# install +pip install ceph-deploy
+pip_dir=$(pip show ceph-deploy | awk '/^Location/ {print $NF}') +ceph_init_file="${pip_dir}/ceph_deploy/hosts/__init__.py" +[[ -f $ceph_init_file ]]&& {
sed -i "/distributions = {/a 'openeuler': fedora," "$ceph_init_file"
+}
+# deploy ceph cluster +disk_name=$(sed -e '1d' -e '/^$/d' /proc/partitions | grep " .da" | awk '{print $NF}') +disk_device="/dev/${disk_name}"
+[[ -d "$HOME/ceph-deploy" ]] || {
mkdir -p "$HOME/ceph-deploy"
+}
+cd "$HOME/ceph-deploy" && {
ceph-deploy new "${hosts[@]}"
echo "public_network = ${net_mask}" >> "$HOME/ceph-deploy/ceph.conf"
ceph-deploy mon create-initial
ceph-deploy --overwrite-conf admin "${hosts[@]}"
ceph-deploy mgr create "${hosts[@]}"
for host in "${hosts[@]}"; do
ceph-deploy osd create --data "$disk_device" "$host"
done
wait
ceph osd pool create ceph-osd-pool 128
+}
maybe you should encapsulate above modules as function, call these functions, it is clear.
Thanks, Liushaofei
-- 2.23.0