[工具] Shell 批量将本地的网站公私钥拷贝到远程服务器

介绍

基本信息

作者:朱明宇
名称:批量将本地的网站公私钥拷贝到远程服务器
作用:批量将本地的网站公私钥拷贝到远程服务器

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

1. sslpath=”/etc/letsencrypt/live/eternalcenter.com” #本地服务器存放网站公私钥的目录
2. sslfile1=”fullchain.pem” #本地服务器上的网站公钥的名称
3. sslfile2=”privkey.pem” #本地服务器上的网站私钥的名称
4. bip=”192.168.0.1″ #存放网站公私钥的远程服务器的 IP 地址,多个 IP 地址可以用空格分隔
5. buser=”mingyuzhu” #用于登录远程服务器的用户名
6. bcache=”/bcache” #远程服务器存放网站公私钥的目录

注意

1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器
2. 必须以 root 用户执行本脚本

脚本

#!/bin/bash

####################### Separator ########################

sslpath="/etc/letsencrypt/live/eternalcenter.com" #website cache
sslfile1="fullchain.pem"
sslfile2="privkey.pem"

bip="192.168.0.1"
buser="mingyuzhu"
bcache="/bcache"

####################### Separator ########################

######################## copy webiste date to remote server #########################

for i in `echo $bip`

do
ping -c4 -i0.8 -w4 $i &> /dev/null

if [ $? -eq 0 ];then
    ssh $buser@$i "who -b"
        if [ $? -eq 0 ];then
#            ssh $buser@$i "sudo mkdir $bcache ; sudo chown $buser:$buser $bcache"
            scp $sslpath/$sslfile1 $buser@$i:$bcache/ 
            scp $sslpath/$sslfile2 $buser@$i:$bcache/ 
        fi
fi
done

######################## copy webiste date to remote server #########################

[STEP] DELL server iDRAC physical disk foreign state clean

Step One: Check the state of physical disk

Storage –> Overview –> Physical Disks
We can see the State is Foreign not Ready

Step Two: Clean the foreign state of physical disk

2.1 Access controllers interface

Storage –> Overview –> Controllers

2.2 Clean the foreign state of physical disk

Choose Controllers à Action à Foreign Configuration à Clean Foreign

[步骤] Rocky Linux & RHEL 本地缓存的软件包的安装

步骤一:将 yum 工具 & dnf 工具缓存下来的软件包设置为持续保存

# vi /etc/yum.conf

或者:

# vi /etc/dnf/dnf.conf

将部分内容修改如下:

......
keepcache = 1

步骤二:清空本地 yum 工具 & dnf 工具的缓存

# yum clean all

或者:

# dnf clean all

步骤三:将 yum 工具 & dnf 工具的软件包清单缓存到本地

# yum makecache

步骤四:将 yum 工具 & dnf 工具所有可以升级的软件包缓存到本地

# yum update --downloadonly

或者:

# dnf update --downloadonly

步骤五:显示已经缓存的软件包

5.1 显示所有已经缓存的软件包

# yum -C list

或者:

# dnf -C list

5.2 显示某个已经缓存的软件包

# yum -C list kernel

或者:

# dnf -C list kernel

(补充:这里以显示已经缓存的 kernel 软件包为例)

步骤六:使用 yum 工具 & dnf 工具缓存的所有软件包提到系统里现存的老的软件包

# yum -C update

或者:

# dnf -C update

[CONTENT] SUSE Repository Mirroring Tool (RMT) mirror schedule configuration

Content One: Configure the mirror schedule

1.1 Modify /etc/systemd/system/multi-user.target.wants/rmt-server-sync.timer file

# vi /etc/systemd/system/multi-user.target.wants/rmt-server-sync.timer

Modify all content as follows:

[Unit]
Description=RMT Sync timer

[Timer]
OnCalendar=*-*-01 01:00:00
RandomizedDelaySec=9h
Unit=rmt-server-sync.service

[Install]
WantedBy=multi-user.target

(Note: here is an example with setting the mirror schedule to the 1st of every month)

1.2 Apply the settings to make them take effect

# systemctl restart rmt-server-sync.timer
# systemctl restart rmt-server-mirror.timer

Content Two: Disable the mirror schedule

2.1 Disable the mirror schedule

# systemctl disable --now rmt-server-sync.timer
# systemctl disable --now rmt-server-mirror.timer
# systemctl daemon-reload

2.2 Manual Mirror

# rmt-cli sync
# rmt-cli mirror

Or:

# rmt-cli sync ; rmt-cli mirror