基于nginx搭建yum服务器
2019-11-21 本文已影响0人
习惯了沉默乄
1、首先关闭防护墙或者设置规则通过且关闭selinux
停止firewall
[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Nov 21 03:49:01 master systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 21 03:49:02 master systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 21 03:56:35 master systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 21 03:56:36 master systemd[1]: Stopped firewalld - dynamic firewall daemon.
禁止firewall开机启动
[root@master ~]# systemctl disable firewalld
修改SELINUX=enforce行为SELINUX=disabled
[root@master ~]# sed -i 's/SELINUX=setenforce 0/SELINUX=disabled/' /etc/sysconfig/selinux
2、nginx-1.17.5版本(编译安装)-自定义安装路径
上传nginx安装包
[root@master ~]# rz -be
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nginx-1.17.5.tar.gz...
100% 1011 KB 1011 KB/sec 00:00:01 0 Errors
解压安装包
[root@master ~]# tar -zxvf nginx-1.17.5.tar.gz
安装编译需要的gcc和gcc-c++
yum install -y gcc gcc-c++
安装nginx依赖pcre-devel、openssl-devel、zlib-devel
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
生成Makefile文件
[root@master ~]# cd nginx-1.17.5
[root@master nginx-1.17.5]# pwd
/root/nginx-1.17.5
./configure --prefix=/root/nginx-1.17 --error-log-path=/root/nginx-1.17/logs/error.log --http-log-path=/root/nginx-1.17/logs/access.log --pid-path=/root/nginx-1.17/logs/nginx.pid --lock-path=/root/nginx-1.17/logs/nginx.lock --user= --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
编译源码并安装
[root@master nginx-1.17.5]# make && make isntall
开启nginx目录浏览
[root@master nginx-1.17]# pwd
/root/nginx-1.17
[root@master nginx-1.17]# vi conf/nginx.conf
添加如下内容:
location / {
root /root/nginx-1.17/html/pack/; #指定实际目录绝对路径;
autoindex on; #开启目录浏览功能;
autoindex_exact_size off; #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_localtime on; #开启以服务器本地时区显示文件修改日期!
}
修改nginx运行用户为root
user root;
检查nginx配置
[root@master nginx-1.17]# sbin/nginx -t
nginx: the configuration file /root/nginx-1.17/conf/nginx.conf syntax is ok
nginx: configuration file /root/nginx-1.17/conf/nginx.conf test is successful
启动nginx
[root@master nginx-1.17]# sbin/nginx
验证
yum仓库
3.创建仓库
创建目录
mkdir -p /root/nginx-1.17/html/pack/centos/7/os/x86_64/Packages/
mkdir -p /root/nginx-1.17/html/pack/centos/7/extras/x86_64/Packages/
mkdir -p /root/nginx-1.17/html/pack/centos/7/updates/x86_64/Packages/
mkdir -p /root/nginx-1.17/html/pack/centos/7/centosplus/x86_64/Packages/
创建/mnt/cdrom目录
mkdir -p mkdir /mnt/cdrom
挂载
[root@master nginx-1.17]# mount -t auto /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
查看
[root@master nginx-1.17]# cd /mnt/cdrom/
[root@master cdrom]# ll
total 694
-rw-rw-r--. 1 root root 14 Sep 9 15:06 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Sep 6 07:48 EFI
-rw-rw-r--. 1 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 1 root root 18009 Dec 9 2015 GPL
drwxr-xr-x. 3 root root 2048 Sep 9 14:07 images
drwxr-xr-x. 2 root root 2048 Sep 9 14:07 isolinux
drwxr-xr-x. 2 root root 2048 Sep 6 07:48 LiveOS
drwxrwxr-x. 2 root root 671744 Sep 11 14:41 Packages
drwxrwxr-x. 2 root root 4096 Sep 11 14:48 repodata
-rw-rw-r--. 1 root root 1690 Dec 9 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 Dec 9 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Sep 11 14:50 TRANS.TBL
复制rpm文件
[root@master Packages]# pwd
/mnt/cdrom/Packages
[root@master Packages]# cp * /root/nginx-1.17/html/pack/centos/7/os/x86_64/Packages/
使用createrepo创建仓库(生成repodata目录)
yum install -y createrepo
createrepo /root/nginx-1.17/html/pack/centos/7/os/x86_64/
createrepo /root/nginx-1.17/html/pack/centos/7/extras/x86_64/
createrepo /root/nginx-1.17/html/pack/centos/7/updates/x86_64/
createrepo /root/nginx-1.17/html/pack/centos/7/centosplus/x86_64/
客户端配置
[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.187.130/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=0
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://192.168.187.130/centos/$releasever/updates/$basearch/
enabled=1
gpgcheck=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://192.168.187.130/centos/$releasever/extras/$basearch/
enabled=1
gpgcheck=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://192.168.187.130/centos/$releasever/centosplus/$basearch/
enabled=1
gpgcheck=0
清理所有缓存
yum clean all
建立缓存
yum makecache
测试(安装openjdk)
[root@localhost ~]# yum search openjdk
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
============================================================ N/S matched: openjdk =============================================================
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without audio and video support
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8
java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11
icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser plug-in and Web Start implementation
Name and summary matches only, use "search all" for everything.
[root@localhost ~]# yum install -y java-1.8.0-openjdk.x86_64