• shell实现部署ftp提供共享yum仓库


    脚本实现自动化配置vsftp,并共享opt目录给其它节点机器实现离线源配置

    使用脚本需修改以下内容:
    ftp_ip为ftp服务器ip
    reponame为repo文件名字
    dir为仓库目录,默认opt下
    houzui为opt目录下的离线仓库,写入到houzui中为数组
    使用前还需保持服务器可以下载vsftp服务

    脚本实现

    #!/bin/bash
    
    ftp_ip="192.168.200.80"
    reponame="local.repo"
    houzui=("centos" "iaas")
    opt="/opt"
    
    if [ "$(hostname -I | awk '{print $1}')" = "$ftp_ip" ]; then
        systemctl stop firewalld
        setenforce 0
        yum install -y vsftpd
        echo "anon_root=$opt" >> /etc/vsftpd/vsftpd.conf
        systemctl enable --now vsftpd
        systemctl restart vsftpd
        rm -rf /etc/yum.repos.d/*
        for repo in "${houzui[@]}"; do
            cat >> "/etc/yum.repos.d/$reponame" <<eof
    [$repo]
    name=$repo
    baseurl=file://$opt/$repo
    gpgcheck=0
    enabled=1
    eof
        done
        yum clean all
        yum repolist
    else
        rm -rf /etc/yum.repos.d/*
        for repo in "${houzui[@]}"; do
            cat >> "/etc/yum.repos.d/$reponame" <<eof
    [$repo]
    name=$repo
    baseurl=ftp://$ftp_ip/$repo
    gpgcheck=0
    enabled=1
    eof
        done
        yum clean all
        yum repolist
    fi
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    脚本测试

    节点IP
    节点1192.168.200.80
    节点2192.168.200.81
    节点3192.168.200.82

    手动配置好离线仓库

    [root@localhost ~]# mkdir /opt/{centos,iaas}
    [root@localhost ~]# mount /dev/sr0 /opt/centos/
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@localhost ~]# cp -rf /opt/centos/* /opt/iaas/
    
    • 1
    • 2
    • 3
    • 4

    脚本部署

    [root@localhost ~]# cat repo.sh
    #!/bin/bash
    
    ftp_ip="192.168.200.80"
    reponame="local.repo"
    houzui=("centos" "iaas")
    opt="/opt"
    
    if [ "$(hostname -I | awk '{print $1}')" = "$ftp_ip" ]; then
        systemctl stop firewalld
        setenforce 0
        yum install -y vsftpd
        echo "anon_root=$opt" >> /etc/vsftpd/vsftpd.conf
        systemctl enable --now vsftpd
        systemctl restart vsftpd
        rm -rf /etc/yum.repos.d/*
        for repo in "${houzui[@]}"; do
            cat >> "/etc/yum.repos.d/$reponame" <<eof
    [$repo]
    name=$repo
    baseurl=file://$opt/$repo
    gpgcheck=0
    enabled=1
    eof
        done
        yum clean all
        yum repolist
    else
        rm -rf /etc/yum.repos.d/*
        for repo in "${houzui[@]}"; do
            cat >> "/etc/yum.repos.d/$reponame" <<eof
    [$repo]
    name=$repo
    baseurl=ftp://$ftp_ip/$repo
    gpgcheck=0
    enabled=1
    eof
        done
        yum clean all
        yum repolist
    fi
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    [root@localhost ~]# hostname -I
    192.168.200.80
    [root@localhost ~]# bash repo.sh
    [root@localhost ~]# cat /etc/yum.repos.d/local.repo
    [centos]
    name=centos
    baseurl=file:///opt/centos
    gpgcheck=0
    enabled=1
    [iaas]
    name=iaas
    baseurl=file:///opt/iaas
    gpgcheck=0
    enabled=1
    [root@localhost ~]# yum clean all;yum repolist
    Loaded plugins: fastestmirror
    Cleaning repos: centos iaas
    Cleaning up list of fastest mirrors
    Other repos take up 195 M of disk space (use --verbose for details)
    Loaded plugins: fastestmirror
    Determining fastest mirrors
    centos                                                                                           | 3.6 kB  00:00:00
    iaas                                                                                             | 3.6 kB  00:00:00
    (1/4): centos/group_gz                                                                           | 153 kB  00:00:00
    (2/4): centos/primary_db                                                                         | 3.3 MB  00:00:00
    (3/4): iaas/group_gz                                                                             | 153 kB  00:00:00
    (4/4): iaas/primary_db                                                                           | 3.3 MB  00:00:00
    repo id                                                  repo name                                                status
    centos                                                   centos                                                   4,070
    iaas                                                     iaas                                                     4,070
    repolist: 8,140
    [root@localhost ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    从节点验证

    [root@localhost ~]# cat /etc/yum.repos.d/local.repo
    [centos]
    name=centos
    baseurl=ftp://192.168.200.80/centos
    gpgcheck=0
    enabled=1
    [iaas]
    name=iaas
    baseurl=ftp://192.168.200.80/iaas
    gpgcheck=0
    enabled=1
    [root@localhost ~]# yum clnen all;yum repolist
    Loaded plugins: fastestmirror
    No such command: clnen. Please use /usr/bin/yum --help
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                                                  repo name                                                status
    centos                                                   centos                                                   4,070
    iaas                                                     iaas                                                     4,070
    repolist: 8,140
    [root@localhost ~]# hostname -I
    192.168.200.81
    [root@localhost ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    [root@localhost ~]# bash repo.sh
    Loaded plugins: fastestmirror
    Cleaning repos: centos iaas
    Cleaning up list of fastest mirrors
    Loaded plugins: fastestmirror
    Determining fastest mirrors
    centos                                                                                           | 3.6 kB  00:00:00
    iaas                                                                                             | 3.6 kB  00:00:00
    (1/4): iaas/group_gz                                                                             | 153 kB  00:00:00
    (2/4): centos/group_gz                                                                           | 153 kB  00:00:00
    (3/4): centos/primary_db                                                                         | 3.3 MB  00:00:00
    (4/4): iaas/primary_db                                                                           | 3.3 MB  00:00:00
    repo id                                                  repo name                                                status
    centos                                                   centos                                                   4,070
    iaas                                                     iaas                                                     4,070
    repolist: 8,140
    [root@localhost ~]# hostname -I
    192.168.200.82
    [root@localhost ~]# cat /etc/yum.repos.d/local.repo
    [centos]
    name=centos
    baseurl=ftp://192.168.200.80/centos
    gpgcheck=0
    enabled=1
    [iaas]
    name=iaas
    baseurl=ftp://192.168.200.80/iaas
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    Flink 简单 入门大纲
    吃鸡战力提升与精彩干货分享,一站式游戏助手“鸡力心”!
    Uniapp 增加百度统计代码
    OAuth2:资源服务器
    《安富莱嵌入式周报》第324期:单对以太网技术实战,IROS2023迪士尼逼真机器人展示,数百万模具CAD文件下载,闭环步进电机驱动器,CANopen全解析
    【C++】class的设计与使用(十一)指向类成员函数的指针 VS 一般函数指针
    聊聊「低代码」的实践之路
    如何有效应对差评对亚马逊销量的影响及应对措施
    modbusRTU通信简单实现(使用NModbus4通信库)
    调用gethostbyname实现域名解析(附源码)
  • 原文地址:https://blog.csdn.net/m0_56363537/article/details/134096201