柴少的官方网站 技术在学习中进步,水平在分享中升华

Centos 6.4 用光盘yum源做成集群yum源服务器

        上篇文章说到了,在不能上网的情况下用光盘搭建本地yum源,但是当我们有一群服务器也不能上网,这时候要安装东西如果每台服务器都挂载一个光盘的话那就恶心死了。

       

这时候我们有两种选择,一种是搭建简易版的集群本地yum源,另一种就是搭建真正的跟公网yum源做同步的本地yum源服务器。这时候就要看我们的需求了,如果我们这群服务器就是安装完某一个环境,比如说就是都搭建完lnmp环境就不会再安装其他软件了(就如我上家公司,我们公司有公网的APP,其中的一个大客户想要一个内部局域网使用的环境用于公司内部办公用,他们那边服务器不能上外网,如果想连通外网就要申请很麻烦,环境部署完毕以后也不会装其他软件了。),这时候我们就可以考虑简易版的本地yum源服务器。

另一种情况就是我们的服务器集群庞大,偶尔不定期的可能要装一些其他的东西,这时候就要考虑高大上的跟公网做同步的本地yum源方案了。

说了那么多废话,我们这里先结合上一篇光盘yum源,做一个简易版的集群yum源服务器。

我的系统环境还是Centos 6.4 64位的操作系统,现在是一个崭新的环境了哈,就让他能上外网吧,为啥子要上网呢,是我加入了一些自己的想法。

我们的yum源服务器端位192.168.1.105,客户端为192.168.1.109。

一、 服务端操作:

1. 安装nginx作为HTTP服务器共享系统光盘内的文件(跟ftp共享差不多)

[root@test1 tools]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
[root@test1 tools]# tar zxf pcre-8.35.tar.gz   #安装pcre使nginx支持正则
[root@test1 tools]# cd pcre-8.35

[root@test1 pcre-8.35]# ./configure  --prefix=/usr/local/pcre && make && make install

[root@test1 tools]# wget nginx.org/download/nginx-1.2.9.tar.gz #下载编译安装包

[root@test1 tools]# tar zxf nginx-1.2.9.tar.gz

[root@test1 tools]# cd nginx-1.2.9

[root@test1 nginx-1.2.9]#./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/tools/pcre-8.35  #如果是搭建web环境就不能这样安装了,编译的时候是要加参数的,不过我们这里就是要让其起到一个共享的功能。

[root@test1 nginx-1.2.9]# make && make install

2.2 创建站点目录并配置nginx文件

[root@test1 nginx-1.2.9]# mkdir /data/yum_repo/ #创建站点目录

[root@test1 /]# mkdir /data/yum_repo/Centos-6 #创建以不同linux版本命令的目录

注:如果想让yum服务器为不同版本的linux服务,可在站点目录下面创建不同版本的目录,然后将光盘内的所有的文件拷贝到对应的目录便可。

[root@test1 yum_repo]# vim /usr/local/nginx/conf/nginx.conf #修改为下面的部分

server {
listen       80;    #默认端口80端口
server_name 192.168.1.105;   #网站名称192.168.1.105
index index.html index.htm index.php;
root  /data/yum_repo/;   #自定义站点目录为/data/yum_repo
#error_page 502 = /502.html;
autoindex on;    #开启nginx的目录浏览功能
autoindex_exact_size off; #文件大小从kb开始显示
autoindex_localtime on; #显示文件的修改时间为服务器的本地时间

location ~ .*\.(php|php5)?$ {
#fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ {
expires      30d;
}
location ~ .*\.(js|css)?$ {
expires      12h;
}
}
log_format  access  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for';
access_log  /data/logs/access.log  access;

[root@test1 nginx-1.2.9]# /usr/local/nginx/sbin/nginx -t #检测一下是否配置成功

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #这是表示成功的意思。

[root@test1 nginx-1.2.9]# /usr/local/nginx/sbin/nginx #启动nginx服务

下面是页面效果图:

yumweb.png

二、客户端的配置

2.1 客户端的yum配置文件修改

[root@localhost ~]# cd /etc/yum.repos.d/  #进入客户端的yum配置文件目录
[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak20150308 #操作前备份

[root@localhost yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-$releasever – Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://192.168.1.105/Centos-6
gpgcheck=1
enable=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever – Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://192.168.1.105/Centos-6
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://192.168.1.105/Centos-6
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#基本上就是将mirrorlist注释掉,然后把baseurl的链接地址换一下。[centosplus][contrib]不用改,因为enabled=0,表示模块没有启用。

2.2 测试

[root@localhost yum.repos.d]# ping 202.106.0.20  #我把网关去掉了现在网上不去了
connect: Network is unreachable
[root@localhost yum.repos.d]# ping 192.168.1.105  #能ping通内网yum源服务器
PING 192.168.1.105 (192.168.1.105) 56(84) bytes of data.
64 bytes from 192.168.1.105: icmp_seq=1 ttl=64 time=0.805 ms
^C
— 192.168.1.105 ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 556ms
rtt min/avg/max/mdev = 0.805/0.805/0.805/0.000 ms

我们下载个时间服务器试一试,网上的帖子不管成功不成功都会搞得成功一样,其实真实环境哪有那么理想化,你看我就没成功,其实这些包是有的,只不过版本有些细微的差别,所以不成功。

xg.png

2.3 巧用yum缓存功能

[root@test1 yum_repo]# vim /etc/yum.conf

keepcache=1  #这里变为1,以后yum安装软件后,软件也会保留到目录/var/cache/yum/x86_64

现在我们在192.168.1.105上面yum下载一下ntp服务:

[root@test1 packages]# yum install ntp -y

[root@test1 packages]# cd /var/cache/yum/x86_64/6/updates/packages/
[root@test1 packages]# ll  #看到没我们yum的关联rpm包找到了
total 672
-rw-r–r–. 1 root root 607020 Dec 20 11:01 ntp-4.2.6p5-2.el6.centos.x86_64.rpm
-rw-r–r–. 1 root root  76952 Dec 20 11:01 ntpdate-4.2.6p5-2.el6.centos.x86_64.rpm

[root@test1 packages]# cp * /data/yum_repo/Centos-6/Packages/ #将所有的关联包拷贝到对应的站点目录中去。

现在我们回到客户端继续测试:

xg2.png

第一次失败了,但是我们在yum服务器端稍微操作了一下,客户端也实现了在不能上网的情况下可以yum安装软件了。

下面是个人的一些见解:

1.思想是活的,照搬照抄是不行的,拿这篇文件举例,你去网上找前半部分应该会找到类似的,但是这最后的第三部分,网上应该找不到,是我从实际的工作中,思考出来的一个简单的小方案。可能在大规模的集群场景中并不适用,但是在某些场景中还是启动简化快速部署的作用的。

2.工具是给人用的,灵活运用就能给我们带来便捷,效率。

3. 第三句话是留给自己的,关于第三部要灵活运用,基本上搞一个可以的机器单独当yum源就行了,如果版本相同客户端不闲的蛋疼update的话,基本在yum服务器上面yum一下然后把软件包拷贝到对应的站点目录中就行了。如果服务器已经yum过软件包了,而客户端yum软件包版本失败,可以试着在服务器端yum remove 软件名称,然后重新yum,然后把软件包拷贝到对应的站点目录中去。

作者:忙碌的柴少 分类:yum源服务 浏览:3471 评论:0
留言列表
发表评论
来宾的头像