1. 程式人生 > 實用技巧 >第二十章 搭建本地yum倉庫,倉庫共享給其他主機

第二十章 搭建本地yum倉庫,倉庫共享給其他主機



搭建本地倉庫


1. yum倉庫, mount /dev/cdrom 將映象光碟進行掛載, /mnt

[root@lxy ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@lxy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 2.0G 46G 5% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
[root@lxy ~]# ll /mnt/Packages/*.rpm |wc -l
4021

2.禁用其它yum源倉庫(連線外網的yum倉庫)

[root@lxy ~]# gzip /etc/yum.repos.d/*
[root@lxy ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 601 Dec 25 11:22 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 254 Dec 25 11:48 epel.repo.gz
[root@lxy ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0

3.書寫yum倉庫的配置檔案

file:// #本地的地址

ftp:// #網路檔案傳輸

http:// https:// #網路協議


[root@lxy ~]# cat /etc/yum.repos.d/local.repo
[lxy]#名稱
name = this is local repo #備註資訊
baseurl = file:///mnt #路徑在哪裡
enabled = 1 #啟用倉庫
gpgcheck = 0 #是否檢查合法性

4.清空快取

[root@lxy ~]# yum clean all

5.檢查倉庫是否可用
[root@lxy ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
lxy | 3.6 kB 00:00:00
(1/2): lxy/group_gz | 166 kB 00:00:00
(2/2): lxy/primary_db | 3.1 MB 00:00:00
repo id repo name status
lxy this is local repo 4,021
repolist: 4,021


將本地倉庫共享給其它主機

1.安裝vsftpd服務

[root@lxy ~]# yum  install  -y  vsftpd

#啟動服務
[root@lxy ~]# systemctl   start  vsftpd
#檢視服務狀態
[root@lxy ~]# systemctl   status  vsftpd

2.關閉防火牆

[root@lxy ~]# systemctl  stop  firewalld
[root@lxy ~]# systemctl  disable  firewalld

3.關閉selinux安全防護用

[root@lxy ~]# getenforce 
Enforcing
[root@lxy ~]# setenforce 
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@lxy ~]# setenforce 0
[root@lxy ~]# getenforce 
Permissive
#永久關閉
[root@lxy ~]# sed  -i  '7s#enforcing#disabled#g'  /etc/selinux/config


4.瀏覽器訪問測試

ftp://10.0.0.90/
#客戶端測試
[root@client ~]# curl  ftp://10.0.0.90
drwxr-xr-x    2 0        0               6 Oct 30  2018 pub

5. 建立一個yum源倉庫  

[root@lxy ~]# mkdir  /var/ftp/local
[root@lxy ~]# ll  /var/ftp/
total 0
drwxr-xr-x. 2 root root 6 Dec 26 10:46 local

6. 將rpm包拷貝到倉庫目錄中

[root@lxy ~]# cp  -rp  /mnt/Packages/*  /var/ftp/local/

7.讓這個目錄變成yum倉庫
[root@lxy ~]# yum  install  -y  createrepo

[root@lxy ~]# createrepo   /var/ftp/local/
Spawning worker 0 with 4021 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

8.書寫配置檔案

[root@lxy ~]# cat /etc/yum.repos.d/local.repo
[lxy]
name = this is local  repo
baseurl = ftp://10.0.0.90/local
enabled = 1
gpgcheck = 0

9. 下載測試  

[root@lxy ~]#  yum  clean  all

[root@lxy ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
lxy                                                                                                           | 2.9 kB  00:00:00     
lxy/primary_db                                                                                                | 3.2 MB  00:00:00     
repo id                                                  repo name                                                             status
lxy                                                      this is local  repo                                                   4,021
repolist: 4,021

10.讓其它的主機也使用這個倉庫


[root@client ~]# gzip  /etc/yum.repos.d/*
[root@client ~]# vi  /etc/yum.repos.d/local.repo
[root@client ~]# cat /etc/yum.repos.d/local.repo
[lxy]
name = this is local  repo
baseurl = ftp://10.0.0.90/local
enabled = 1
gpgcheck = 0
[root@client ~]# yum  clean  all
Loaded plugins: fastestmirror
Cleaning repos: lxy
Cleaning up list of fastest mirrors
Other repos take up 105 M of disk space (use --verbose for details)
[root@client ~]# yum  repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
lxy                                                                                                           | 2.9 kB  00:00:00     
lxy/primary_db                                                                                                | 3.2 MB  00:00:00     
repo id                                                  repo name                                                             status
lxy                                                      this is local  repo                                                   4,021
repolist: 4,021

編譯安裝


Nginx

準備環境

[root@client ~]# rm -rf /etc/yum.repos.d/*

[root@client ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 77411 0 --:--:-- --:--:-- --:--:-- 78843
[root@client ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 664 100 664 0 0 23762 0 --:--:-- --:--:-- --:--:-- 24592
[root@client ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2523 Dec 26 19:41 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Dec 26 19:41 epel.repo


1. 下載Nginx的原始碼包
[root@client ~]# yum install -y wget
[root@client ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

2.解壓

[root@client ~]# tar xf nginx-1.16.1.tar.gz
[root@client ~]# ll
total 1016
-rw-------. 1 root root 1429 Nov 26 20:28 anaconda-ks.cfg
drwxr-xr-x. 8 1001 1001 158 Aug 13 20:51 nginx-1.16.1

3.進入目錄,開始預編譯,生成makefile檔案

[root@client nginx-1.16.1]# ./configure --prefix=/application/nginx-1.16.1 --with-http_ssl_module

#第一步報錯
[root@client nginx-1.16.1]# ./configure --prefix=/application/nginx-1.16.1 --with-http_ssl_module
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

[root@client nginx-1.16.1]# yum install -y gcc #按照報錯進行安裝gcc軟體

#重新進行預編譯
[root@client nginx-1.16.1]# ./configure --prefix=/application/nginx-1.16.1 --with-http_ssl_module

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

解決這個報錯:

[root@client nginx-1.16.1]# yum install -y openssl openssl-devel



#重新進行預編譯
[root@client nginx-1.16.1]# ./configure --prefix=/application/nginx-1.16.1 --with-http_ssl_module

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

#解決報錯

[root@client nginx-1.16.1]# yum install -y pcre pcre-devel

[root@client nginx-1.16.1]# echo $?
0

[root@client nginx-1.16.1]# ll
total 756
drwxr-xr-x. 6 1001 1001 4096 Dec 26 19:48 auto
-rw-r--r--. 1 1001 1001 296463 Aug 13 20:51 CHANGES
-rw-r--r--. 1 1001 1001 452171 Aug 13 20:51 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Dec 26 19:48 conf
-rwxr-xr-x. 1 1001 1001 2502 Aug 13 20:51 configure
drwxr-xr-x. 4 1001 1001 72 Dec 26 19:48 contrib
drwxr-xr-x. 2 1001 1001 40 Dec 26 19:48 html
-rw-r--r--. 1 1001 1001 1397 Aug 13 20:51 LICENSE
-rw-r--r--. 1 root root 412 Dec 26 20:01 Makefile

4.進行編譯,根據makefile檔案進行編譯

[root@client nginx-1.16.1]# make

5.將編譯的結果拷貝到預編譯的指定的程式目錄

[root@client nginx-1.16.1]# make install

[root@client nginx-1.16.1]# ll /application/nginx-1.16.1/
total 4
drwxr-xr-x. 2 root root 4096 Dec 26 20:10 conf
drwxr-xr-x. 2 root root 40 Dec 26 20:10 html
drwxr-xr-x. 2 root root 6 Dec 26 20:10 logs
drwxr-xr-x. 2 root root 19 Dec 26 20:10 sbin

6. 做個軟連線

[root@client nginx-1.16.1]# ln -s /application/nginx-1.16.1/ /application/nginx

7.啟動nginx

[root@client nginx-1.16.1]# /application/nginx/sbin/nginx
[root@client nginx-1.16.1]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12139/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6871/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6996/master
tcp6 0 0 :::22 :::* LISTEN 6871/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6996/master

8.瀏覽器訪問測試

[root@client nginx-1.16.1]# systemctl stop firewalld
[root@client nginx-1.16.1]# setenforce 0

http://10.0.0.80/