第一步、首先去到Prometheus的镜像源仓库
https://packagecloud.io/app/prometheus-rpm/release/search
下载想要同步YUM源的repo文件
rpm
quick install
curl -s https://packagecloud.io/install/repositories/prometheus-rpm/release/script.rpm.sh | sudo bash
full script.rpm.sh 下载的脚本内容如下:
#!/bin/bash
epoch_time=`date +%s`
# Set the target directory where .npmrc will be written by setting the $DIR
# environment variable prior to running this script.
#
# If $DIR is left unset, the script will default to writing an .npmrc in
# the current user's home directory.
#
# Alternatively, $DIR can be set to a specific directory so that the npmrc
# takes effect only for commands run in that directory.
set_write_dir () {
if [[ -z $DIR ]]; then
NPMRC_DEST_DIR=$HOME
elif [[ ! -d $DIR ]]; then
echo "${DIR} does not exist. You must specify an existing directory for .npmrc to be written."
exit 1
else
NPMRC_DEST_DIR=$DIR
fi
}
curl_check ()
{
echo "Checking for curl..."
if command -v curl > /dev/null; then
echo "Detected curl..."
else
echo "curl could not be found, please install curl and try again"
exit 1
fi
}
abort_if_npmrc_exists ()
{
if [[ ( -e ${NPMRC_DEST_DIR}/.npmrc ) && ( -z "${force_npm}" ) ]]; then
echo
echo "WARNING: your system already has an ${NPMRC_DEST_DIR}/.npmrc file"
echo " this script will now exit without doing anything!"
echo
echo "You can also specify an alternate directory where .npmrc will be written by setting"
echo "DIR and re-running the script (e.g., DIR=/var/code/project ./script.sh)"
echo
echo "If you want to use ${NPMRC_DEST_DIR} even though it has an .npmrc already, you should either"
echo "delete your existing ${NPMRC_DEST_DIR}/.npmrc or set force_npm=1 when running"
echo "this script!"
echo
exit 1
elif [[ ( -e ${NPMRC_DEST_DIR}/.npmrc ) ]]; then
echo "Existing ${NPMRC_DEST_DIR}/.npmrc file detected, but force_npm specified."
echo "Renaming your existing file to: ${NPMRC_DEST_DIR}/${epoch_time}.npmrc.bak."
mv ${NPMRC_DEST_DIR}/.npmrc ${NPMRC_DEST_DIR}/${epoch_time}.npmrc.bak
fi
}
generate_npmrc ()
{
echo "Generating ${NPMRC_DEST_DIR}/.npmrc..."
repo_url=https://packagecloud.io/prometheus-rpm/release/npm/
echo "registry=${repo_url}" > ${NPMRC_DEST_DIR}/.npmrc
if [[ -z "$DIR" ]]; then
echo
echo "You didn't specify the environment variable DIR, so your .npmrc file was written to your home directory (${NPMRC_DEST_DIR})."
echo "If you want to create a project specific npmrc, you can re-run this script and set \$DIR to the directory where .npmrc should be written."
fi
}
main ()
{
curl_check
set_write_dir
abort_if_npmrc_exists
generate_npmrc
}
main
运行
yum clean all
yum makecache
更新仓库元数据
第二步、安装必要的软件包
yum install createrepo yum-utils -y
安装完之后,查看仓库名字
或者到/etc/yum.repos.d 查看需要创建本地yum源的仓库名字
创建一个文件夹,用于当作本地yum源的仓库目录
mkdir -p prometheus.repo
next
reposync -r prometheus-rpm_release -p ./prometheus.repo/
然后创建
createrepo -v ./prometheus.repo/
之后在/root/prometheus.repo文件夹内生成以下文件repodata
三、搭建httpd服务器将/root/prometheus.repo文件夹,复制到网站根目录/var/www/html下
四、在client端/etc/yum.repos.d下创建prometheus.repo文件
如下:
[prometheus]
name=prometheus
baseurl=http://IP/prometheus.repo/
enabled=1
gpgcheck=0
之后运行yum clean all & yum makecache 生成缓存元数据即可。