步骤一:挂载本地镜像
# mount /dev/sr1 /mnt
(补充:这里以挂载 /dev/sr1 到 /mnt 目录为例)
步骤二:添加本地镜里的软件源
# zypper ar file:///mnt/Module-Basesystem local
(补充:这里以将 file:///mnt/Module-Basesystem 添加到软件源并命名为 local 为例)
# mount /dev/sr1 /mnt
(补充:这里以挂载 /dev/sr1 到 /mnt 目录为例)
# zypper ar file:///mnt/Module-Basesystem local
(补充:这里以将 file:///mnt/Module-Basesystem 添加到软件源并命名为 local 为例)
作者:朱明宇
名称:批量检测服务器 TCP 端口的联通状态
作用:批量检测服务器 TCP 端口的联通状态
使用方法:
1. 端口清单 $portlist 每一个端口占用一行,格式为:<要联通端口号对应的 IP 地址>:<要联通的端口号>:<端口功能>
2. 在此脚本的分割线内写入相应的内容,并和此脚本放在同一目录下
3. 给此脚本添加执行权限
4. 执行此脚本,并将要测试的服务器 IP 地址跟在脚本的后面,例:. <脚本名> <服务器 IP 地址 1> <服务器 IP 地址 2> ……
脚本分割线里的变量:
portlist=tcp_ports.txt #存放要测试的 TCP 端口的文件
注意:
1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器
2. 执行此脚本前确保 nc 命令已经安装
#!/bin/bash
####################### Separator ########################
portlist=tcp_ports.txt
####################### Separator ########################
for hosts in $*
do
echo $hosts
ssh $hosts "which nc" &> /dev/null
if [ $? -ne 0 ];then
echo -e "\033[31m$hosts can not use nc !!!!!!!!!!\033[0m"
continue
fi
for line in `cat $portlist`
do
ips=`echo $line | awk -F':' '{print $1}'`
ports=`echo $line | awk -F':' '{print $2}'`
remarks=`echo $line | awk -F':' '{print $3}'`
ssh $hosts "nc -z -w 3 $ips $ports"
if [ $? -ne 0 ];then
echo -e "\033[31m$ips $ports $remarks can not be connected !!!!!!!!!!\033[0m"
else
echo -e "\033[32m$ips $ports $remarks can be connected\033[0m"
fi
done
done
纪念:站主于 2021 年 2 月完成了此开源实验,并将过程中的所有命令经过整理和主是以后,形成以下教程
client eth0:10.0.0.10/24
proxy eth0:10.0.0.5/24
eth1:10.0.1.5/24
web1 eth1:10.0.1.100/24
web2 eht1:10.0.1.200/24
web1
eth1:10.0.1.100/24
client proxy
eth0:10.0.0.10/24 eth0:10.0.0.5/24
eth1:10.0.1.5/24
web2
eht2:10.0.1.200/24
(1)client 向 proxy 的 eth0:10.0.0.5/24 发送 web 请求
(2)proxy 收到 web 请求后通过 eth1:10.0.1.5/24 将请求发往 web1 或 web2
(3)web1 或 web2 回应 web 请求,并通过 proxy 返回给 client
(4)最终实现单点代理器,双网站热备份
(1)所有服务器的系统都需要是 CentOS 8 版本
(2)所有服务器都要关闭防火墙
(3)所有服务器都要关闭 SELinux
(4)所有服务器系统都要配置好可用的软件源
(5)需要按照拓扑图给对应的服务器配置好 IP 地址和主机名
(6)所有服务器都要可以相互 ping 通自己和对方的 IP 地址
(只在 proxy 上执行以下步骤)
# yum -y install haproxy
(只在 web1 上执行以下步骤)
# yum -y install httpd
(只在 web1 上执行以下步骤)
# echo "10.0.1.100" > /var/www/html/index.html
(只在 web1 上执行以下步骤)
# systemctl start httpd ; systemctl enable httpd
(只在 web2 上执行以下步骤)
# yum -y install httpd
(只在 web2 上执行以下步骤)
# echo "10.0.1.200" > /var/www/html/index.html
(只在 web2 上执行以下步骤)
# systemctl start httpd ; systemctl enable httpd
(只在 proxy 上执行以下步骤)
# vim /etc/sysctl.conf
添加以下内容:
net.ipv4.ip_forward = 1
(只在 proxy 上执行以下步骤)
# sysctl -p
(只在 proxy 上执行以下步骤)
# vim /etc/haproxy/haproxy.cfg
将全部内容修改如下:
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# https://www.haproxy.org/download/1.8/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
# utilize system-wide crypto-policies
ssl-default-bind-ciphers PROFILE=SYSTEM
ssl-default-server-ciphers PROFILE=SYSTEM
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
bind *:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:80 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 10.0.1.100:80 check
server app2 10.0.1.200:80 check
(只在 proxy 上执行以下步骤)
# systemctl start haproxy ; systemctl enable haproxy
(只在 client 上执行以下步骤)
# curl 10.10.10.5
(注意:这一步需要多做几次)
# convert <input options> <output file name> <output options> <output file name>
# convert "a.png" "a.png.jpg"
(补充:这里以将 a.png 转换成 a.png.jpg 为例)
# ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg"'
(补充:这里以将当前目录下的所有 *.png 文件转换成 *.png.jpg 文件)
sshpass的安装使用
1:sshpass下载与安装
yum安装:
yum install sshpass
若yum安装不上,则用下面方法
https://sourceforge.net/projects/sshpass/files/
or
https://pan.baidu.com/s/1pLNxeLd
or
wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz
2:下载后,解压,安装
tar -zxvf sshpass-1.06.tar.gz
cd sshpass-1.06
./configure
make
make install
3:使用命令
sshpass -p 123456 scp /home/file.txt root@10.0.0.37:/home/copy
后面这个是 “Are you sure you want to continue connecting (yes/no)”使得这个自动接受,若不加,则成功不了
4:脚本
复制代码
#!/bin/bash
password=123456
user=root
ip=10.0.0.37
file=/home/file.txt
sshpass -p $password scp file $user@$ip:/home/copy/
————————————————
版权声明:本文为CSDN博主「totoroKing」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_30553235/article/details/78711491
注明:所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来