100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 设置开机ceph自动map rbd块设备

设置开机ceph自动map rbd块设备

时间:2021-06-02 14:23:41

相关推荐

设置开机ceph自动map rbd块设备

独角兽企业重金招聘Python工程师标准>>>

1. 先下载init-rbdmap到/etc/init.d目录:

wget /ceph/ceph/a4ddf704868832e119d7949e96fe35ab1920f06a/src/init-rbdmap -O /etc/init.d/rbdmap

下载的原始文件有些错误,打开此文件:

vim /etc/init.d/rbdmap#!/bin/bash#chkconfig: 2345 80 60#description: start/stop rbdmap### BEGIN INIT INFO# Provides:rbdmap# Required-Start: $network# Required-Stop:$network# Default-Start:2 3 4 5# Default-Stop:0 1 6# Short-Description: Ceph RBD Mapping# Description: Ceph RBD Mapping### END INIT INFODESC="RBD Mapping"RBDMAPFILE="/etc/ceph/rbdmap". /lib/lsb/init-functions#. /etc/redhat-lsb/lsb_log_message,加入此行后不正长do_map() {if [ ! -f "$RBDMAPFILE" ]; thenlog_warning_msg "$DESC : No $RBDMAPFILE found."exit 0filog_daemon_msg "Starting $DESC"# Read /etc/rbdtab to create non-existant mappingnewrbd=RET=0while read DEV PARAMS; docase "$DEV" in""|\#*)continue;;*/*);;*)DEV=rbd/$DEV;;esacOIFS=$IFSIFS=','for PARAM in ${PARAMS[@]}; doCMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"doneIFS=$OIFSif [ ! -b /dev/rbd/$DEV ]; thenlog_progress_msg $DEVrbd map $DEV $CMDPARAMS[ $? -ne "0" ] && RET=1newrbd="yes"fidone < $RBDMAPFILElog_end_msg $RET# Mount new rbdif [ "$newrbd" ]; thenlog_action_begin_msg "Mounting all filesystems"mount -alog_action_end_msg $?fi}do_unmap() {log_daemon_msg "Stopping $DESC"RET=0# Unmap all rbd devicefor DEV in /dev/rbd[0-9]*; dolog_progress_msg $DEV# Umount before unmapMNTDEP=$(findmnt --mtab --source $DEV --output TARGET | sed 1,1d | sort -r)for MNT in $MNTDEP; doumount $MNT || sleep 1 && umount -l $DEVdonerbd unmap $DEV[ $? -ne "0" ] && RET=1donelog_end_msg $RET}case "$1" instart)do_map;;stop)do_unmap;;reload)do_map;;status)rbd showmapped;;*)log_success_msg "Usage: rbdmap {start|stop|reload|status}"exit 1;;esacexit 0

运行会提示如下错误:

./rbdmap: line 34: log_progress_msg: command not found./rbdmap: line 44: log_action_begin_msg: command not found./rbdmap: line 46: log_action_end_msg: command not found

解决方法是将log_*换成echo,或者直接注释掉。

然后chkconfig --add rbdmap; chkconfig rbdmap on就可以了。

有时候rbdmap服务不会自动启动,可以将rbdmap脚本中的函数拆分出来加入到/etc/init.d/ceph中:将其中的do_map加入到start)中,将do_unmap加入到stop中,将rbd showmapped加入到status)中。这样rbdmap就随ceph一起启动和停止了。

有兴趣的可以研究一下/etc/init.d/ceph脚本:

