Skip to content

Commit

Permalink
添加nexus迁移文档
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliang-ms committed Dec 9, 2024
1 parent b821f2c commit 2892aed
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,154 +176,204 @@ scp /etc/ceph/{ceph.conf,ceph.client.admin.keyring} ip:/etc/ceph/
mkfs.ext4 -q /dev/rbd0
```

> 11.挂载使用

创建文件,写入挂载配置
```shell
mount /dev/rbd0 /ceph
vim /etc/rbd_mount.conf
```

> 12.查看挂载
配置内容如下:

```shell
lsblk
rbd-harbor-pool
rbd-harbor-image /ceph
```

> 13.查看块设备映射
创建挂载脚本,

```shell
[root@localhost ~]# rbd device list
id pool namespace image snap device
0 rbd-demo-pool rbd-demo-image - /dev/rbd0
mkdir -p /etc/init.d
vim /etc/init.d/ceph-mount-rbd.sh
```

> 14.修改`fstab`,设置开机挂载
内容如下:

```shell
echo "/dev/rbd0 /ceph ext4 defaults,noatime,_netdev 0 0" >> /etc/fstab
```

> 15.配置开机自启动
```shell
vim /etc/init.d/rbdmap
```

填充以下内容

```shell
````shell
#!/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 INFO

DESC="RBD Mapping"
RBDMAPFILE="/etc/ceph/rbdmap"

