centos 7服务器安装软件配置文件,CentOS7服务搭建----搭建yum(软件仓库)在线服务器...

闲话不多说,既然选择看,就是想学习,开整。

1,yum服务器搭建环境及软件需求

系统环境:CentOS7

所需软件:

A,createrepo:用于软件仓库元数据生成

B,nginx/httpd:任选一个,yum是一种web服务,需要web服务器

C,rsync:用于同步其他源镜像站

D,yum-utils:用于下载软件包但不安装

说明:

1)搭建yum镜像站的服务器连接互联网,能正常访问CentOS镜像站点,本例使用中科大的源:http://mirrors.ustc.edu.cn。

2)CentOS镜像站点需要支持 rsync 协议。

2,nginx软件安装

注:nginx本例选择编译安装,也可直接yum安装

nginx1.16.1稳定版 下载:http://nginx.org/download/nginx-1.16.1.tar.gz

1),依赖环境安装

命令:

yum -y install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool wget

c8d17b5b54d0

依赖软件安装

安装依赖软件

注:为了减少出现一下不可预知的事情,先把firewall和SELINUX关闭

关闭firewall并禁止随系统启动

命令:

systemctl stop firewalld #关闭firewall服务

systemctl disable firewalld #禁止firewall随机启动

systemctl status firewalld #查看firewall服务状态

c8d17b5b54d0

关闭firewall并禁止随系统启动

关闭selinux并永久关闭(禁止随机启动)

命令:

getenforce #查看selinux服务状态

setenforce 0 #关闭selinux服务(临时)

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux #将禁止随机启动写入selinux配置文件

c8d17b5b54d0

关闭selinux并永久关闭

下载nginx稳定版1.16.1

命令:

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

c8d17b5b54d0

下载nginx

解压nginx压缩包

命令:

tar -zxf nginx-1.16.1.tar.gz

c8d17b5b54d0

解压nginx软件包

编译nginx源码包

c8d17b5b54d0

编译安装

命令:(注:需要cd到nginx解压的目录中执行)

./configure \

--prefix=/opt/nginx \

--sbin-path=/opt/nginx/sbin/nginx \

--conf-path=/opt/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--with-http_ssl_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--with-pcre \

编译注解:

./configure:编译

--prefix=/opt/nginx:指定nginx安装目录,即将nginx安装到哪里去

--sbin-path=/opt/nginx/sbin/nginx:指定nginx的命令存放目录

--conf-path=/opt/nginx/nginx.conf:指定nginx配置文件及位置

--error-log-path=/var/log/nginx/error.log:指定nginx错误日志文件及位置

--http-log-path=/var/log/nginx/access.log:指定nginx日志文件和位置

--pid-path=/var/run/nginx/nginx.pid:指定nginx的pid文件和位置

--lock-path=/var/lock/nginx.lock:指定nginx的lock文件和位置

--with-http_ssl_module:启用http ssl模块

--with-http_stub_status_module:启用提供网站用户接入基本状态的信息模块

--with-http_gzip_static_module:启用gzip压缩模块

--with-pcre:强制使用PCRE库

c8d17b5b54d0

编译完成

编译过程无报错即可

安装nginx

命令:make & make instal

c8d17b5b54d0

make安装

安全起见,新增nginx用户及用户组,nginx服务使用nginx用户启动

命令:

groupadd nginx

useradd -g nginx nginx -s /bin/false

c8d17b5b54d0

新建nginx用户和组

修改nginx配置文件,指定启动运行nginx服务的用户和组

c8d17b5b54d0

nginxconf编辑

启动nginx测试

命令:

/opt/nginx/sbin/nginx

打开浏览器,输入服务器地址,访问到如下界面既nginx安装成功

c8d17b5b54d0

nginx服务

3,yum站点部署

安装所需工具

命令:

yum -y install rsync createrepo yum-utils

c8d17b5b54d0

工具安装

建立yum仓库存储位置

命令:

mkdir -p /data/repos/centos/7/{os,updates,extras,centosplus}/x86_64

c8d17b5b54d0

建立仓库目录

如果需要epel也镜像的话,建立epel目录

