如何创建CPAN私有或离线镜像?

Linux基础

1 理论部分

1.1 命令作用

minicpan命令是用于创建或更新本地镜像

1.2 命令行选项

minicpan [options]
 
Options
  -l LOCAL    - where is the local minicpan?     (required)
  -r REMOTE   - where is the remote cpan mirror? (required)
  -d 0###     - permissions (numeric) to use when creating directories
  -f          - check all directories, even if indices are unchanged
  -p          - mirror perl, ponie, and parrot distributions
  --debug     - run in debug mode (print even banal messages)
  -q          - run in quiet mode (don't print status)
  -qq         - run in silent mode (don't even print warnings)
  -c CLASS    - what class to use to mirror (default: CPAN::Mini)
  -C FILE     - what config file to use (default: ~/.minicpanrc)
  -h          - print help and exit
  -v          - print version and exit
  -x          - build an exact mirror, getting even normally disallowed files
  -t SEC      - timeout in sec. Defaults to 180 sec
  --offline   - operate in offline mode (generally: do nothing)
  --log-level - provide a log level; instead of --debug, -q, or -qq
  --remote-from TYPE - cpan remote from 'cpan' or 'cpanplus' configs

注,参数大致中文解析如下,

- l参数,指定保存镜像的路径(必须)
- r参数,指定要同步的远程的镜像地址(必须)
- d参数,指定创建目录是的权限,如“0660”
- f参数,检查所有目录(即使索引不变)
- p参数,镜像perl、ponie和parrot distributions
- debug参数,使用调试模式运行
- q参数,以安静模式运行(无状态消息)
- qq参数,以静默模式运行(无警告)
- c参数,使用镜像的类,例如“CPAN::Mini”
- C参数,指定配置文件,例如“~/.minicpanrc”
- h参数,打印帮助信息
- v参数,打印版本信息
- x参数,构建精确的镜像(甚至可以正常访问不允许的文件)
- t参数,设置超时时间(单位为秒,默认180秒)
- offline参数,以离线模式运行
- log-level参数,提供日志级别的运行
- remote-from参数,cpan远程从cpan或cpanplus配置

2 实践部分

2.1 基础配置

2.1.1 环境信息

OS = CentOS 7.4 x86_64
IP Address = 10.168.0.x
Host Name = cpan.cmdschool.org

2.1.2 安装CPAN

yum install perl-CPAN

2.1.3 安装编译环境

yum install -y gcc gcc-c++ make expat-devel

2.1.4 添加运行用户

useradd -d /usr/cpan -s /bin/bash cpan

2.1.5 安装常用的工具

yum install -y vim

2.2 安装配置CPAN镜像

2.2.1 安装minicpan工具

su - cpan
cpan CPAN::Mini

2.2.2 新建镜像存储目录

mkdir /data/cpan/

注:由于源的分享不是本章重点,如需客户端能读取请自行搭建http服务

2.2.3 手动测试镜像更新

minicpan -l /data/cpan/ -r http://mirrors.163.com/cpan/

注:镜像源可参考以下链接,
https://www.cpan.org/SITES.html

2.2.4 设置镜像配置文件

如果你想简化,建议使用配置文件指定镜像的保存目录和镜像的源,有以下四种方式,

2.2.4.1 使用命令行参数指定配置文件

vim /usr/cpan/minicpanrc

加入如下内容:

local:  /data/cpan/
remote: http://mirrors.163.com/cpan/
exact_mirror: 1

使用参数指定配置文件执行镜像:

minicpan -C /usr/cpan/minicpanrc

2.2.4.2 使用环境变量声明配置文件路径

vim /etc/profile.d/minicpanrc.sh

加入如下内容:

export CPAN_MINI_CONFIG=/usr/cpan/minicpanrc

导入环境变量是配置生效:

source /etc/profile

检查环境变量

echo $CPAN_MINI_CONFIG

使用参数指定配置文件执行镜像:

minicpan

注:以上方法所有用户都有效

2.2.4.3 使用默认用户配置文件

vim ~/.minicpanrc

加入如下内容:

local:  /data/cpan/
remote: http://mirrors.163.com/cpan/
exact_mirror: 1

测试执行:

minicpan

注:以上方法仅当前用户有效

2.2.4.4 使用CPAN的配置文件声明

官方给出的路径,

CPAN/Mini/minicpan.conf

注:暂时没有理解,有待测试

2.3 修改客户端CPAN的源

2.3.1 向导方式修改

2.3.1.1 进入cpan子命令

cpan

2.3.1.2 查看当前配置

cpan[1]> o conf

2.3.1.3 修改配置

cpan[2]> o conf urllist push http://mirrors.163.com/cpan/

2.3.1.4 提交配置

cpan[3]> o conf commit

2.3.1.5 退出配置

cpan[5]> exit

2.3.2 配置文件方式修改

vim /usr/share/perl5/CPAN/Config.pm

修改如下行的配置:

'urllist' => [q[http://mirrors.163.com/cpan/]],

参阅文档:
============================
https://metacpan.org/pod/distribution/CPAN-Mini/bin/minicpan

没有评论

发表回复

Linux基础
如何熟悉Linux的PAM模块

1 PAM的简介 1.1 PAM的概念 – PAM即Pluggable Authenti …

Linux基础
如何配置RHEL 8.x OpenSSH客户端登录自动过期?

1 前言 一个问题,一篇文章,一出故事。 基于服务器安全,笔者需要让OpenSSH客户端在10分钟内 …

Linux基础
如何安装部署SentinelOne EDR?

1 基础知识 1.1 软件公司介绍 SentinelOne,Inc.是一家在纽约证券交易所上市的美国 …