. /lib/lsb/init-functions
#. /etc/redhat-lsb/lsb_log_message,加入此行后不正长
do_map() {
if [ ! -f "$RBDMAPFILE" ]; then
echo "$DESC : No $RBDMAPFILE found."
exit 0
fi

echo "Starting $DESC"
# Read /etc/rbdtab to create non-existant mapping
newrbd=
RET=0
while read DEV PARAMS; do
case "$DEV" in
""|\#*)
continue
;;
*/*)
;;
*)
DEV=rbd/$DEV
;;
esac
OIFS=$IFS
IFS=','
for PARAM in ${PARAMS[@]}; do
CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"
done
IFS=$OIFS
if [ ! -b /dev/rbd/$DEV ]; then
echo $DEV
rbd map $DEV $CMDPARAMS
[ $? -ne "0" ] && RET=1
newrbd="yes"
fi
done < $RBDMAPFILE
echo $RET

# Mount new rbd
if [ "$newrbd" ]; then
echo "Mounting all filesystems"
mount -a
echo $?
fi
}
# chkconfig: 345 20 80
# description: 自动挂载 Ceph RBD 设备

do_unmap() {
echo "Stopping $DESC"
RET=0
# Unmap all rbd device
for DEV in /dev/rbd[0-9]*; do
echo $DEV
# Umount before unmap
MNTDEP=$(findmnt --mtab --source $DEV --output TARGET | sed 1,1d | sort -r)
for MNT in $MNTDEP; do
umount $MNT || sleep 1 && umount -l $DEV
done
rbd unmap $DEV
[ $? -ne "0" ] && RET=1
done
echo $RET
log_file="/var/log/ceph-mount.log"
mapping_file="/etc/rbd_mapping"
config_file="/etc/rbd_mount.conf"

log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$log_file"
}

log "脚本开始运行"

case "$1" in
start)
do_map
;;
log "读取配置文件并挂载 RBD 设备"

stop)
do_unmap
;;
if [ ! -f "$mapping_file" ]; then
touch "$mapping_file"
fi

if [ ! -f "$config_file" ]; then
log "配置文件不存在:$config_file"
exit 1
fi

reload)
do_map
;;
declare -A mappings

status)
rbd showmapped
;;
# 读取现有的映射关系
if [ -s "$mapping_file" ]; then
while read -r line; do
device=$(echo "$line" | awk '{print $1}')
mount_point=$(echo "$line" | awk '{print $2}')
mappings[$mount_point]=$device
done < "$mapping_file"
fi

# 清空映射文件
> "$mapping_file"

# 读取配置文件
while read -r line; do
log "读取行:$line"
# 忽略注释行和空行
if [[ $line =~ ^# ]] || [[ -z $line ]]; then
log "跳过行:$line"
continue
fi

# 解析配置
if [[ $line =~ ^\ *([^\ ]+)\ *$ ]]; then
pool=${BASH_REMATCH[1]}
log "设置 pool 为:$pool"
elif [[ $line =~ ^\ *([^\ ]+)\ *([^\ ]+)\ *$ ]]; then
image=${BASH_REMATCH[1]}
mount_point=${BASH_REMATCH[2]}
log "挂载 Ceph RBD 设备 $image$mount_point"

mapped_device=$(rbd map -p "$pool" "$image" --id admin --keyring /etc/ceph/ceph.client.admin.keyring)
if [ $? -ne 0 ]; then
log "RBD 映射失败,错误码:$?"
exit 1
fi

log "映射到的设备:$mapped_device"
if [ -n "$mapped_device" ];then
# 等待设备出现在 /dev 中
udevadm settle

if [ ! -e "$mapped_device" ]; then
log "设备 $mapped_device 不存在,等待 udev 处理"
sleep 5
fi

if [ ! -e "$mapped_device" ]; then
log "设备 $mapped_device 仍然不存在,映射失败"
exit 1
fi

# 记录映射
echo "$mapped_device $mount_point" >> "$mapping_file"
# 检查是否已格式化
fs_type=$(blkid -o value -s TYPE "$mapped_device")
if [ -z "$fs_type" ];then
log "设备未格式化,正在格式化设备:$mapped_device"
mkfs.ext4 "$mapped_device"
else
log "设备已格式化,文件系统类型:$fs_type"
fi

# 挂载设备
mkdir -p "$mount_point"
mount "$mapped_device" "$mount_point"
if [ $? -eq 0 ];then
log "挂载成功:$mapped_device$mount_point"
else
log "挂载失败:$mapped_device$mount_point,错误码:$?"
exit 1
fi
else
log "无法找到映射的设备"
exit 1
fi
else
log "无效的配置行:$line"
fi
done < "$config_file"
;;
stop)
log "停止所有挂载并解除映射"
if [ -s "$mapping_file" ];then
while read -r line; do
device=$(echo $line | awk '{print $1}')
mount_point=$(echo $line | awk '{print $2}')

umount "$mount_point"
if [ $? -eq 0 ];then
log "卸载成功:$device$mount_point"
else
log "卸载失败:$device$mount_point,错误码:$?"
fi

rbd unmap "$device"
if [ $? -eq 0 ];then
log "解除映射成功:$device"
else
log "解除映射失败:$device,错误码:$?"
fi
done < "$mapping_file"
fi
;;
*)
echo "Usage: rbdmap {start|stop|reload|status}"
exit 1
;;
echo "Usage: $0 {start|stop}"
exit 1
esac

exit 0
````

修改权限

```shell
chmod a+x /etc/init.d/ceph-mount-rbd.sh
```

配置service文件

```shell
cat > /etc/systemd/system/ceph-rbd-mount.service <<EOF
[Unit]
Description=Ceph RBD 自动挂载服务
After=network.target
[Service]
Type=oneshot
ExecStart=/etc/init.d/ceph-mount-rbd.sh start
ExecStop=/etc/init.d/ceph-mount-rbd.sh stop
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
EOF
```

启动服务

```shell
systemctl enable ceph-rbd-mount.service --now
```

> 16.赋权
查看状态

```shell
yum install redhat-lsb -y
chmod +x /etc/init.d/rbdmap
service rbdmap start
chkconfig rbdmap on
systemctl status ceph-rbd-mount.service
```

### 适用场景
Expand Down
41 changes: 40 additions & 1 deletion 1.Linux基础/1.7存储/lvm/lvm.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
## lvm架构

![](lvm.png)
![](lvm.png)

### 创建lvm

1. 创建pv

```shell
pvcreate /dev/sdb
```

2. 创建vg

```shell
vgcreate data-volume /dev/sdb
```

3. 创建lv(逻辑卷)

```shell
lvcreate -n data-lv -l 100%free data-volume
```

4. 格式化lv

```shell
mkfs.ext4 /dev/data-volume/data-lv
```

5. 挂载使用

```shell
mkdir /data
mount /dev/data-volume/data-lv
```

6. 设置自动挂载

```shell
echo "/dev/data-volume/data-lv /data ext4 defaults 0 0" >> /etc/fstab
```
5 changes: 3 additions & 2 deletions 1.Linux基础/rockylinux/10配置chrony.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ EOF

启动
```shell
$ systemctl enable chronyd --now
systemctl enable chronyd --now
```

手动同步

```shell
timedatectl set-ntp true
chronyc -a makestep
timedatectl set-ntp yes
```
4 changes: 2 additions & 2 deletions 2.容器/cni/cilium/cilium替换calico.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ https://www.cnblogs.com/dudu/p/16269093.html
查看模式

```shell
$ kubectl exec -it -n kube-system ds/cilium -- cilium status | grep KubeProxyReplacement
kubectl exec -it -n kube-system ds/cilium -- cilium status | grep KubeProxyReplacement
```

查看服务列表

```shell
$ kubectl exec -it -n kube-system daemonset/cilium -- cilium service list
kubectl exec -it -n kube-system daemonset/cilium -- cilium service list
```

删除iptables
Expand Down
Loading

0 comments on commit 2892aed

Please sign in to comment.