• 虚拟机初始化脚本, 虚拟机相互免秘钥


    一、虚拟机初始化脚本 

    #!/bin/bash
    ## -bash: ./lucky.sh: /bin/bash^M: bad interpreter: No such file or directory
    ## vim 或者 vi 的命令模式下,输入命令 set fileformat=unix 即可解决换行问题
    echo -e "\e[1;31m ---------------------------------------- opt var 创建 lucky 文件
    夹】 \e[0m"
    sleep 5
    mkdir -p /opt/lucky
    mkdir -p /var/lucky
    mkdir -p /usr/local/script
    echo -e "\e[1;31m ---------------------------------------- 禁用防火墙】 \e[0m"
    sleep 5
    systemctl stop firewalld
    systemctl disable firewalld
    systemctl status firewalld
    echo -e "\e[1;32m ---------------------------------------- 修改 selinux \e[0m"
    sleep 5
    sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
    echo -e "\e[1;32m ---------------------------------------- 安装 wget \e[0m"
    sleep 5
    yum install wget -y
    echo -e "\e[1;33m ---------------------------------------- 修改 yum 源】 \e[0m"
    sleep 5
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-
    7.repo
    yum clean all
    yum makecache
    echo -e "\e[1;33m ---------------------------------------- 安装常用软件】 \e[0m"
    yum install man man-pages ntp vim lrzsz zip unzip telnet perl net-tools -y
    echo -e "\e[1;34m ---------------------------------------- 同步系统时间】 \e[0m"
    yum info ntp && ntpdate cn.ntp.org.cn
    echo -e "\e[1;34m ----------------------------------------DNS 域名配置】 \e[0m"
    sleep 5
    echo "192.168.58.100 basenode" >> /etc/hosts
    echo "192.168.58.161 bd1601" >> /etc/hosts
    echo "192.168.58.162 bd1602" >> /etc/hosts
    echo "192.168.58.163 bd1603" >> /etc/hosts
    echo -e "\e[1;34m ---------------------------------------- 安装 JDK \e[0m"
    sleep 5
    rpm -ivh jdk-8u231-linux-x64.rpm
    echo 'export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64' >> /etc/profile
    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
    source /etc/profile
    echo -e "\e[1;35m ---------------------------------------- 安装 Tomcat \e[0m"
    sleep 5
    tar -zxf apache-tomcat-8.5.47.tar.gz
    mv apache-tomcat-8.5.47 /opt/lucky/
    echo -e "\e[1;35m ---------------------------------------- 安装 Mysql \e[0m"
    sleep 5
    rpm -e --nodeps `rpm -qa | grep mariadb`
    tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
    rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
    rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
    rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
    rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
    systemctl start mysqld
    systemctl enable mysqld
    temppasswd = `grep "A temporary password" /var/log/mysqld.log | awk '{ print
    $NF }'`
    mysql -uroot -p $temppasswd --connect-expired-password << EOF
    set global validate_password_policy = low;
    set global validate_password_length = 6 ;
    alter user root@localhost identified by '123456' ;
    use mysql;
    update user set host = '%' where user = 'root' ;
    commit;
    quit
    EOF
    systemctl restart mysqld
    echo -e "\e[1;35m ---------------------------------------- 安装 Nginx \e[0m"
    sleep 5
    echo -e "\e[1;36m ---------------------------------------- 设置开机启动项】 \e[0m"
    sleep 5
    touch /usr/local/script/auto_ntpdate.sh
    echo '#!/bin/bash' >> /usr/local/script/auto_ntpdate.sh
    echo 'yum info ntp && ntpdate cn.ntp.org.cn' >>
    /usr/local/script/auto_ntpdate.sh
    chmod u + x /usr/local/script/auto_ntpdate.sh
    echo '/usr/local/script/auto_ntpdate.sh' >> /etc/rc.local
    chmod u + x /etc/rc.local
    echo -e "\e[1;36m ---------------------------------------- 删除文件】 \e[0m"
    sleep 5
    rm -rf apache-tomcat-8.5.47.tar.gz
    rm -rf jdk-8u231-linux-x64.rpm
    rm -rf mysql*
    rm -rf *.sh
    echo -e "\e[1;36m ---------------------------------------- 关闭计算器,拍快照】
    \e[0m"
    sleep 5
    shutdown -h now

    二、虚拟机相互免秘钥

    ## 三台主机分别生成秘钥
    123 ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
    ##host 验证
    123 vim /etc/ssh/ssh_config 在最后添加
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    ## 将秘钥分别拷贝给自己和别人
    123 ssh-copy-id -i ~/.ssh/id_rsa.pub root@bd1701
    123 ssh-copy-id -i ~/.ssh/id_rsa.pub root@bd1702
    123 ssh-copy-id -i ~/.ssh/id_rsa.pub root@bd1703
    123456
    ## 关闭主机拍摄快照
    power off
  • 相关阅读:
    1.6 前后端身份认证
    利用 Pandoc 将 Latex 转为 MS word 的方法
    Jquery入门和案例
    H2N-Gly-Gly-Pro-COOH,14379-76-1
    金九银十就靠它啦!共计1700页的Java岗面试核心MCA版,面试必胜!!
    JVM基础03_运行时数据区
    有了这款工具,自动化识别验证码再也不是问题
    设计模式——原型模式
    47. 从零开始学springboot: spel结合redisson实现动态参数分布式锁
    区块链的使用场景和优势
  • 原文地址:https://blog.csdn.net/m0_50370837/article/details/125563410