diff --git a/Public/dep/octopus_ssh_banner b/Public/dep/octopus_ssh_banner new file mode 100644 index 0000000..2b06cfa --- /dev/null +++ b/Public/dep/octopus_ssh_banner @@ -0,0 +1,25 @@ + + ______ __ ______ __ + / \ | \ / \ | \ +| $$$$$$\ _______ _| $$_ ______ ______ __ __ _______ | $$$$$$\ ______ ______ _______ _| $$_ +| $$ | $$/ | $$ \ / \ / \| \ | \/ \ | $$__| $$/ \ / \| | $$ \ +| $$ | $| $$$$$$$\$$$$$$ | $$$$$$| $$$$$$| $$ | $| $$$$$$$ | $$ $| $$$$$$| $$$$$$| $$$$$$$\$$$$$$ +| $$ | $| $$ | $$ __| $$ | $| $$ | $| $$ | $$\$$ \ | $$$$$$$| $$ | $| $$ $| $$ | $$| $$ __ +| $$__/ $| $$_____ | $$| | $$__/ $| $$__/ $| $$__/ $$_\$$$$$$\ | $$ | $| $$__| $| $$$$$$$| $$ | $$| $$| \ + \$$ $$\$$ \ \$$ $$\$$ $| $$ $$\$$ $| $$ | $$ | $$\$$ $$\$$ | $$ | $$ \$$ $$ + \$$$$$$ \$$$$$$$ \$$$$ \$$$$$$| $$$$$$$ \$$$$$$ \$$$$$$$ \$$ \$$_\$$$$$$$ \$$$$$$$\$$ \$$ \$$$$ + | $$ | \__| $$ + | $$ \$$ $$ + \$$ \$$$$$$ + __ __ + | \ | \ + ____| $$ ______ ____| $$ ______ __ __ __ ______ _______ ______ + ______ ______ ______ / $$| \ / $$| \ | \ | \ | \| \| \ / \ +| | | \ | $$$$$$$ \$$$$$$| $$$$$$$ \$$$$$$\ | $$ | $$ | $$ \$$$$$$| $$$$$$$| $$$$$$\ + \$$$$$$\$$$$$$\$$$$$$ | $$ | $$/ $| $$ | $$/ $$ | $$ | $$ | $$/ $| $$ | $| $$ | $$ + | $$__| $| $$$$$$| $$__| $| $$$$$$$ | $$_/ $$_/ $| $$$$$$| $$ | $| $$__| $$ + \$$ $$\$$ $$\$$ $$\$$ $$ \$$ $$ $$\$$ $| $$ | $$\$$ $$ + \$$$$$$$ \$$$$$$$ \$$$$$$$ \$$$$$$$ \$$$$$\$$$$ \$$$$$$$\$$ \$$_\$$$$$$$ + | \__| $$ + \$$ $$ + \$$$$$$ diff --git a/Public/dep/ssh_key_pub.txt b/Public/dep/ssh_key_pub.txt index f7111e8..8b5724b 100644 --- a/Public/dep/ssh_key_pub.txt +++ b/Public/dep/ssh_key_pub.txt @@ -1 +1,2 @@ + ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL9S6CSAjTFe2fy4bAIfqu90ft6E+GBRvS59kno6LDeAbqUQNYf9hEnIg07Ee/x5DlnYE0S3Ykv3WCHuVyBH2zANnC0P87SqphDGmoqdqF3r6uDaCr4lBsUqEai9X2q6dyjZj6ym+r4zQhMApNDzbhcyfKQ54tKFylGIdx6siyktuU/VbOzWc6G8r+BfFsQpMCA1ihmCY1jGjsKPqFlZGLeTrlBb1Zk0OV+GtDhlf/t0cd0kRPJoydm2juTXrZO+tFmf9turfKZsBnRYKtQBLJG5mF1hsjIqo8DHr+PUL2wRrSxEhGTZiJL4rNJo/kHhKXXsomc5RM/AnfgAfxrLlH zeasl@DESKTOP-K2F9GG3 diff --git a/Public/init-script-wdd.sh b/Public/init-script-wdd.sh index 2876975..ca480de 100644 --- a/Public/init-script-wdd.sh +++ b/Public/init-script-wdd.sh @@ -8,7 +8,7 @@ echo "" echo "" mkdir -p /root/wdd/lib/ lib_file_list=(wdd-lib-log.sh wdd-lib-sys.sh) -for lib_file in ${lib_file_list[@]} ; do +for lib_file in ${lib_file_list[@]}; do wget "https://oss-s1.107421.xyz/${lib_file}" -qO "/root/wdd/lib/${lib_file}" echo "加载库文件 < /root/wdd/lib/${lib_file}" . "/root/wdd/lib/${lib_file}" @@ -23,6 +23,7 @@ done docker_version=20.10.10 oss_url_prefix="https://oss-s1.107421.xyz" +modify_ssh_port=22333 # 脚本执行内容 deploy_in_cn=0 @@ -107,15 +108,15 @@ shutdown_firewall() { add_octopus_host() { FunctionStart "添加Octopus自定义Hosts!" - if grep -q "140.238" < /etc/hosts; then + if grep -q "140.238" > /etc/hosts + cat /tmp/wdd-server-host.txt >>/etc/hosts fi - if grep -q "140.238" < /etc/hosts; then + if grep -q "140.238" /etc/fstab + grep -v swap /etc/fstab colorEchoGreen " 修改完成 " FunctionEnd } @@ -197,7 +198,6 @@ install_docker() { $CMD_REMOVE "$pre_one" done - colorEchoGreen "----------docker环境清理完成----------" SplitGreen @@ -272,8 +272,8 @@ install_docker() { log "开始添加 Docker官方 的docker源的apt源" echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ - "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" \ + | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null colorEchoGreen " apt源添加成功 " echo "" fi @@ -368,7 +368,7 @@ install_zsh() { echo y | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" fi SplitLine -log + log if modify_zsh; then log "开始修改默认shell为zsh……" local i @@ -437,9 +437,9 @@ EOF echo "" colorEchoGreen "请检查当前zsh的插件开启情况:" colorEchoGreen "------------------------------------------" - grep "plugins=" < /root/.zshrc| grep -v "\#" - grep "plugins=" < /root/.zshrc| grep -v "\#" - grep "plugins=" < /root/.zshrc| grep -v "\#" + grep "plugins=" /dev/null; then + log "当前的ssh登录端口已经为${SSHLoginPort},无需修改!" + else + if sed -i "/^#Port 22/a Port ${modify_ssh_port}" $ssh_config_file; then + log "ssh的登陆端口已被修改为${modify_ssh_port},请修改防火墙以开放该端口!!" + fi + fi + SplitGreen + + # 修改ssh的连接中断延时 + log "修改ssh的连接中断延时!" + echo "ClientAliveInterval 30" >>$ssh_config_file + echo "ClientAliveCountMax 60" >>$ssh_config_file + SplitGreen + + # 修改ssh的banner信息 + log "修改ssh的banner信息 !" + wget $oss_url_prefix/octopus_ssh_banner -qO /etc/ssh/octopus_banner + sed -i "s/#Banner none/Banner \/etc\/ssh\/octopus_banner/g" $ssh_config_file + echo "" + log "banner 内容为 => $(cat /etc/ssh/octopus_banner)" + SplitGreen + + # 重启SSHD服务 + log "开始重启SSHD服务!" + if systemctl restart sshd.service; then + log "sshd.service服务已经重启完成!" + colorEchoGreen "sshd文件已经修改成功,可以进行root登录,请修改root密码~~" + else + error "sshd服务重启失败,请检查原因!!!" + error "如果是CentOS,大概率是防火墙的问题。" + fi + SplitGreen + + FunctionEnd } -modify_ssh_login(){ +####################################### +# description +# Arguments: +# None +# Returns: +# 1 ... +####################################### +modify_ssh_login() { FunctionStart "开始配置SSH 登录密钥!" - + if [[ ! -f /root/.ssh/id_rsa ]]; then log "未检测到 ssh rsa 密钥信息,开始生成!" ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa fi - cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys - chmod 600 ~/.ssh/authorized_keys + if grep $(cut -d " " -f3 < ~/.ssh/id_rsa.pub) < ~/.ssh/authorized_keys; then + log "本机的ssh-key信息已经写入,跳过!" + else + cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + fi SplitLine log "下载公共id_rsa.pub文件!" wget https://oss-s1.107421.xyz/ssh_key_pub.txt -qO /tmp/ssh_key_pub.txt - if [[ ! -s /tmp/ssh_key_pub.txt ]]; then error "下载 ssh-key 失败!" return 1 fi log "开始写入ssh-key信息!" - cat /tmp/ssh_key_pub.txt >> ~/.ssh/authorized_keys + cat /tmp/ssh_key_pub.txt >>~/.ssh/authorized_keys - if grep -q "DESKTOP-K2F9GG3" < ~/.ssh/authorized_keys; then - colorEchoGreen "公共SSH-Key已经写入成功!" + if grep -q "DESKTOP-K2F9GG3" <~/.ssh/authorized_keys; then + log $(grep "DESKTOP-K2F9GG3" <~/.ssh/authorized_keys) + colorEchoGreen " 公共SSH-Key已经写入成功! " SplitGreen fi @@ -649,26 +749,39 @@ common_tool_install() { # None ####################################### help() { + + local call_script_command="source <(curl -sL https://oss-s1.107421.xyz/init-script-wdd.sh)" + + local only_ssh_init_command="$call_script_command --ssh-login --ssh-port 22333 --firewall " + + local base_init_command="$only_ssh_init_command --tools --host --zsh" + cat - 1>&2 < 安装docker,并且指定相应的版本 + --docker 安装docker 版本 --docker-compose 安装docker-compose 2.18.0 --zsh 安装并且配置ZSH --cn 是否在国内安装 --host 是否配置服务器的Host解析 --time 是否配置时间同步 --ssh-login 修改ssh的登录密钥 - --ssh-port 修改ssh的登录端口 + --ssh-port 修改ssh的登录端口 端口 EOF } @@ -710,12 +823,13 @@ while [[ $# -gt 0 ]]; do is_modify_ssh_login=1 ;; --ssh-port) - is_modify_ssh_login=1 + is_modify_ssh_port=1 + modify_ssh_port=$2 ;; *) # unknown option ;; - esac + esac shift # past argument or value done @@ -738,7 +852,7 @@ main() { check_root check_sys - if [[ "$is_shutdown_firewall" -eq "1" ]]; then + if [[ $is_shutdown_firewall -eq "1" ]]; then shutdown_firewall fi @@ -746,7 +860,7 @@ main() { # 关闭虚拟缓存,k8s安装的时候才需要 disable_swap fi - + if [[ $is_modify_ssh_login -eq 1 ]]; then modify_ssh_login fi @@ -782,9 +896,6 @@ main() { install_zsh fi - - - # 使用chrony进行NTP时间同步--包含下面的设置 # time_sync_to_ali_by_chrony || return $? @@ -793,4 +904,3 @@ main() { } main - diff --git a/Public/mid-script.sh b/Public/mid-script.sh index c1afeee..acc186c 100644 --- a/Public/mid-script.sh +++ b/Public/mid-script.sh @@ -1,5 +1,9 @@ #!/bin/bash + +. + + ## 对外暴露的安装Redis的主函数 InstallRedis() { FunctionStart