在项目开发部署过程中,一般都是内网环境,无法在线安装一些软件,这时候就需要我们配置离线的yum源。
centos版本:7.9.2009
制作yum源
一般会选择从阿里云:https://developer.aliyun.com/mirror/ 下载,速度比较快,资源也比较丰富,建议下载everything,虽然文件比较大。
也可以自行下载rpm包,然后上传到centos服务器,比如/data/rpm目录下,进入存放目录,执行以下命令:
这样,rpm包存放的目录就可以作为yum源目录使用了,也可以将这个目录打包后,放到其他地方使用。
安装yum源
使用iso文件制作yum源,需要先挂载
1 2 3 4
| mkdir -p /data/iso # 创建挂载目录
cd /data # 假设文件上传到/data目录下 mount -o loop -t iso9660 CentOS-7-x86_64-Everything-2009.iso /data/iso # 可以添加到/etc/rc.local中,避免重启失效
|
添加repo配置文件,并将之前的repo备份
1 2 3 4
| cd /etc/yum.repos.d/ mkdir bak mv *repo bak/ vim local.repo
|
至于local.repo中的内容则如下
1 2 3 4 5
| [iso] name=CentOS-7-x86_64-Everything-2009-iso baseurl=file:///data/iso gpgcheck=0 enabled=1
|
最后刷新一下yum缓存
1 2
| yum clean all yum makecache
|
如果是自行制作的yum源,则直接解压,并配置.repo文件即可
共享yum源
完成以上步骤,只能在本地使用离线yum仓库,如果希望局域网内的其他服务器也能使用该yum仓库,则需要通过http服务或者是ftp服务将yum仓库共享出去,这里以http方式进行示例
1 2 3
| yum install -y httpd systemctl enable httpd systemctl start httpd
|
如果无法通过yum方式安装,请依次下载以下包进行安装(centos7.0系统为例)
1 2 3 4 5 6 7 8
| rpm -ivh apr-1.4.8-3.el7.x86_64.rpm rpm -ivh apr-util-1.5.2-6.el7.x86_64.rpm rpm -ivh httpd-tools-2.4.6-31.el7.x86_64.rpm rpm -ivh mailcap-2.1.41-2.el7.noarch.rpm rpm -ivh httpd-2.4.6-31.el7.x86_64.rpm
systemctl enable httpd systemctl start httpd
|
httpd服务默认的端口是80,默认的资源路径是/var/www/html/,因此可以将/data/iso目录做个软连接到这个目录下:
1
| ln -s /data/iso /var/www/html/iso
|
然后就可以直接访问了
这样如果想在其它服务上使用该仓库,添加一下配置就可以了
1 2 3 4 5
| [http_iso] name=http_repo baseurl=http://192.168.141.21/iso gpgcheck=0 enabled=1
|
FAQ
ssh服务设置
vim /etc/ssh/sshd_config
1 2 3 4 5 6 7 8
| PermitRootLogin yes PasswordAuthentication yes ## 允许root远程密码登录
GSSAPIAuthentication no UseDNS no ## 解决ssh登录慢问题
ClientAliveInterval 600 ClientAliveCountMax 10 ## 修改ssh空闲时间,每隔600秒尝试连接一下客户端,尝试10次失败后断开连接
|
服务信息获取
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| function version_of_os(){ if [ -f "/etc/redhat-release" ]; then cat /etc/redhat-release | grep -oE '[0-9]+\.[0-9\.]+'; elif [ -f "/etc/kylin-release" ]; then cat /etc/kylin-release | grep -oE 'V[0-9]+'; elif [ -f "/etc/os-release" ]; then cat /etc/os-release | grep VERSION= | grep -oE '[0-9]+\.[0-9\.]+'; else echo "unkown version of os"; exit 1; fi }
os_version=$(version_of_os)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| function name_of_os(){ if [ -f "/etc/redhat-release" ]; then cat /etc/redhat-release | awk '{print $1}'; elif [ -f "/etc/kylin-release" ]; then cat /etc/kylin-release | awk '{print $1}'; elif [ -f "/etc/os-release" ]; then cat /etc/os-release | grep -E "^ID=" | awk -F'=' '{print $2}' | sed 's/\"//g' else echo "unkown name of os"; exit 1; fi }
os_name=$(name_of_os)
|
参考:
- https://blog.csdn.net/sinat_32724581/article/details/110119231
- https://blog.csdn.net/huangjin0507/article/details/51351807