无网络内部yum源仓库


状态:公司内部服务器为内网客户端,Centos7系统,且无法与外网连接。需要部署对应的LANMP环境及其它软件

解决办法

利用网络云服务器,例如利用阿里云的yum源仓库,下载对应软件及关联软件。

在客户机上面自建yum仓库,然后通过yum安装,解决依赖问题

下载软件
[root@Centos7 tmp]# mkdir -pv /app/text

[root@Centos7 text]# ll /app/text
total 0
[root@Centos7 text]# yum install nginx --downloadonly --downloaddir=/app/text
[root@Centos7 text]# ll /app/text
total 0
-rw-r--r-- 1 root root 0 Jan 14 10:40 fontconfig-2.10.95-10.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 fontpackages-filesystem-1.44-8.el7.noarch.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 gd-2.0.35-26.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 GeoIP-1.5.0-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 libXpm-3.5.11-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-all-modules-1.10.2-1.el7.noarch.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-filesystem-1.10.2-1.el7.noarch.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-http-geoip-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-http-image-filter-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-http-perl-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-http-xslt-filter-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-mail-1.10.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 0 Jan 14 10:40 nginx-mod-stream-1.10.2-1.el7.x86_64.rpm

 利用yum的参数,进行只下载,不安装,同时会下载对应依赖的软件

自建仓库

将下载的软件包复制到客户内网机器,设置目录为/app/down

[root@Centos7 ~]# cd /usr/app
[root@Centos7 app]# createrepo .

 

注意:如果createrepo命令不存在的,可以yum install createrepo进行安装

这样自行仓库就建立完成,然后/etc/yum.repos.d/添加对应的配置文件


[root@Centos7 yum.repos.d]# cat localself.repo

[epel]

name=epel

baseurl=file:///app/down

gpgcheck=0


[root@Centos7 yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, langpacks

Cleaning repos: self

Cleaning up everything

[root@Centos7 yum.repos.d]# yum repolist

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

repo id                          repo name                 status

epel                             epel                      245

repolist: 245

 

可以看到自行存放的245个app已经出现在仓库列表中

然后可以通过yum安装自行解决对应的依赖关系,而不是手动安装


CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo


CentOS 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo


CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo


运行yum makecache生成缓存



Centos7修改hostname

[root@centos7 ~]$ hostnamectl set-hostname Centos7.L         --->使用这个命令会立即生效且重启也生效
[root@centos7 ~]$ hostname                                   --->查看下
Centos7.L 
[root@Centos7 ~]$ vim /etc/hosts                             --->编辑下hosts文件, 给127.0.0.1添加hostname
[root@Centos7 ~]$ cat /etc/hosts                             --->查看
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 Centos7.L
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


Centos6下修改hostname

[root@centos6 ~]$ hostname                                           ---> 查看当前的hostnmae
centos6.magedu.com
[root@centos6 ~]$ vim /etc/sysconfig/network                         ---> 编辑network文件修改hostname行(重启生效)
[root@centos6 ~]$ cat /etc/sysconfig/network                         ---> 检查修改
NETWORKING=yes
HOSTNAME=Centos6.L
[root@Centos6 ~]$ hostname Centos6.L                                 ---> 设置当前的hostname(立即生效)
[root@Centos6 ~]$ vim /etc/hosts                                     ---> 编辑hosts文件,给127.0.0.1添加hostname
[root@Centos6 ~]$ cat /etc/hosts                                     ---> 检查
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 Centos6.L
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

使其立即生效而不用重启操作系统
而/etc/rc.d/rc.sysinit中HOSTNAME的取值来自与/etc/sysconfig/network下的HOSTNAME。


HOSTNAME=`/bin/hostname`
 
HOSTTYPE=`uname -m`
 
unamer=`uname -r`
 
set -m
 
if [ -f /etc/sysconfig/network ]; then
 
. /etc/sysconfig/network
 
fi
 
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
 
    HOSTNAME=localhost
 
fi


在CentOS中,我们常用Tab键进行命令补全,但是系统总是提示滴滴声,让人很烦躁。  即使把音频设备关掉,或者虚拟机的音频设备也关掉,还是有这个声音。

 

如果不喜欢这个声音,可以通过修改配置去掉它。用vi或vim 编辑 /etc/inputrc 文件,在vi的命令模式下,用键盘方向键进行定位, 找到“#set bell-style none”,用X 删除语句前方的#号,就可以了。“: wq”进行文件保存,并对系统进行重启以后,既可以去掉这个烦扰的声音了。


1. 查看当前内核版本

[root@L~]#more /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m
[root@L~]#uname -a
Linux L 4.4.127-1.el6.elrepo.x86_64 #1 SMP Sun Apr 8 10:50:25 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux


2. 导入public key

[root@L~]#rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org


3. 安装ELRepo到CentOS

可以去http://elrepo.org/tiki/tiki-index.php 选择要安装的ELRepo 

20D3144D-F594-41ED-A0B7-D797BBF4BBB5.png

[root@L~]#rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm


4. 安装 kernel-lt(lt=long-term)

[root@L~]#yum --enablerepo=elrepo-kernel install kernel-lt -y

或者 安装kernel-ml(ml=mainline)

[root@L~]#yum --enablerepo=elrepo-kernel install kernel-ml -y


5. 编辑grub.conf文件,修改Grub引导顺序

82335256-1DBB-422C-A70C-1DB43F3E0AF0.png

因为一般新安装的内核在第一个位置,所以设置default=0,表示启动新内核


6. 重启

查看此时内核版本:

[root@L~]#uname -a
Linux L 4.4.127-1.el6.elrepo.x86_64 #1 SMP Sun Apr 8 10:50:25 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux