1:两台Linux服务器之间传输文件
scp [参数] <源地址(用户名@IP地址或主机名)>:<文件路径> <目的地址(用户名 @IP 地址或主机名)>:<文件路径>
举例:
scp /home/work/source.txt work@192.168.0.10:/home/work/ #把本地的source.txt文件拷贝到192.168.0.10机器上的/home/work目录下
2:导出镜像和导入镜像
-
导出镜像
docker save nginx > /root/images/nginx.tar
-
导入镜像
docker load < /opt/images/hello-world.tar
3:内网环境安装docker
-
下载docker版本
-
解压缩文件
tar -zxvf docker-19.03.8.tgz
-
将解压好的 Docker 文件复制到 /usr/bin 目录下
cp docker/* /usr/bin/
-
在 /etc/systemd/system/ 目录下新增 docker.service 文件,将 docker 注册为服务,内容如下
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1 ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
此处的–insecure-registry=127.0.0.1(此处改成你私服ip)设置是针对有搭建了自己私服Harbor时允许docker进行不安全的访问,否则访问将会被拒绝
-
启动 docker
为 docker.service 文件添加执行权限
chmod +x /etc/systemd/system/docker.service
重新加载配置文件
重新加载配置文件 systemctl daemon-reload 启动 systemctl start docker 设置开机启动 systemctl enable docker.service 查看docker的服务状态 systemctl status docker
4:内网安装docker-compose
-
下载安装包:
https://github.com/docker/compose/releases -
将下载好的额docker-compose-Linux-x86_64上传到 /usr/local/bin/目录下即可
-
修改名称进行授权即可
cd /usr/local/bin mv docker-compose-Linux-x86_64 docker-compose sudo chmod +x docker-compose
-
查看docker-compose版本号
docker-compose --version
5: linux生成密钥
生成密钥对
ssh-keygen -t rsa
查看密钥信息
cd /root/.ssh
6:docker配置代理
1 创建目录
mkdir /etc/systemd/system/docker.service.d
2 创建文件
touch /etc/systemd/system/docker.service.d/http-proxy.conf
3 配置http-proxy.conf文件增加以下内容
[Service]
Environment="HTTP_PROXY=http://10.98.65.55:8000"
4 daemon重新reload 并重启docker
systemctl daemon-reload
systemctl restart docker
7:Linux 通过iptables实现内网服务器访问外网
环境:
A服务器 外网ip:123.123.123.123 内网ip:192.168.10.10
B服务器 内网ip:192.168.10.11
配置
1.在A服务器上打开转发
sysctl -a |grep 'net.ipv4.ip_forward' 查看转发是否开启 1为开启
设置转发:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
2.在A服务器上设置iptables规则:
iptables -t nat -A POSTROUTING -s 192.168.10.11 -j SNAT --to 123.123.123.123
如果想让整个内网的机器全部上网,只需要把 -s 192.168.10.11 换成 -s 192.168.10.0/255.255.255.0 即可
3.在B服务器上设置网关为A服务器内网地址 192.168.10.10
vim /etc/sysconfig/network-scripts/ifcfg-eth0
添加以下行
GATEWAY=192.168.15.100
保存退出
重启network服务
service network restart
4.测试B服务器是否已经可以访问外网
8:cnetos常用命令
查看端口占用情况
netstat -ntlp // 带线程id号
netstat -ntl // 不带线程id号
route -n
9:tinyproxy代理
tinyproxy是一款轻量级的http/https代理软件,可以满足小规模的代理上网请求
-
安装
安装 yum -y install tinyproxy
-
配置
vim /etc/tinyproxy/tinyproxy.conf 默认为 8888
注释掉 Allow,表示允许所有人访问代理 #Allow 127.0.0.1 隐藏掉Via请求头部,去掉下面的注释 DisableViaHeader Yes 更多配置项,下面是列举一些配置文件默认的,不需要配置: PidFile "/var/run/tinyproxy/tinyproxy.pid" LogFile "/var/log/tinyproxy/tinyproxy.log" LogLevel Info MaxClients 100 MinSpareServers 5 MaxSpareServers 20 StartServers 10
-
启动TinyProxy
systemctl start tinyproxy.service
systemctl restart tinyproxy.service systemctl stop tinyproxy.service systemctl status tinyproxy.service systemctl enable tinyproxy.service
-
关闭防火墙或开放端口访问
方式1:关闭防火墙
/etc/init.d/iptables stop
方式2:开放端口访问
iptables -A INPUT -p tcp --dport 12801 -j ACCEPT
重启防火墙
/etc/init.d/iptables restart
-
验证生效
1)命令行测试验证(服务器本地测试)
使用TinyProxy拉取google.com的页面信息:
curl -x 127.0.0.1:8888 www.baidu.com