mkdir -p /data/repos/epel/7/x86_64

c8d17b5b54d0

目录树

同步中科大的centos7源

命令:

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /data/repos/centos/7/os/x86_64/

rsync

-avz --delete --exclude='repodata'

rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/

/data/repos/centos/7/updates/x86_64/

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /data/repos/centos/7/extras/x86_64/

rsync

-avz --delete --exclude='repodata'

rsync://mirrors.ustc.edu.cn/centos/7/centosplus/x86_64/

/data/repos/centos/7/centosplus/x86_64/

#同步gpgkey

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /data/repos/centos/

命令比较长,版面有点乱,看图简洁

c8d17b5b54d0

需要同步的目录

开始同步(过程会比较慢,主要取决于网络带宽了)

同步os部分

c8d17b5b54d0

同步os部分

同步update部分

c8d17b5b54d0

同步update部分

同步extras部分

c8d17b5b54d0

同步extras部分

同步contosplus部分

c8d17b5b54d0

同步centosplus部分

如果需要epel源的话,同步epel源(epel源的软件比centos的要多一些,更全面)

命令:

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /data/repos/epel/7/x86_64/

c8d17b5b54d0

同步epel源

#同步gpgkey

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-7 /data/repos/epel/

c8d17b5b54d0

同步gpgkey

使用createrepo创建仓库(生成repodata目录)

命令:

createrepo /data/repos/centos/7/os/x86_64/

createrepo /data/repos/centos/7/updates/x86_64/

createrepo /data/repos/centos/7/extras/x86_64/

createrepo /data/repos/centos/7/centosplus/x86_64/

c8d17b5b54d0

创建仓库

创建epel仓库

命令:

createrepo /data/repos/epel/7/x86_64/

c8d17b5b54d0

创建epel仓库

crontab自动同步脚本(实现crontab定时同步镜像与源站更新):

脚本内容就不放上来了,排版会很乱,如有需要,私信发送。

c8d17b5b54d0

同步脚本

完成以上工作,接下来配置nginx服务

找到nginx.conf文件配置如图:

c8d17b5b54d0

nginx配置

配置完成,测试配置文件及启动nginx服务

命令:

/opt/nginx/sbin/nginx -t

/opt/nginx/sbin/nginx

c8d17b5b54d0

测试nginx配置文件

c8d17b5b54d0

浏览器查看服务

4,yum客户端配置

修改 /etc/yum.repos.d/CentOS-Base.repo 文件

内容:

[os]

name=CentOS-$releasever - Base

baseurl=http://10.211.55.21/centos/$releasever/os/$basearch/

enabled=1

gpgcheck=0

#released updates

[updates]

name=CentOS-$releasever - Updates

baseurl=http://10.211.55.21/centos/$releasever/updates/$basearch/

enabled=1

gpgcheck=0

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

baseurl=http://10.211.55.21/centos/$releasever/extras/$basearch/

enabled=1

gpgcheck=0

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

baseurl=http://10.211.55.21/centos/$releasever/centosplus/$basearch/

enabled=1

gpgcheck=0

c8d17b5b54d0

yum源配置

修改 /etc/yum.repos.d/CentOS-Base.repo 文件(如果没有,需要新建)

内容:

[epel]

name=Extra Packages for Enterprise Linux 7 - $basearch

baseurl=http://10.211.55.21//epel/7/$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey=http://10.211.55.21/epel/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]

name=Extra Packages for Enterprise Linux 7 - $basearch - Debug

baseurl=http://10.211.55.21/epel/7/$basearch/debug

failovermethod=priority

enabled=0

gpgkey=http://10.211.55.21/epel/RPM-GPG-KEY-EPEL-7

gpgcheck=1

c8d17b5b54d0

epel源配置

清空yum缓存,新建缓存,查看yum源列表

命令:

yum clean all

yum makecache

yum repolist

c8d17b5b54d0

查看yum源

软件安装测试

c8d17b5b54d0

软件安装测试

至此,yum的在线镜像站搭建完毕,有好的意见或建议,可私信互相交流。

红校生-专注互联技术传道授业!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值