linux搭建yum倉庫


Linux9期基礎-day25

搭建yum倉庫

# 關閉防火牆和selinux
[root@qls yum.repos.d]# systemctl stop firewalld
[root@qls yum.repos.d]# setenforce 0

## 搭建yum倉庫的三種方式
# 方案一:vsftpd服務實現yum倉庫 (ftp://)
# 1.安裝vsftpd
[root@qls yum.repos.d]# yum install -y vsftpd
# 2.啟動服務
[root@qls yum.repos.d]# systemctl start vsftpd
# 3.檢查端口
[root@qls yum.repos.d]# netstat -lntup|grep 21
tcp6       0      0 :::21                   :::*                    LISTEN      8433/vsftpd 
# 4.安裝創建yum倉庫的命令
[root@qls pub]# yum install -y createrepo
# 5.制作成yum倉庫
[root@qls pub]# createrepo /var/ftp/pub/base/
# 6.在客戶機上配置yum倉庫
[root@qls yum.repos.d]# vi zls_vsftpd.repo 
[zls_vsftpd]
name='This is zls's vsftpd repository'
baseurl=ftp://10.0.0.150/pub/base/
gpgcheck=0
enabled=1

# 方案二:本地,掛載光盤鏡像 (file://)
# 1.將光盤插入光驅

1587000990081

# 2.掛載光驅
[root@qls pub]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
# 3.創建yum倉庫
[root@qls pub]# createrepo /var/ftp/pub/zabbix/
# 4.配置yum源
[root@qls yum_repo]# vi /etc/yum.repos.d/zls_local.repo
[zls_local]
name=123
baseurl=file:///opt/yum_repo/
gpgcheck=0
enabled=1

# 方案三:nginx服務搭建yum倉庫
# 1.安裝nginx
[root@qls conf.d]# yum install -y nginx
# 2.刪除nginx的conf.d下默認配置文件
[root@qls conf.d]# rm -fr /etc/nginx/conf.d/*
# 3.配置nginx配置文件
[root@qls conf.d]# vim /etc/nginx/conf.d/yum.conf
server {
        listen 80;
        server_name www.drz.com;
        root /kpw_dsb;
        autoindex on;
}
# 4.創建站點目錄
[root@qls conf.d]# mkdir /kpw_dsb
# 5.啟動nginx服務
[root@qls kpw_dsb]# systemctl start nginx
# 6.配置域名解析
按 windows + r 打開運行,輸入 'drivers'

1587002458268

1587002478270

1587002525146

1587002546499

# 7.創建yum倉庫
[root@qls nginx]# createrepo /kpw_dsb
# 8.手寫repo文件
[root@qls yum.repos.d]# vi zls_nginx.repo
[zls_nginx]
name=456
baseurl=http://www.drz.com/
gpgcheck=0
enabled=1
# 9.在客戶機配置域名解析
[root@qls yum.repos.d]# vi /etc/hosts
10.0.0.150 www.drz.com

自制RPM包

## 源碼安裝nginx
# 0.安裝依賴
[root@qls nginx-1.16.1]# yum install -y gcc gcc-c++ glibc zlib-devel pcre-devel openssl-devel
# 1.下載nginx源碼包
[root@qls ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# 2.解壓
[root@qls ~]# tar xf nginx-1.16.1.tar.gz 
[root@qls ~]# cd nginx-1.16.1
# 3.生成
[root@qls ~]# mkdir /app
[root@qls nginx-1.16.1]# useradd nginx -s /sbin/nologin -M
[root@qls nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=nginx --group=nginx
# 4.編譯
[root@qls nginx-1.16.1]# make
# 5.安裝
[root@qls nginx-1.16.1]# make install
# 6.檢測配置文件有沒有語法錯誤
[root@qls sbin]# /app/nginx-1.16.1/sbin/nginx -t
nginx: the configuration file /app/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.1/conf/nginx.conf test is successful
# 7.啟動nginx
[root@qls sbin]# /app/nginx-1.16.1/sbin/nginx
# 8.檢測80端口
[root@qls sbin]# netstat -lntup|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13468/nginx: master
# 9.做軟連接
[root@qls nginx-1.16.1]# ln -s /app/nginx-1.16.1 /app/nginx

## 自定義
# 修改默認頁面
[root@qls html]# vim /app/nginx-1.16.1/html/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>歡迎來到曾老濕的nginx頁面</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>歡迎來到曾老濕nginx的web頁面</h1>
<a href="http://www.driverzeng.com">我的博客地址</a>.<br/>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>


## 制作rpm包
[root@qls ~]# mkdir fpm
[root@qls ~]# mv fpm-1.3.3.x86_64.tar.gz fpm
[root@qls fpm]# cd /root/fpm/

# 1. 解壓
[root@qls fpm]# tar xf fpm-1.3.3.x86_64.tar.gz 
# 2.安裝ruby
[root@qls fpm]# yum -y install ruby rubygems ruby-devel rpm-build
# 3.查看gem的源
[root@qls fpm]# gem sources --list
*** CURRENT SOURCES ***

https://rubygems.org/

# 4.更換阿里雲的源 先移除國外源
[root@qls fpm]# gem sources --remove https://rubygems.org/

# 5.更換阿里雲的源, 添加阿里雲的源
[root@qls fpm]# gem sources -a https://mirrors.aliyun.com/rubygems/

# 6.使用gem命令安裝當前目錄下所有的.gem文件
[root@qls fpm]# gem install *.gem
# 7.寫出安裝rpm之后要執行的腳本
[root@qls ~]# vim /root/nginx.sh
#!/bin/bash
useradd nginx -s /sbin/nologin -M
ln -s /app/nginx-1.16.1 /app/nginx
# 8.使用fpm打包
[root@qls fpm]# fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'zlib-devel,gcc,gcc-c++,glibc,pcre-devel,openssl-devel' --post-install /root/nginx.sh -f /app/nginx-1.16.1/

fpm:打rpm包命令
-s:dir     # 打目錄
-t:rpm     # 把目錄打成rpm包
-n:nginx   # 軟件名字叫nginx
-v:1.16.1  # 軟件的版本號
-d:        # 指定nginx的依賴包
-f:        # 指定要達成rpm包的目錄路徑
--post-install # 指定rpm包安裝完成之后要執行的腳本
--pre-install  # 指定rpm包安裝之前,要執行的腳本

1587012215576

yum install -y rpm-build
fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'zlib-devel,pcre-devel,openssl-devel' --post-install /root/nginx.sh -f /app/nginx-1.16.1/

-d zlib-devel,gcc,gcc-c++,glibc,pcre-devel,openssl-devel
## 安裝nginx的rpm包,需要以上依賴。

同步中科大源

# 安裝rsync同步工具
[root@qls nginx2]# yum install -y rsync

# 同步
rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/centos ./
rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/nginx ./
rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/epel ./

# 拉全部
rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/ ./


免責聲明!

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



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