ubuntu搭建APT私有仓库

第1章ubuntu搭建APT私有仓库

1.1实验环境准备

操作系统为ubuntu14.04

root@ubuntu:~# uname -a

Linux ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

 

关闭防火墙(我是关闭了,怕出错)

root@ubuntu:~# ufw disable

Firewall stopped and disabled on system startup

如果没有ufw,使用apt-get -y install ufw下载即可

 

IP地址为192.168.56.18 内网为172.16.1.18

root@ubuntu:~# ip a show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:d4:a1:85 brd ff:ff:ff:ff:ff:ff

    inet 192.168.56.18/24 brd 192.168.56.255 scope global eth0

       valid_lft forever preferred_lft forever

    inet6 fe80::20c:29ff:fed4:a185/64 scope link

       valid_lft forever preferred_lft forever

root@ubuntu:~# ip a show eth1

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000

    link/ether 00:0c:29:d4:a1:8f brd ff:ff:ff:ff:ff:ff

    inet 172.16.1.18/24 brd 192.168.56.255 scope global eth1

       valid_lft forever preferred_lft forever

    inet6 fe80::20c:29ff:fed4:a18f/64 scope link

       valid_lft forever preferred_lft forever

 

1.2实验参考文档

http://www.cnblogs.com/huangyibo/p/4360602.html

http://blog.csdn.net/mountzf/article/details/51863859

https://wenku.baidu.com/view/de8a1d9c3c1ec5da51e2704f.html

https://wenku.baidu.com/view/7ebaf1bf960590c69ec3769c.html?re=view

http://www.cnblogs.com/Genesis-007/p/5219960.html

http://www.xuebuyuan.com/937430.html

http://blog.csdn.net/ermuzhi/article/details/7817801

http://blog.csdn.net/wanghaitao95/article/details/10187339

http://blog.csdn.net/sky_qing/article/details/8469946

http://blog.csdn.net/ermuzhi/article/details/7817801

https://linux.cn/article-5707-1.html

http://www.xuebuyuan.com/937430.html

http://blog.csdn.net/yygydjkthh/article/details/36902781

http://www.cnblogs.com/Genesis-007/p/5219960.html

http://purplegrape.blog.51cto.com/1330104/1586097

http://www.xuebuyuan.com/937430.html

http://www.cnblogs.com/Genesis-007/p/5219960.html

http://blog.csdn.net/michaelwubo/article/details/41844997

https://www.debian.org/doc/manuals/maint-guide/build.zh-cn.html

以上网站内容仅做参考,内容都大同小异;

1.3配置阿里云仓库

在文件/etc/ apt/sources.list的最后一行加入如下内容

deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse

  deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse

  deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse

  deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse

  deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse

  deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse

  deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse

  deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse

  deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse

  deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse

然后:wq保存退出

root@ubuntu:~# apt-get update 进行更新仓库,一定要操作

1.4安装nginx及fpm

安装nginx主要为了提供仓库的web服务,fpm主要提供打包模板,及自定义生成deb包;

下载nginx的依赖包(注意:不要一起执行)

apt-get -y install build-essential

apt-get -y install libpcre3 libpcre3-dev

apt-get -y install ruby

apt-get -y install zlib1g-dev

apt-get -y install openssl libssl-dev

安装好nginx的依赖包后,下载nginx的源码包,进行编译安装

wget http://nginx.org/download/nginx-1.6.0.tar.gz

tar xvf nginx-1.6.0.tar.gz

./configure

 make  

 make install

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx

然后可以进行测试访问一下

root@ubuntu:~# curl -I 192.168.56.18

HTTP/1.1 200 OK

Server: nginx/1.6.0

Date: Thu, 07 Sep 2017 07:41:43 GMT

Content-Type: text/html

Connection: keep-alive

显示200的状态码,说明可以访问

第2章安装fpm打包工具

使用apt-get下载所需要用到的工具

apt-get -y install ruby-full

apt-get -y install rubygems

移除原有的rubygems,使用国内的红宝石,此处遇到无数的坑;主要还是看脸

root@ubuntu:~# gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

