admin 管理员组

文章数量: 887007

一.本地yum服务kylin的创建:

1.背景

项目安装部署过程中,有很多包需要在线下载,但又是网络是隔离的,无法连接外网。

此时,我们需要kylin v10源中的所有rpm包一次性全部下载到本地机器,搭建一个本地yum源或者局域网yum源,用于离线安装。

首先使用官网镜像在本地vmware上利用镜像Kylin-Server-10-SP2-Release-Build09-20210524-x86_64.iso创建安装kylin-v10的系统

2.进入kylin v10系统,利用linux终端登录工具登录到系统中首先执行安装reposync的工具

yum -y install   yum-utils

3.设置 Kylin v10 SP1yum源如下:

cd /etc/yum.repo.d/

mkdir bak

mv kylin_x86_64.repo bak/

###重新编辑创建kylin_x86_64.repo的文件

cat > /etc/yum.repos.d/kylin_x86_64.repo <<EOF

###Kylin Linux Advanced Server 10 - os repo###

[os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = https://update.cs2c/NS/V10/V10SP1/os/adv/lic/base/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = http://update.cs2c/NS/V10/V10SP1/os/adv/lic/updates/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[addons]
name = Kylin Linux Advanced Server 10 - Addons
baseurl = http://update.cs2c/NS/V10/V10SP1/os/adv/lic/addons/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

EOF

或者

 vim /etc/yum.repos.d/kylin_x86_64.repo
###Kylin Linux Advanced Server 10 - os repo###

[os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = https://update.cs2c/NS/V10/V10SP1/os/adv/lic/base/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = http://update.cs2c/NS/V10/V10SP1/os/adv/lic/updates/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[addons]
name = Kylin Linux Advanced Server 10 - Addons
baseurl = http://update.cs2c/NS/V10/V10SP1/os/adv/lic/addons/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

3.执行命令把rpm包下载到本地目录例如/opt/kylin

mkidr /opt/kylin

reposync -p /opt/kylin/

####显示以下内容则为成功

 找到对应的x86_64目录下:移动 /opt/kylin/os/Packages目录到此目录下:

在这里用了项目的*yum-repo.tar.gz,直接解压此包

tar xf *yum-repo.tar.gz -C /opt/tmp

mv /opt/tmp/*yum-repo /opt/tmp/kylin-yum-repo

cd /opt/centos/7/x86_64

rm -rf *

mv /opt/kylin/os/Packages .
createrepo .

cd /opt/tmp/kylin-yum-repo

 bash install.sh 192.168.24.136 /opt

以下为执行成功:

 

本地挂iso方式创建本地离线yum源

二. 使用麒麟v10的iso镜像创建本地yum源

1.在服务器本地创建新的文件夹 /opt/kylin

    # mount  Kylin-Server-10-SP1-Release-Build04-20200711-x86_64.iso   /mnt    //将对应系统iso镜像上传到系统,并挂载到/mnt目录
    # mkdir  /opt/kylin      #这是举例,路径和名称视情况而定

    # cp  -r   /mnt/Packages  /opt/kylin/     #将镜像内容的所有rpm包拷贝到本地目录,可以防止服务器重启挂载失效

   #cd /opt/kylin/;createrepo .    #生成repo文件


2.编辑yum配置文件
    配置文件在/etc/yum.repo.d下,首先将文件夹下默认的外网源配置文件备份
    # cd  /etc/yum.repos.d
    # mkdir  bak
    # mv  *.repo  bak
 

3.创建新的配置文件
# vim  kylin.repo      #配置文件必须以repo为后缀,名称随意
编辑配置文件内容为

[kylin]
name=kylin repo
baseurl=file:///opt/kylin
gpgcheck=0
enable=1

保存退出

或者

echo "

[kylin]
name=kylin repo
baseurl=file:///opt/kylin
gpgcheck=0
enable=1" > /etc/yum.repos.d/kylin.repo

或者

cat > /etc/yum.repos.d/kylin_x86_64.repo <<EOF

[kylin]
name=kylin repo
baseurl=file:///opt/kylin
gpgcheck=0
enable=1

EOF

4.清除yum缓存,查看配置是否生效
# yum  clean all     //清缓存
# yum  repolist      //查看是否生效,yum源有数量即为生效


5.yum安装rzsz例包
# yum install   -y
参考链接:
原文链接:https://blog.csdn/qq_28903377/article/details/120703047

 拓展:借鉴思想

1. yum 下载rpm包到指定目录,只下载不安装,找任何环境上制作下载离线包

yum install  --downloadonly --downloaddir=路径  安装包名

例如: yum install  --downloadonly --downloaddir=/opt screen

yum install  --downloadonly --downloaddir=/opt  nginx

检查是否有这11个包,若都满足,证明nginx依赖齐了,在麒麟v10系统上能成功安装nginx 1.16

 

java-1.8.0-openjdk满足以下8个包则依赖全

 

 

 

2.写一个小脚本,将epel源中的所有rpm包一次性下载

# cat dowmload_epel_rpm.sh

########################################

#!/bin/bash

rpms=`yum list all --disablerepo="*" --enablerepo="epel" | grep -Ev "Loaded|Loading|Installed" | awk '{print $1}'`

mkdir  -p  yum

for rpm  in ${rpms}

do

  repotrack  ${rpm}  -p  yum

done

######################################

三.使用iso镜像创建本地yum服务 kylin.service

# mount  Kylin-Server-10-SP1-Release-Build04-20200711-x86_64.iso   /mnt 

cp -r /mnt/Packages /opt/kylin-yum-repo/centos/7/x86_64/

cd /opt/kylin-yum-repo/centos/7/x86_64/ ;createrepo .

cat > kylin.repo.template  << EOF
[kylin]
name=Kylin components
baseurl=http://%kylin-yum-repo-ip%:881/centos/7/$basearch/
enabled=1
gpgcheck=0

EOF

 

cat > install.sh << EOF

#!/bin/bash

USAGE="Usage: $0 <local-ip>"

if [ -z "$1" ]; then
  echo "Local IP is empty"
  echo $USAGE
  exit 1
fi

local_ip=$1
work_dir=$2

if [ "$work_dir" == "" ]; then
        work_dir="`echo /opt`"
fi

echo "Local IP: $local_ip"
echo "Work Direction: $work_dir"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $DIR

TARGET_DIR=$work_dir/kylin-yum-repo
rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR

echo "Copying packages, which may take a while..."
cp -rf centos $TARGET_DIR

cp kylin.repo.template $TARGET_DIR/kylin.repo
sed -i "s#%kylin-yum-repo-ip%#$local_ip#g" $TARGET_DIR/kylin.repo

cp -f bin/static-file-server-v1.6.4-linux-amd64 $TARGET_DIR/static-file-server
chmod +x $TARGET_DIR/static-file-server

# 替换kylin-yum-repo.service的配置
# add privilege:/usr/lib/systemd/system
sudo chmod o+w /usr/lib/systemd/system

cp -f kylin-yum-repo.service /usr/lib/systemd/system
sed -i "s#%work_dir%#$work_dir#g" /usr/lib/systemd/system/kylin-yum-repo.service

# remove privilege:/usr/lib/systemd/system
sudo chmod o-w /usr/lib/systemd/system

sudo systemctl daemon-reload
sudo systemctl enable kylin-yum-repo

echo "Starting kylin-yum-repo..."
sudo systemctl start kylin-yum-repo
echo "run curl or wget to enable Kylin yum repo:"
echo "  curl -o /etc/yum.repos.d/kylin.repo http://$local_ip:881/kylin.repo"
curl -o /etc/yum.repos.d/kylin.repo http://$local_ip:881/kylin.repo
echo "  wget -O /etc/yum.repos.d/kylin.repo http://$local_ip:881/kylin.repo"
wget -O /etc/yum.repos.d/kylin.repo http://$local_ip:881/kylin.repo
echo "Then you can run yum to install pacakge from Kylin yum repo, for example:"

echo ""
echo "Install kylin-yum-repo succeed."
echo ""
echo "In wherever you need to install Kylin-related packages (e.g. nginx), "
echo '  yum --disablerepo="*" --enablerepo=kylin install nginx'
yum --disablerepo="*" --enablerepo=kylin install telnet
sudo systemctl status kylin-yum-repo && sleep 30

EOF

cat > kylin-yum-repo.service << EOF
[Unit]
Description=Kylin Yum Repo

[Service]
Type=simple
WorkingDirectory=%work_dir%/kylin-yum-repo
Environment="PORT=881"
Environment="FOLDER=%work_dir%/kylin-yum-repo"
ExecStart=%work_dir%/kylin-yum-repo/static-file-server
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

EOF

cat  > uninstall.sh <<EOF
#!/bin/bash
work_dir=$1

if [ "$work_dir" == "" ]; then
        work_dir="`echo /opt`"
fi

rm -rf $work_dir/kylin-yum-repo
sudo systemctl stop kylin-yum-repo

# add
sudo chmod o+w /usr/lib/systemd/system
# clear
rm -f /usr/lib/systemd/system/kylin-yum-repo.service
# remove
sudo chmod o-w /usr/lib/systemd/system

EOF

配置完后:

安装kylin-yum-repo服务:

执行install.sh

bash install.sh 本地ip  安装目录work_dir
 

例如

bash install.sh 192.168.24.188 /opt

检查kylin-yum-repo端口:

 netstat -nulpt |grep 881

 

卸载kylin-yum-repo服务:

bash uninstall.sh  安装目录work_dir

例如:

bash uninstall.sh /opt

本文标签: 安装包 目录 系统 kylin yum