前言:
其实,咱也不知道为啥写了这篇博客,咱就是想学一学suse,咱也不会,咱也只能学,只能查
[# 上个月部署公司新版本产品,使用的是ansible部署的,由于suse的一些特殊性(暂时还没有去研究ansible的zypper部署方式,最终是用python的方式部署的ansible),想起之前用过yum的缓存方式去创建本地源,就想着给suse也整一个,最近整完之后,在思考几个问题,如下:
1、'虽然机器是客户的,无法添加光驱,但是我可以把iso镜像里面的文件压缩一下,上传到服务器就可以了(iso里面的源已经压缩了,但是文件比较大,要3.7G,上传到客户环境不是狠方便,暂且搁置,毕竟需要啥上传啥挺好的,各有优缺点)'
2、'虽然解决了本地源的情况,目前还有一些问题,比如一些开源软件在centos上,可以利用repo源进行yum安装,不知道suse上是否可以利用zypper实现,还需要自己实践,毕竟这样配合本地源,才有本地源的意义,否则不如直接编译安装(如果有大佬知道,希望可以赐教)'
3、'虽然可以使用编译的方式去部署一些服务,但是从脚本编写的角度考虑,还是觉得rpm包安装的方式,写脚本更舒服一点把(来自菜鸡的错觉~~~)']
zypper-cache:~ # cat /etc/issue
Welcome to SUSE Linux Enterprise Server 12 SP3 (x86_64) - Kernel \r (\l).
服务端获取
添加源
1、# 添加网络源,之所以写repo文件,是因为zypper ar添加的repo源,没有gpgcheck=0这一项配置,安装软件的时候会报错,在加上还要写keeppackages=1,所以还是觉得写repo文件更舒服把,后期自己需要复制使用也狠方便
cat > /etc/zypp/repos.d/opensuse.repo << EOF
[opensuse-non-oss] # 以下都是suse12的国内源(中国科技大学镜像站)(国内源速度快)
name=opensuse-non-oss
enabled=1
autorefresh=0
baseurl=http://mirrors.ustc.edu.cn/opensuse/distribution/openSUSE-current/repo/non-oss
gpgcheck=0
keeppackages=1
[opensuse-oss]
name=opensuse-oss
enabled=1
autorefresh=0
baseurl=http://mirrors.ustc.edu.cn/opensuse/distribution/openSUSE-current/repo/oss
gpgcheck=0
keeppackages=1
[opensuse-update-non-oss]
name=opensuse-update-non-oss
enabled=1
autorefresh=0
baseurl=http://mirrors.ustc.edu.cn/opensuse/update/openSUSE-non-oss-current/
gpgcheck=0
keeppackages=1
[opensuse-update]
name=opensuse-update
enabled=1
autorefresh=0
baseurl=http://mirrors.ustc.edu.cn/opensuse/update/openSUSE-current/
gpgcheck=0
keeppackages=1
EOF
zypper-cache:~ # zypper refresh
2、# 添加本地源
zypper-cache:~ # zypper ar /root/suse12-dvd suse12-dvd # 本地源需要自己准备rpm目录
zypper-cache:~ # echo "gpgcheck=0" >> /etc/zypp/repos.d/suse12-dvd.repo
zypper-cache:~ # echo "keeppackages=1" >> /etc/zypp/repos.d/suse12-dvd.repo
刷新源
zypper-cache:~ # vim /etc/zypp/zypp.conf
packagesdir = /var/cache/zypp/packages
zypper-cache:~ # zypper refresh # 刷新一下源
zypper-cache:~ # zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.
# | Alias | Name | Enabled | GPG Check | Refresh
--+-------------------------+-------------------------+---------+-----------+--------
1 | SLES12-SP3-12.3-0 | SLES12-SP3-12.3-0 | No | ---- | ---- # 虚拟机安装的suse12,会自带镜像里面的源(需要光驱开机自启,生产环境不一定有,所以为了测试,吧这个源禁用了,可以不操作)
2 | opensuse-non-oss | opensuse-non-oss | Yes | ( ) No | No # repo文件没有问题的情况下,这些源是可以被 zypper lr 查看的
3 | opensuse-oss | opensuse-oss | Yes | ( ) No | No
4 | opensuse-update | opensuse-update | Yes | ( ) No | No
5 | opensuse-update-non-oss | opensuse-update-non-oss | Yes | ( ) No | No
6 | suse12-dvd | suse12-dvd | Yes | ( ) No | No
清除缓存
zypper-cache:~ # zypper clean
All repositories have been cleaned up.
安装软件
zypper-cache:~ # zypper in sl
获取rpm包
zypper-cache:~ # mkdir rpmcache/sl
zypper-cache:~ # find /var/cache/zypp/ -name "*.rpm" -exec mv {} /root/rpmcache/sl/ \;
zypper-cache:~ # scp -r rpmcache/sl/ 192.168.10.158:/root
客户端测试
linux-oz6w:~ # zypper ar /root/sl/ sl # 创建本地源
linux-oz6w:~ # echo "gpgcheck=0" >> /etc/zypp/repos.d/sl.repo
linux-oz6w:~ # zypper in sl # 成功安装即可
zypper --help
Repository Management: # zypper 后面可以带简写,比如lr ar ref 具体可以参考zypper --help
repos, lr List all defined repositories.
addrepo, ar Add a new repository.
removerepo, rr Remove specified repository.
renamerepo, nr Rename specified repository.
modifyrepo, mr Modify specified repository.
refresh, ref Refresh all repositories.
clean Clean local caches.
Software Management:
install, in Install packages.
remove, rm Remove packages.
verify, ve Verify integrity of package dependencies.
source-install, si Install source packages and their build
dependencies.
install-new-recommends, inr
Install newly added packages recommended
by installed packages.
Update Management:
update, up Update installed packages with newer versions.
list-updates, lu List available updates.
patch Install needed patches.
list-patches, lp List needed patches.
dist-upgrade, dup Perform a distribution upgrade.
patch-check, pchk Check for patches.