Error fetching https://gems.ruby-china.org/:

         hostname was not match with the server certificate (https://gems.ruby-china.org/specs.4.8.gz)

然后用淘宝的也不行

gem sources --add https://ruby.taobao.org/ --remove http://rubygems.org/

最后实在困得不行了,关机睡了,第二早开机一弄,可以用了,不过强哥提供了一个阿里云的红宝石,就用了阿里云的

gem sources -a http://mirrors.aliyun.com/rubygems/

gem sources --removed http://rubygems.org/

然后安装fpm,出现了如下错误;

root@ubuntu:~# gem install fpm

Fetching: arr-pm-0.0.10.gem (100%)

Successfully installed arr-pm-0.0.10

ERROR:  Error installing fpm:

         mustache requires Ruby version >= 1.9.3.

root@ubuntu:~# gem update --system

Latest version currently installed. Aborting.

 

解决方法是:我用的是第二种

1) 更新ruby

2 )安装旧版本的fpm

root@ubuntu:~# gem install fpm -v 1.4.0

安装完成之后可以测试了

2.1打包工具fpm介绍

FPM的github:https://github.com/jordansissel/fpm

FPM功能简单说就是将一种类型的包转换成另一种类型。
  1. 支持的源类型包
dir 将目录打包成所需要的类型,可以用于源码编译安装的软件包

rpm 对rpm进行转换

gem 对rubygem包进行转换

python 将python模块打包成相应的类型
  1. FPM的参数介绍
详细使用见fpm –help

常用参数

-s 指定源类型

-t 指定目标类型,即想要制作为什么包

-n 指定包的名字

-v 指定包的版本号

-C 指定打包的相对路径 Change directory to here before searching forfiles

-d 指定依赖于哪些包

-f 第二次打包时目录下如果有同名安装包存在,则覆盖它

-p 输出的安装包的目录,不想放在当前目录下就需要指定

--post-install 软件包安装完成之后所要运行的脚本;同--after-install

--pre-install 软件包安装完成之前所要运行的脚本;同--before-install

--post-uninstall 软件包卸载完成之后所要运行的脚本;同--after-remove

--pre-uninstall 软件包卸载完成之前所要运行的脚本;同--before-remove

2.2测试环境准备

然后进行测试,我测试的是定制nginx的安装包

 

root@ubuntu:~# fpm -s dir -t deb -n nginx -v 2.0 -d 'build-essential,libpcre3,libpcre3-dev,ruby,zlib1g-dev,openssl libssl-dev' --deb-no-default-config-files /usr/local/nginx/

把服务器的deb包及定制的nginx.deb包拷贝到创建的目录下

mkdir -p /usr/local/mydeb/

