jenkins安装脚本

  • jenkins安装脚本
#!/bin/bash
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install wget git curl -y
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install java jenkins -y
systemctl start jenkins
## 查看jenkins默认生成的密码
cat /var/lib/jenkins/secrets/initialAdminPassword

SHELL脚本之case

  • 一般形式
case variable in
    pattern1 | pattern2)
        command;;
    pattern3)
        command;;
    *)
        default command;;
esac
  • 例子
#!/bin/bash
case $USER in
    root | user)
        echo "Welcome.$USER"
        echo "Please enjoy your visit";;
    testing)
        echo "Special testing acount";;
    *)
    echo "Sorry,you are not allowed here";;
esac

SHELL脚本之if

if语句的几种常用方法

  • if then fi
if command
then
    commands
fi
  • if then else fi
if command
then
    commands
else
    commands
fi
  • if then elif then fi
if command1
then
    commands
elif command2
then
    more commands
fi

PS:
1.if-then语句允许你使用布尔逻辑来组合测试,有两种布尔运算符可用:
[ condition ] && [ condition2 ]
[ condition ] || [ condition2 ]
2.双圆括号命令允许你将高级数学表达式放入比较中:
(( expression ))
3.双方括号里的expression使用了test命令中采用的标准字符串进行比较。但他提供了test命令未提供的另一种特性—-模式匹配
[[ expression ]]

go环境搭建

本方法在centos系列系统中实用,其余系统暂没有测试过!

  • 下载go的tar文件并解压
cd /opt && wget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz
tar zxvf go1.17.5.linux-amd64.tar.gz
[ -f go1.17.5.linux-amd64.tar.gz ] && rm go1.17.5.linux-amd64.tar.gz -rf
  • 设置环境变量
echo "" >> /etc/profile
echo "##go 环境变量设置" >> /etc/profile
echo "export GOPATH=/opt/go" >> /etc/profile
echo "export PATH=\$PATH:\$GOPATH/bin" >> /etc/profile
echo 'export GOPROXY="https://goproxy.cn"' >> /etc/profile
echo "export GO111MODULE=on" >> /etc/profile
source /etc/profile

ngrok作为内网穿透工具来使用

  • 创建自有证书,并编译服务端和客户端的bin文件。 编译的时候需要go环境,请参考 go环境搭建
NGROK_DOMAIN="your_domain_name"
[ ! -d /opt/ssl ] && mkdir -p /opt/ssl
cd /opt && git clone https://github.com/inconshreveable/ngrok.git
cd /opt/ssl
openssl genrsa -out base.key 2048
openssl req -new -x509 -nodes -key base.key -days 3650 -subj "/CN=${NGROK_DOMAIN}" -out base.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=${NGROK_DOMAIN}" -out server.csr
openssl x509 -req -in server.csr -CA base.pem -CAkey base.key -CAcreateserial -days 3650 -out server.crt
cp base.pem /opt/ngrok/assets/client/tls/ngrokroot.crt
cd /opt/ngrok
make release-server release-client
  • ngrokd 会开一个 4443 端口用来跟客户端通讯(可通过 -tunnelAddr=”:xxx” 指定),这儿使用的是8899
/opt/ngrok/bin/ngrokd -tlsKey=/opt/ssl/server.key -tlsCrt=/opt/ssl/server.crt -domain="your_domain_name" -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":8899"
  • 客户端的一个示例配置文件(ngrok.cfg)
server_addr: "your_domain_name:8899"
trust_host_root_certs: false
tunnels:
  http:
    subdomain: "httptest"
    proto:
       http: "172.16.50.35:80"
  https:
    subdomain: "httpstest"
    proto:
      https: "172.16.50.35:443"
  ssh:
    remote_port: 12345
    proto:
      tcp: "172.16.50.35:22"
  • 客户端启动,客户端bin程序从刚刚的服务端编译好的下载下来使用
/opt/ngrok/ngrok -config=/opt/ngrok/ngrok.cfg start-all