#!/bin/sh# Start/stop ceph daemons# chkconfig: 2345 60 80### BEGIN INIT INFO# Provides:ceph# Default-Start:2 3 4 5# Default-Stop:0 1 6# Required-Start: $remote_fs $named $network $time# Required-Stop:$remote_fs $named $network $time# Short-Description: Start Ceph distributed file system daemons at boot time# Description: Enable Ceph distributed file system services.### END INIT INFODESC="RBD Mapping"RBDMAPFILE="/etc/ceph/rbdmap". /lib/lsb/init-functionsdo_map() {if [ ! -f "$RBDMAPFILE" ]; thenecho "$DESC : No $RBDMAPFILE found."exit 0fiecho "Starting $DESC"# Read /etc/rbdtab to create non-existant mappingnewrbd=RET=0while read DEV PARAMS; docase "$DEV" in""|\#*)continue;;*/*);;*)DEV=rbd/$DEV;;esacOIFS=$IFSIFS=','for PARAM in ${PARAMS[@]}; doCMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"doneIFS=$OIFSif [ ! -b /dev/rbd/$DEV ]; then#log_progress_msg $DEVrbd map $DEV $CMDPARAMS[ $? -ne "0" ] && RET=1newrbd="yes"fidone < $RBDMAPFILE#echo $RET# Mount new rbdif [ "$newrbd" ]; thenecho "Mounting all filesystems"mount -a#log_action_end_msg $?fi}do_unmap() {echo "Stopping $DESC"RET=0# Unmap all rbd devicefor DEV in /dev/rbd[0-9]*; do#log_progress_msg $DEV# Umount before unmapMNTDEP=$(findmnt --mtab --source $DEV --output TARGET | sed 1,1d | sort -r)for MNT in $MNTDEP; doumount $MNT || sleep 1 && umount -l $DEVdonerbd unmap $DEV[ $? -ne "0" ] && RET=1done#log_end_msg $RET}# if we start up as ./mkcephfs, assume everything else is in the# current directory too.if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; thenBINDIR=.SBINDIR=.LIBDIR=.ETCDIR=.elseBINDIR=/usr/binSBINDIR=/usr/sbinLIBDIR=/usr/lib64/cephETCDIR=/etc/cephfiusage_exit() {echo "usage: $0 [options] {start|stop|restart|condrestart} [mon|osd|mds]..."printf "\t-c ceph.conf\n"printf "\t--valgrind\trun via valgrind\n"printf "\t--hostname [hostname]\toverride hostname lookup\n"exit}# behave if we are not completely installed (e.g., Debian "removed,# config remains" state)test -f $LIBDIR/ceph_common.sh || exit 0. $LIBDIR/ceph_common.shEXIT_STATUS=0# detect systemdSYSTEMD=0grep -qs systemd /proc/1/comm && SYSTEMD=1signal_daemon() {name=$1daemon=$2pidfile=$3signal=$4action=$5[ -z "$action" ] && action="Stopping"echo -n "$action Ceph $name on $host..."do_cmd "if [ -e $pidfile ]; thenpid=`cat $pidfile`if [ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline ; thencmd=\"kill $signal \$pid\"echo -n \$cmd...\$cmdfifi"echo done}daemon_is_running() {name=$1daemon=$2daemon_id=$3pidfile=$4do_cmd "[ -e $pidfile ] || exit 1 # no pid, presumably not runningpid=\`cat $pidfile\`[ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline && grep -qwe -i.$daemon_id /proc/\$pid/cmdline && exit 0 # runningexit 1 # pid is something else" "" "okfail"}stop_daemon() {name=$1daemon=$2pidfile=$3signal=$4action=$5[ -z "$action" ] && action="Stopping"echo -n "$action Ceph $name on $host..."do_cmd "while [ 1 ]; do[ -e $pidfile ] || breakpid=\`cat $pidfile\`while [ -e /proc/\$pid ] && grep -q $daemon /proc/\$pid/cmdline ; docmd=\"kill $signal \$pid\"echo -n \$cmd...\$cmdsleep 1continuedonebreakdone"echo done}## command line optionsoptions=version=0dovalgrind=docrun=allhosts=0debug=0monaddr=dofsmount=1dofsumount=0verbose=0while echo $1 | grep -q '^-'; do# FIXME: why not '^-'?case $1 in-v | --verbose)verbose=1;;--valgrind)dovalgrind=1;;--novalgrind)dovalgrind=0;;--allhosts | -a)allhosts=1;;;--restart)docrun=1;;--norestart)docrun=0;;-m )[ -z "$2" ] && usage_exitoptions="$options $1"shiftMON_ADDR=$1;;--btrfs | --fsmount)dofsmount=1;;--nobtrfs | --nofsmount)dofsmount=0;;--btrfsumount | --fsumount)dofsumount=1;;--conf | -c)[ -z "$2" ] && usage_exitoptions="$options $1"shiftconf=$1;;--hostname )[ -z "$2" ] && usage_exitoptions="$options $1"shifthostname=$1;;*)echo unrecognized option \'$1\'usage_exit;;esacoptions="$options $1"shiftdoneverify_confcommand=$1[ -n "$*" ] && shiftget_local_name_listget_name_list "$@"# Reverse the order if we are stoppingif [ "$command" = "stop" ]; thenfor f in $what; donew_order="$f $new_order"donewhat="$new_order"fifor name in $what; dotype=`echo $name | cut -c 1-3` # e.g. 'mon', if $item is 'mon1'id=`echo $name | cut -c 4- | sed 's/^\\.//'`cluster=`echo $conf | awk -F'/' '{print $(NF)}' | cut -d'.' -f 1`num=$idname="$type.$id"check_host || continuebinary="$BINDIR/ceph-$type"cmd="$binary -i $id"get_conf run_dir "/var/run/ceph" "run dir"get_conf pid_file "$run_dir/$type.$id.pid" "pid file"if [ "$command" = "start" ]; thenif [ -n "$pid_file" ]; thendo_cmd "mkdir -p "`dirname $pid_file`cmd="$cmd --pid-file $pid_file"figet_conf log_dir "" "log dir"[ -n "$log_dir" ] && do_cmd "mkdir -p $log_dir"get_conf auto_start "" "auto start"if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; thenif [ -z "$@" ]; thenecho "Skipping Ceph $name on $host... auto start is disabled"continuefifiif daemon_is_running $name ceph-$type $id $pid_file; thenecho "Starting Ceph $name on $host...already running"do_mapcontinuefiget_conf copy_executable_to "" "copy executable to"if [ -n "$copy_executable_to" ]; thenscp $binary "$host:$copy_executable_to"binary="$copy_executable_to"fifi# conf filecmd="$cmd -c $conf"if echo $name | grep -q ^osd; thenget_conf osd_data "/var/lib/ceph/osd/ceph-$id" "osd data"get_conf fs_path "$osd_data" "fs path" # mount point defaults so osd dataget_conf fs_devs "" "devs"if [ -z "$fs_devs" ]; then# try to fallback to old keysget_conf tmp_btrfs_devs "" "btrfs devs"if [ -n "$tmp_btrfs_devs" ]; thenfs_devs="$tmp_btrfs_devs"fififirst_dev=`echo $fs_devs | cut '-d ' -f 1`fi# do lockfile, if RHget_conf lockfile "/var/lock/subsys/ceph" "lock file"lockdir=`dirname $lockfile`if [ ! -d "$lockdir" ]; thenlockfile=""figet_conf asok "$run_dir/ceph-$type.$id.asok" "admin socket"case "$command" instart)# Increase max_open_files, if the configuration calls for it.get_conf max_open_files "32768" "max open files"# build final commandwrap=""runmode=""runarg=""[ -z "$docrun" ] && get_conf_bool docrun "0" "restart on core dump"[ "$docrun" -eq 1 ] && wrap="$BINDIR/ceph-run"[ -z "$dovalgrind" ] && get_conf_bool valgrind "" "valgrind"[ -n "$valgrind" ] && wrap="$wrap valgrind $valgrind"[ -n "$wrap" ] && runmode="-f &" && runarg="-f"[ -n "$max_open_files" ] && files="ulimit -n $max_open_files;"if [ $SYSTEMD -eq 1 ]; thencmd="systemd-run -r bash -c '$files $cmd --cluster $cluster -f'"elsecmd="$files $wrap $cmd --cluster $cluster $runmode"fiif [ $dofsmount -eq 1 ] && [ -n "$fs_devs" ]; thenget_conf pre_mount "true" "pre mount command"get_conf fs_type "" "osd mkfs type"if [ -z "$fs_type" ]; then# try to fallback to to old keysget_conf tmp_devs "" "btrfs devs"if [ -n "$tmp_devs" ]; thenfs_type="btrfs"elseecho No filesystem type defined!exit 0fifiget_conf fs_opt "" "osd mount options $fs_type"if [ -z "$fs_opt" ]; thenif [ "$fs_type" = "btrfs" ]; then#try to fallback to old keysget_conf fs_opt "" "btrfs options"fiif [ -z "$fs_opt" ]; thenif [ "$fs_type" = "xfs" ]; thenfs_opt="rw,noatime,inode64"else#fallback to use at least noatimefs_opt="rw,noatime"fififi[ -n "$fs_opt" ] && fs_opt="-o $fs_opt"[ -n "$pre_mount" ] && do_cmd "$pre_mount"if [ "$fs_type" = "btrfs" ]; thenecho Mounting Btrfs on $host:$fs_pathdo_root_cmd_okfail "modprobe btrfs ; btrfs device scan || btrfsctl -a ; egrep -q '^[^ ]+ $fs_path' /proc/mounts || mount -t btrfs $fs_opt $first_dev $fs_path"elseecho Mounting $fs_type on $host:$fs_pathdo_root_cmd_okfail "modprobe $fs_type ; egrep -q '^[^ ]+ $fs_path' /proc/mounts || mount -t $fs_type $fs_opt $first_dev $fs_path"fiif [ "$ERR" != "0" ]; thenEXIT_STATUS=$ERRcontinuefifiif [ "$type" = "osd" ]; thenget_conf update_crush "" "osd crush update on start"if [ "${update_crush:-1}" = "1" -o "${update_crush:-1}" = "true" ]; then# update location in crushget_conf osd_location_hook "$BINDIR/ceph-crush-location" "osd crush location hook"osd_location=`$osd_location_hook --cluster ceph --id $id --type osd`get_conf osd_weight "" "osd crush initial weight"defaultweight="$(df -P -k $osd_data/. | tail -1 | awk '{ print sprintf("%.2f",$2/1073741824) }')"get_conf osd_keyring "$osd_data/keyring" "keyring"do_cmd "timeout 30 $BINDIR/ceph -c $conf --name=osd.$id --keyring=$osd_keyring osd crush create-or-move -- $id ${osd_weight:-${defaultweight:-1}} $osd_location"fifiecho Starting Ceph $name on $host...mkdir -p $run_dirget_conf pre_start_eval "" "pre start eval"[ -n "$pre_start_eval" ] && $pre_start_evalget_conf pre_start "" "pre start command"get_conf post_start "" "post start command"[ -n "$pre_start" ] && do_cmd "$pre_start"do_cmd_okfail "$cmd" $runargif [ "$ERR" != "0" ]; thenEXIT_STATUS=$ERRfiif [ "$type" = "mon" ]; then# this will only work if we are using default paths# for the mon data and admin socket. if so, run# ceph-create-keys. this is the case for (normal)# chef and ceph-deploy clusters, which is who needs# these keys. it's also true for default installs# via mkcephfs, which is fine too; there is no harm# in creating these keys.get_conf mon_data "/var/lib/ceph/mon/ceph-$id" "mon data"if [ "$mon_data" = "/var/lib/ceph/mon/ceph-$id" -a "$asok" = "/var/run/ceph/ceph-mon.$id.asok" ]; thenecho Starting ceph-create-keys on $host...cmd2="$SBINDIR/ceph-create-keys -i $id 2> /dev/null &"do_cmd "$cmd2"fifi[ -n "$post_start" ] && do_cmd "$post_start"[ -n "$lockfile" ] && [ "$?" -eq 0 ] && touch $lockfiledo_map;;stop)get_conf pre_stop "" "pre stop command"get_conf post_stop "" "post stop command"[ -n "$pre_stop" ] && do_cmd "$pre_stop"stop_daemon $name ceph-$type $pid_file[ -n "$post_stop" ] && do_cmd "$post_stop"[ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfileif [ $dofsumount -eq 1 ] && [ -n "$fs_devs" ]; thenecho Unmounting OSD volume on $host:$fs_pathdo_root_cmd "umount $fs_path || true"fido_unmap;;status)if daemon_is_running $name ceph-$type $id $pid_file; thenecho -n "$name: running "do_cmd "$BINDIR/ceph --admin-daemon $asok version 2>/dev/null" || echo unknownelif [ -e "$pid_file" ]; then# daemon is dead, but pid file still existsecho "$name: dead."EXIT_STATUS=1else# daemon is dead, and pid file is goneecho "$name: not running."EXIT_STATUS=3firbd showmapped;;ssh)$ssh;;forcestop)get_conf pre_forcestop "" "pre forcestop command"get_conf post_forcestop "" "post forcestop command"[ -n "$pre_forcestop" ] && do_cmd "$pre_forcestop"stop_daemon $name ceph-$type $pid_file -9[ -n "$post_forcestop" ] && do_cmd "$post_forcestop"[ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile;;killall)echo "killall ceph-$type on $host"do_cmd "pkill ^ceph-$type || true"[ -n "$lockfile" ] && [ "$?" -eq 0 ] && rm -f $lockfile;;force-reload | reload)signal_daemon $name ceph-$type $pid_file -1 "Reloading";;restart)$0 $options stop $name$0 $options start $name;;condrestart)if daemon_is_running $name ceph-$type $id $pid_file; then$0 $options stop $name$0 $options start $nameelseecho "$name: not running."fi;;cleanlogs)echo removing logs[ -n "$log_dir" ] && do_cmd "rm -f $log_dir/$type.$id.*";;cleanalllogs)echo removing all logs[ -n "$log_dir" ] && do_cmd "rm -f $log_dir/* || true";;*)usage_exit;;esacdone# activate latent osds?if [ "$command" = "start" -a "$BINDIR" != "." ]; thenif [ "$*" = "" ] || echo $* | grep -q ^osd\$ ; thenceph-disk activate-allfifiexit $EXIT_STATUS

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。