搭建YUM仓库与定制RPM包
#服务端
1.
#先保留平常下载下来的rpm包
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
这样当我们yum安装软件的时候,文件就是被保存下来:
/var/cache/yum/
#部署nginx,提供80端口服务
#安装依赖包
yum install -y pcre-devel openssl-devel rpm -qa pcre-devel openssl-devel
#下载nginx-10.0.2
mkdir -p /home/oldboy/tools cd /home/oldboy/tools wget -q http://nginx.org/download/nginx-1.10.2.tar.gz
#配置
./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
#编译
make && make install
#做软连接
ln -s /application/nginx-1.10.2 /application/nginx
#启动nginx进行测试
/applicaton/nginx/sbin/nginx lsof -i:80
#======================================
#==================================
#定制rpm包
####下载工具
yum install fpm-1.6.3-1.x86_64.rpm -y rpm -qa fpm
#将nginx打包
fpm -s dir -t rpm -n nginx -v 1.10.2 -d 'pcre-devel,openssl-devel' --post-install /server/scripts/nginx_rpm.sh -f /application/nginx-1.10.2/
#错误说明:
#1.[root@m01 application]# fpm -s dir -t rpm -n mysql -v 5.6.34 -f /application/mysql-5.6.34-linux-glibc2.5-x86_64 --post-install /server/scripts/mysql_rpm.sh All flags should be before the first argument (stray flags found: ["--post-install"] {:level=>:warn} Invalid package configuration: Cannot package the path './--post-install', does it exist? {:level=>:error}
解决方法: --post-install不能放到最后,选项的顺序最好不要随意变换
#这样。。将定制好的nginx-1.10.2-1.x86_64 放入下面yum仓库对应目录,客户端配置一下就可以进行yum安装了
#fpm相关命令说明
# fpm -h #查看命令的帮助,下面对常用的参数进行简单的说明
# -s:指定源类型
# -t:指定目标类型
# -n:指定名字
# -v:指定版本号
# -C:指定打包的相对路径
# -d:指定依赖于哪些包
# -f:第二次打包时目录下如果有同名安装包存在,则覆盖它
# -p:输出的安装包的目录,不想放在当前目录下就需要指定
# --post-install 软件包安装完成之后所要运行的脚本;同--after-install
# --pre-install 软件包安装完成之前所要运行的脚本;同--before-install
#=================================
#=================================
#安装createrepo软件(创建存储库)
yum -y install createrepo
#创建yum仓库目录
mkdir -p /application/nginx/html/yumcache/
#将保存好的rpm包放入/application/nginx/html/yumcache/
#初始化yum仓库
createrepo -pdo /application/nginx/html/yumcache/ /application/nginx/html/yumcache/
##当有新的rpm放到/application/nginx/html/yumcache里时,执行更新
createrepo --update /application/nginx/html/yumcache/
#修改nginx配置文件,让它默认访问浏览器找到html/yumcache/目录
cat >/application/nginx/conf/nginx.conf<<EOF worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html/yumcache; autoindex on; ##开启目录 index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } EOF
#检查语法重启nginx服务
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx
#访问ip可以查看yum仓库内容,下面会多个一个repodata/目录,是createrepo生成的。
#这是一个简单的yum仓库就搭建完成了,但是现在只有nginx的功能,以后可以增加更多的内容,放进来目录即可
==========================================
==========================================
##客户端部署
cd /etc/yum.repos.d/ mkdir yum_bak
#把之前的yum源移动到刚创建的目录做备用
mv *.repo yum_bak
#新建一个本地yum源文件
cat >/etc/yum.repos.d/myyum.repo<<EOF [myyum] name=Server baseurl=http://10.0.0.61 enabled=1 gpgcheck=0 EOF #清空之前的缓存 yum clean all
==================================================
==================================================
错误排查
Error: Package: nginx (myyum) Requires: libxslt-develpcre
#在提示类似错误的时候,是缺少某个依赖包,下来放到yum仓库即可。
#仓库执行update的命令;客户端执行yum clean all
#如果确认仓库有包,但是客户端没有,排查思路
#1、yum仓库createrepo --update /application/nginx/html/yumcache/
#2、客户端,yum clean all;
#3、如何还不可以,服务端删除生成的repodata目录,重新createrepo -pdo /application/nginx/html/yumcache/ /application/nginx/html/yumcache/,然后执行第二步;
#在客户机安装的时候总提示没有可用的安装包,最后发现是/etc/yum.repos.d/下的文件名后缀写错了。
==============================================================
在客户机安装的时候总是提示文件找不到,什么都不能安装
error was [Errno 2] Local file does not exist: /root/pdate/libiconv-devel-1.14-1.x86_64.rpm libxml2-devel-2.7.6-21.el6_8.1.x86_64: failed to retrieve libxml2-devel-2.7.6-21.el6_8.1.x86_64.rpm from m01 error was [Errno 2] Local file does not exist: /root/pdate/libxml2-devel-2.7.6-21.el6_8.1.x86_64.rpm libX11-devel-1.6.3-2.el6.x86_64: failed to retrieve libX11-devel-1.6.3-2.el6.x86_64.rpm from m01 error was [Errno 2] Local file does not exist: /root/pdate/libX11-devel-1.6.3-2.el6.x86_64.rpm libXt-1.1.4-6.1.el6.x86_64: failed to retrieve libXt-1.1.4-6.1.el6.x86_64.rpm from m01 error was [Errno 2] Local file does not exist: /root/pdate/libXt-1.1.4-6.1.el6.x86_64.rpm mhash-0.9.9.9-3.el6.x86_64: failed to retrieve mhash-0.9.9.9-3.el6.x86_64.rpm from m01 error was [Errno 2] Local file does not exist: /root/pdate/mhash-0.9.9.9-3.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64: failed to retrieve libmcrypt-2.5.8-9.el6.x86_64.rpm from m01 error was [Errno 2] Local file does not exist: /root/pdate/libmcrypt-2.5.8-9.el6.x86_64.rpm
解决方法:在服务端在/application/nginx/html/yumcache/下删除repodata 这个目录然后执行
createrepo --update /application/nginx/html/yumcache即可
rpm的常用命令
rpm -qpi your.rpm #查看rpm包信息 rpm -qpl your.rpm #查看rpm包内容 rpm -qpR your.rpm #查看rpm包的依赖 rpm -qp --scripts your.rpm #查看rpm包要执行的脚本,存的不是文件了。 rpm -ivh your.rpm #安装rpm包