在centos中搭建基於nginx的apt源服務器,整合yum源和apt源在一台服務器


1、首先關閉防護牆或者設置規則通過且關閉selinux

2、nginx-1.14.2版本(編譯安裝)-自定義安裝路徑

3、開啟nginx目錄瀏覽

以上步驟請參考前文:https://www.cnblogs.com/omgasw/p/10194698.html

4、調整分區大小

把/dev/centos/home下的50G變為8G

1.增加

1.1去掉掛載

df –Th #查看分區信息

umount /home

1.2減小home,

lvreduce -L 8G /dev/centos/home    或 -42G

1.3擴容/dev/centos/root

lvextend -L 42G /dev/centos/root

xfs_growfs /dev/centos/root

2.減小

xfs是不支持減少的,但無法使用resize2fs,會報錯:Couldn't find valid filesystem superblock。意思就是減少后的邏輯分區需要通過mkfs.xfs命令重新格式化一下

5、使用Alien將RPM轉換成DEB

1.安裝Alien及其依賴包

要安裝alien到CentOS/RHEL 7中,你需要啟用EPEL和Nux Dextop倉庫

yum install epel-release -y

啟用Nux Dextop倉庫的包的當前最新版本是0.5(2015年8月10日發布),在安裝之前你可以查看http://li.nux.ro/download/nux/dextop/el7/x86_64/上是否有更新的版本

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
yum update && yum install alien -y

2.將deb轉換成rpm包

wget(例:dateutils_0.3.1-1.1_amd64.deb)

alien dateutils_0.3.1-1.1_amd64.deb

 

在Linux中將deb轉換成rpm

重要:(請注意alien是怎樣來增加目標包的次版本號的,如果你想要無視該行為,請添加-keep-version標識)

6、創重新構建RPM包

如果我們嘗試馬上安裝該包,我們將碰到些許問題:

rpm -ivh dateutils-0.3.1-2.1.x86_64.rpm

 

要解決該問題,我們需要啟用epel-testing倉庫,然后安裝rpmbuild工具來編輯該包的配置以重建包:

yum --enablerepo=epel-testing install rpmrebuild -y

然后運行

rpmrebuild -pe dateutils-0.3.1-2.1.x86_64.rpm

它會打開你的默認文本編輯器,請轉到%files並刪除涉及到錯誤信息中提到的目錄的行,然后保存文件並退出:

 

退出該文件后,將提示你繼續去重構,如果你選擇“Y”,該文件會重構到指定的目錄(與當前工作目錄不同):

 

7、apt-mirror配置

1.安裝apt-mirror

rpm –ivh apt-mirror_0.5.4-2.noarch.rpm

2.修改apt-mirror配置文件

在修改配置文件之前,我們首先要確定自己系統的版本,sudo lsb_release -a

#sudo lsb_release -a

    No LSB modules are available.

    Distributor ID: Ubuntu

    Description:    Ubuntu 16.04 LTS

    Release:    16.04

    Codename:   xenial

Codename代號的意思,16.04代號xenial,所以我們接下來的配置文件跟xenial有關,當然14.04代號是trusty,一樣的操作

打開清華大學開源鏡像

進入dists目錄,在目錄下找到跟系統代號相關問文件夾,一般是5個,將下面規則文本復制出來,把加粗部分替換成相應的5個文件目錄名。進入這5個目錄,里面有4個跟源有關的目錄(by-hash除外),目錄名與下面斜體部分比較,如果不一樣請修改

# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 預發布軟件源,不建議啟用

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

然后

vim /etc/apt/mirror.list

參考以下配置文件:

清空原有的配置文件,修改以下配置文件相應代號部分即可,如果想添加多個版本的源,可以依次在下面增加相應的規則(就是增加對應代號的源地址)

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

# 以下注釋的內容都是默認配置,如果需要自定義,取消注釋修改即可

set base_path /yryun/ubuntu

# 鏡像文件下載地址

# set mirror_path $base_path/mirror

# 臨時索引下載文件目錄,也就是存放軟件倉庫的dists目錄下的文件(默認即可)

# set skel_path $base_path/skel

# 配置日志(默認即可)

# set var_path $base_path/var

# clean腳本位置

# set cleanscript $var_path/clean.sh

# 架構配置,i386/amd64,默認的話會下載跟本機相同的架構的源

set defaultarch amd64

# set postmirror_script $var_path/postmirror.sh

set run_postmirror 0

#如果報/bin/sh: 0: can't open /media/newsmy/ubuntu1204mirror/var/postmirror.sh,把set run_postmirror 0即可

# 下載線程數

set nthreads 20

set _tilde 0

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

# 清華大學開源
# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋

# ubuntu 18.04 LTS
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# ubuntu 16.04 LTS
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# ubuntu 14.04 LTS
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse

# debian 9
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free

clean http://mirrors.tuna.tsinghua.edu.cn/ubuntu
clean http://mirrors.tuna.tsinghua.edu.cn/debian

3.指向鏡像路徑

ln –s /yryun/ubuntu/mirror/mirrors.tuna.tsinghua.edu.cn/ubuntu/ /usr/local/nginx/html/pack/ubuntu
ln –s /yryun/ubuntu/mirror/mirrors.tuna.tsinghua.edu.cn/debian/ /usr/local/nginx/html/pack/debian

4.開始同步

apt-mirror

等待很長時間(該鏡像差不多100G左右,具體時間看網絡環境)

注意:當apt-mirror 被意外中斷時,只需要重新運行即可,apt-mirror支持斷點續存;另外,意外關閉,需要在/var/spool/apt-mirror/var目錄下面刪除 apt-mirror.lock文件【 sudo rm apt-mirror.lock 】,之后執行apt-mirror重新啟動

5.創建自動同步

vim /etc/crontab
0  5  *  *  2  root  /usr/bin/apt-mirror >/dev/null 2>&1

8、客戶端配置

1.編輯/etc/apt/source.list,選擇相應的版本

# ubuntu 18.04 LTS
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ bionic main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ bionic-security main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ bionic-backports main restricted universe multiverse
# ubuntu 16.04 LTS
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ xenial main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ xenial-security main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ xenial-backports main restricted universe multiverse
# ubuntu 14.04 LTS
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ trusty main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ trusty-security main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb [arch=amd64] http://mirrors.yryun.com/ubuntu/ trusty-backports main restricted universe multiverse
# debian 9
deb [arch=amd64] http://mirrors.yryun.com/debian/ stretch main contrib non-free
deb [arch=amd64] http://mirrors.yryun.com/debian/ stretch-updates main contrib non-free
deb [arch=amd64] http://mirrors.yryun.com/debian/ stretch-backports main contrib non-free

2.更新apt-get源

sudo apt update

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM