当前位置: 首页 > article >正文

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

shell

    • 脚本实现
    • 脚本测试

脚本实现自动化配置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

脚本测试

节点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/

脚本部署

[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
[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 ~]#

从节点验证

[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 ~]#
[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

http://www.kler.cn/a/107813.html

相关文章:

  • ARM架构中断与异常向量表机制解析
  • Bugku CTF_Web——点login咋没反应
  • 开发语言中,堆区和栈区的区别
  • Linux git-bash配置
  • React的基础API介绍(二)
  • Jmeter性能测试 -3数据驱动实战
  • QT中获取当前项目路径的写法
  • 已有wchar_t *类型的filepath,使用Qt打开该文件
  • CLIP文章精读
  • 【计算机毕设经典案例】基于微信小程序的图书管理系统
  • 水性杨花:揭秘CSS响应式界面设计,让内容灵活自如,犹如水之变幻
  • synchronized 的锁类型
  • 使用mac自带VNC公网远程控制macOS
  • [备忘.Linux]服务部署管理常用命令|systemd
  • JS条件表达式
  • [Python] OSError: [E050] Can‘t find model ‘en_core_web_sm‘.
  • 实用篇-认识微服务
  • stable-diffusion-ui 下载和安装
  • 【uniapp】仿微信支付界面
  • Day 46 动态规划 part12
  • 【问题】在安装torchvision的时候,会自动安装torch?
  • 【考研数学】数学“背诵”手册 | 需要记忆且容易遗忘的知识点
  • 软考系列(系统架构师)- 2009年系统架构师软考案例分析考点
  • 【JAVA学习笔记】50 - Math类,Array类,System类,BigInteger和BigDecimal类
  • IO流框架,缓冲流
  • 【Codeforces】 CF79D Password