对于一些不能访问Internet的服务器,需要通过离线安装软件。通过制作ubuntu本地源,可以实现通过apt install来离线安装软件。
1.首先需要在能访问网络的机器上,将需要安装的软件包及依赖下载到本地。
以安装expect为例:
a. mkdir packages
b . cd packages
下载依赖包有两种方法,推荐方法二
方法一:
apt-get download expect && apt-cache depends -i expect | awk '/Depends:/ {print $2}' | xargs apt-get download
若碰到类似下面的错误
W: Download is performed unsandboxed as root as file '/home/dongsongz/local/packages/cdebconf_0.213ubuntu1_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
执行chown _apt:root ../packages/
然后重新下载(上面apt-get download三条命令)
方法二:
下载除了用上面的apt-get downlaod方法外,一个更可靠的方法如下
mkdir -p /root/packages
mkdir -p /root/packages/partial
apt-get -o dir::cache::archives="/root/packages/" -d --reinstall install expect
下载的安装包都在/root/packages路径下。
若遇到目标已安装且不能重复安装导致不能下载,可以通过apt autoremove [package name]先卸载再下载。
c. dpkg-scanpackages . | gzip -9c > Packages.gz
Command 'dpkg-scanpackages' not found, but can be installed with:
apt install dpkg-dev
d. tar -zcf ubuntu_local_package.tar.gz packages/
2.将ubuntu_local_package.tar.gz拷贝到目标机器进行离线安装
tar zxf ubuntu_local_package.tar.gz -C localPackages/
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb [trusted=yes] file:///home/dongsongz/local/localPackages/packages/ ./" > /etc/apt/sources.list
/home/dongsongz/local/localPackages/packages/替换为实际解压的路径
apt clean all
apt update
apt install -y tcl tk expect
3.安装完毕,测试一下
#/usr/bin/expect
spawn ssh [email protected]
expect {
"*yes/no" {
send "yes\n"
expect "*password:" {
send "letmein\r"
}
}
"*password:" {
send "letmein\r"
}
}
expect "*#"
send "ls"
interact
expect -f login.sh
spawn ssh [email protected]
[email protected]'s password:
Last login: Tue Jul 21 19:18:36 2020 from ............
[root@cdh1 ~]#
登录成功~