cp /var/cache/apt/archives/* /usr/local/mydeb/

cp /root/nginx_2.0_amd64.deb /usr/local/mydeb/

 

nginx的主配置内容

root@ubuntu:~# cat /usr/local/nginx/conf/nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  localhost;

        autoindex on;

        location / {

            root /usr/local/;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }

}

然后进行web访问是否成功

2.3创建索引及更新

此步骤,每加入一个deb的包都需要进行更新

apt-get -y install dpkg-dev

cd /usr/local/mydeb/

dpkg-scanpackages ./ /dev/null | gzip -1c > ./Packages.gz

第3章安装客户端

新开一台虚拟机进行测试,测试仓库

配置source源

root@ubuntu:~# cd /etc/apt/

root@ubuntu:/etc/apt# cat sources.list

deb http://192.168.56.18/mydeb/ /

然后进行更新,很重要

root@ubuntu:/etc/apt# apt-get update

Ign http://192.168.56.18  InRelease

Ign http://192.168.56.18  Release.gpg

Ign http://192.168.56.18  Release

Ign http://192.168.56.18  Packages/DiffIndex

Hit http://192.168.56.18  Packages

Ign http://192.168.56.18  Translation-en_US

Ign http://192.168.56.18  Translation-en

Reading package lists... Done

 

然后进行安装测试

root@ubuntu:/etc/apt# apt-get install nginx

注意:不用加-y参数

 

root@ubuntu:/etc/apt# apt-get install dpkg-dev

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following extra packages will be installed:

  build-essential fakeroot g++ g++-4.8 libalgorithm-diff-perl

  libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libfakeroot

  libfile-fcntllock-perl libstdc++-4.8-dev make

Suggested packages:

  debian-keyring g++-multilib g++-4.8-multilib gcc-4.8-doc libstdc++6-4.8-dbg

  libstdc++-4.8-doc make-doc

The following NEW packages will be installed:

  build-essential dpkg-dev fakeroot g++ g++-4.8 libalgorithm-diff-perl

  libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libfakeroot

  libfile-fcntllock-perl libstdc++-4.8-dev make

0 upgraded, 13 newly installed, 0 to remove and 3 not upgraded.

Need to get 20.4 MB of archives.

After this operation, 44.4 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

WARNING: The following packages cannot be authenticated!

  make libstdc++-4.8-dev g++-4.8 g++ libdpkg-perl dpkg-dev build-essential

  libfakeroot fakeroot libalgorithm-diff-perl libalgorithm-diff-xs-perl

  libalgorithm-merge-perl libfile-fcntllock-perl

Install these packages without verification? [y/N] y

Get:1 http://192.168.56.18/mydeb/  make 3.81-8.2ubuntu3 [119 kB]

Get:2 http://192.168.56.18/mydeb/  libstdc++-4.8-dev 4.8.4-2ubuntu1~14.04.3 [1,053 kB]

Get:3 http://192.168.56.18/mydeb/  g++-4.8 4.8.4-2ubuntu1~14.04.3 [18.1 MB]

Get:4 http://192.168.56.18/mydeb/  g++ 4:4.8.2-1ubuntu6 [1,490 B]

Get:5 http://192.168.56.18/mydeb/  libdpkg-perl 1.17.5ubuntu5.7 [179 kB]

Get:6 http://192.168.56.18/mydeb/  dpkg-dev 1.17.5ubuntu5.7 [726 kB]

Get:7 http://192.168.56.18/mydeb/  build-essential 11.6ubuntu6 [4,838 B]

Get:8 http://192.168.56.18/mydeb/  libfakeroot 1.20-3ubuntu2 [25.4 kB]

Get:9 http://192.168.56.18/mydeb/  fakeroot 1.20-3ubuntu2 [55.0 kB]

Get:10 http://192.168.56.18/mydeb/  libalgorithm-diff-perl 1.19.02-3 [50.0 kB]

Get:11 http://192.168.56.18/mydeb/  libalgorithm-diff-xs-perl 0.04-2build4 [12.6 kB]

Get:12 http://192.168.56.18/mydeb/  libalgorithm-merge-perl 0.08-2 [12.7 kB]

Get:13 http://192.168.56.18/mydeb/  libfile-fcntllock-perl 0.14-2build1 [15.9 kB]

Fetched 20.4 MB in 0s (33.5 MB/s)             

Selecting previously unselected package make.

(Reading database ... 71046 files and directories currently installed.)

Preparing to unpack .../make_3.81-8.2ubuntu3_amd64.deb ...

Unpacking make (3.81-8.2ubuntu3) ...

Selecting previously unselected package libstdc++-4.8-dev:amd64.

Preparing to unpack .../libstdc++-4.8-dev_4.8.4-2ubuntu1~14.04.3_amd64.deb ...

Unpacking libstdc++-4.8-dev:amd64 (4.8.4-2ubuntu1~14.04.3) ...

Selecting previously unselected package g++-4.8.

Preparing to unpack .../g++-4.8_4.8.4-2ubuntu1~14.04.3_amd64.deb ...

Unpacking g++-4.8 (4.8.4-2ubuntu1~14.04.3) ...

Selecting previously unselected package g++.

Preparing to unpack .../g++_4%3a4.8.2-1ubuntu6_amd64.deb ...

Unpacking g++ (4:4.8.2-1ubuntu6) ...

Selecting previously unselected package libdpkg-perl.

Preparing to unpack .../libdpkg-perl_1.17.5ubuntu5.7_all.deb ...

Unpacking libdpkg-perl (1.17.5ubuntu5.7) ...

Selecting previously unselected package dpkg-dev.

Preparing to unpack .../dpkg-dev_1.17.5ubuntu5.7_all.deb ...

Unpacking dpkg-dev (1.17.5ubuntu5.7) ...

Selecting previously unselected package build-essential.

Preparing to unpack .../build-essential_11.6ubuntu6_amd64.deb ...

Unpacking build-essential (11.6ubuntu6) ...

Selecting previously unselected package libfakeroot:amd64.

Preparing to unpack .../libfakeroot_1.20-3ubuntu2_amd64.deb ...

Unpacking libfakeroot:amd64 (1.20-3ubuntu2) ...

Selecting previously unselected package fakeroot.

Preparing to unpack .../fakeroot_1.20-3ubuntu2_amd64.deb ...

Unpacking fakeroot (1.20-3ubuntu2) ...

Selecting previously unselected package libalgorithm-diff-perl.

Preparing to unpack .../libalgorithm-diff-perl_1.19.02-3_all.deb ...

Unpacking libalgorithm-diff-perl (1.19.02-3) ...

Selecting previously unselected package libalgorithm-diff-xs-perl.

Preparing to unpack .../libalgorithm-diff-xs-perl_0.04-2build4_amd64.deb ...

Unpacking libalgorithm-diff-xs-perl (0.04-2build4) ...

Selecting previously unselected package libalgorithm-merge-perl.

Preparing to unpack .../libalgorithm-merge-perl_0.08-2_all.deb ...

Unpacking libalgorithm-merge-perl (0.08-2) ...

Selecting previously unselected package libfile-fcntllock-perl.

Preparing to unpack .../libfile-fcntllock-perl_0.14-2build1_amd64.deb ...

Unpacking libfile-fcntllock-perl (0.14-2build1) ...

Processing triggers for man-db (2.6.7.1-1ubuntu1) ...

Setting up make (3.81-8.2ubuntu3) ...

Setting up libstdc++-4.8-dev:amd64 (4.8.4-2ubuntu1~14.04.3) ...

Setting up g++-4.8 (4.8.4-2ubuntu1~14.04.3) ...

Setting up g++ (4:4.8.2-1ubuntu6) ...

update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode

Setting up libdpkg-perl (1.17.5ubuntu5.7) ...

Setting up dpkg-dev (1.17.5ubuntu5.7) ...

Setting up build-essential (11.6ubuntu6) ...

Setting up libfakeroot:amd64 (1.20-3ubuntu2) ...

Setting up fakeroot (1.20-3ubuntu2) ...

update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode

Setting up libalgorithm-diff-perl (1.19.02-3) ...

Setting up libalgorithm-diff-xs-perl (0.04-2build4) ...

Setting up libalgorithm-merge-perl (0.08-2) ...

Setting up libfile-fcntllock-perl (0.14-2build1) ...

root@ubuntu:/etc/apt# apt-get install -y dpkg-dev

Reading package lists... Done

Building dependency tree      

Reading state information... Done

dpkg-dev is already the newest version.

0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

第4章同步官网镜像源

由于软件源的体积比较大,大概需要50G左右,这里我只同步了一部分作为测试

第一步、安装apt-mirror工具

apt-get install apt-mirror

第二步、配置apt-mirror

root@ubuntu:~# cat /etc/apt/mirror.list

############# config ##################

#

# set base_path    /var/spool/apt-mirror

#

# set mirror_path  $base_path/mirror

# set skel_path    $base_path/skel

# set var_path     $base_path/var

# set cleanscript $var_path/clean.sh

# set defaultarch 

# set postmirror_script $var_path/postmirror.sh

# set run_postmirror 0

set nthreads     20

set _tilde 0

#

############# end config ##############

 

# Precise 64Bit Mirror

deb-amd64 http://cn.archive.ubuntu.com/ubuntu precise main restricted universe multiverse

deb-amd64 http://cn.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse

deb-amd64 http://cn.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse

deb-amd64 http://cn.archive.ubuntu.com/ubuntu precise-proposed main restricted universe multiverse

deb-amd64 http://cn.archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse

 

# Precise 32Bit Mirror

#deb-i386 http://cn.archive.ubuntu.com/ubuntu precise main restricted universe multiverse

#deb-i386 http://cn.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse

#deb-i386 http://cn.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse

#deb-i386 http://cn.archive.ubuntu.com/ubuntu precise-proposed main restricted universe multiverse

#deb-i386 http://cn.archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse

 

#deb-src http://cn.archive.ubuntu.com/ubuntu precise main restricted universe multiverse

#deb-src http://cn.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse

#deb-src http://cn.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse

#deb-src http://cn.archive.ubuntu.com/ubuntu precise-proposed main restricted universe multiverse

#deb-src http://cn.archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse

 

# Puppet mirror

deb-amd64 http://apt.puppetlabs.com/ precise main

#deb-i386 http://apt.puppetlabs.com/ precise main

 

clean http://cn.archive.ubuntu.com/ubuntu

#clean http://apt.puppetlabs.com/

第三步、同步镜像

apt-mirror

查看是否同步

root@ubuntu:~# du -sh /var/spool/apt-mirror/mirror/cn.archive.ubuntu.com/ubuntu/pool/

2.3G /var/spool/apt-mirror/mirror/cn.archive.ubuntu.com/ubuntu/pool/

此时正在同步
0
如无特殊说明,文章均为本站原创,转载请注明出处

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论

Hi,请填写昵称和邮箱!

取消评论
代码 贴图 加粗 链接 删除线 签到