Shell脚本一键部署(mysql)

编译安装MySQL

1、软件包

MySQL安装包

    将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者. 执行脚本,等脚本执行完成,即可使用mysql -u root -p点击回车即可进入。

2、MySQL一键部署脚本(使用source或者.执行脚本!)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 #!/bin/bash echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m" ping -c1 -W1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m" mkdir -p /etc/yum.repos.d/repo.bak   mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null   wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null   yum clean all &> /dev/null yum list &> /dev/null echo -e "\033[31m 在线源已配置完成 \033[0m"   else echo -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m" mount /dev/sr0 /mnt &> /dev/null cd /etc/yum.repos.d/ mkdir -p /etc/yum.repos.d/repo.bak   mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null   echo '[local] name=local baseurl=file:///mnt enabled=1 gpgcheck=0' > /etc/yum.repos.d/local.repo yum clean all &> /dev/null yum makecache &> /dev/null   df -h | grep "/mnt" if [ $? -ne 0 ];then echo -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m" else echo -e "\033[31m 本地yum源已配置完成 \033[0m" fi fi   #关闭系统防火墙和安全机制 systemctl stop firewalld systemctl disable firewalld setenforce 0   echo -e "\033[31m 检查安装包是否正确,请耐心等待 \033[0m" ls /opt | egrep "^mysql-boost-5.7.20.tar.gz$" if [ $? -eq 0 ];then echo -e "\033[31m 接下来进入正式配置,请耐心等待 \033[0m" else echo -e "\033[31m 请准备正确安装包mysql-boost-5.7.20.tar.gz \033[0m" exit fi     #安装Mysql环境依赖包 yum -y install \ ncurses \ ncurses-devel \ bison \ cmake \ gcc \ gcc-c++ \ make   #创建程序用户,便于准确控制访问用户 useradd -M -s /sbin/nologin  mysql   #编译安装 cd /opt tar xzvf mysql-boost-5.7.20.tar.gz -C /opt   cd /opt/mysql-5.7.20/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8  \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1   #编译及安装 make && make install   #修改mysql 配置文件 echo '[client] port = 3306 socket=/usr/local/mysql/mysql.sock   [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1   sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf     #更改mysql安装目录和配置文件的属主属组 chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf   #设置路径环境变量 echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile source /etc/profile   #初始化数据库 cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data   #添加mysqld系统服务 cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/     systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld

编译安装MySQL

1、软件包

MySQL安装包

    将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者. 执行脚本,等脚本执行完成,即可使用mysql -u root -p点击回车即可进入。

2、MySQL一键部署脚本(使用source或者.执行脚本!)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 #!/bin/bash echo -e "\033[31m =====正在验证当前为仅主机还是NAT模式===== \033[0m" ping -c1 -W1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then echo -e "\033[31m 检测当前为NAT模式,为您配置在线yum源 \033[0m" mkdir -p /etc/yum.repos.d/repo.bak   mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null   wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null   yum clean all &> /dev/null yum list &> /dev/null echo -e "\033[31m 在线源已配置完成 \033[0m"   else echo -e "\033[31m 检测当前为仅主机模式,为您配置本地yum源 \033[0m" mount /dev/sr0 /mnt &> /dev/null cd /etc/yum.repos.d/ mkdir -p /etc/yum.repos.d/repo.bak   mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null   echo '[local] name=local baseurl=file:///mnt enabled=1 gpgcheck=0' > /etc/yum.repos.d/local.repo yum clean all &> /dev/null yum makecache &> /dev/null   df -h | grep "/mnt" if [ $? -ne 0 ];then echo -e "\033[31m 检测当前为仅主机模式,但光盘未连接! \033[0m" else echo -e "\033[31m 本地yum源已配置完成 \033[0m" fi fi   #关闭系统防火墙和安全机制 systemctl stop firewalld systemctl disable firewalld setenforce 0   echo -e "\033[31m 检查安装包是否正确,请耐心等待 \033[0m" ls /opt | egrep "^mysql-boost-5.7.20.tar.gz$" if [ $? -eq 0 ];then echo -e "\033[31m 接下来进入正式配置,请耐心等待 \033[0m" else echo -e "\033[31m 请准备正确安装包mysql-boost-5.7.20.tar.gz \033[0m" exit fi     #安装Mysql环境依赖包 yum -y install \ ncurses \ ncurses-devel \ bison \ cmake \ gcc \ gcc-c++ \ make   #创建程序用户,便于准确控制访问用户 useradd -M -s /sbin/nologin  mysql   #编译安装 cd /opt tar xzvf mysql-boost-5.7.20.tar.gz -C /opt   cd /opt/mysql-5.7.20/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8  \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1   #编译及安装 make && make install   #修改mysql 配置文件 echo '[client] port = 3306 socket=/usr/local/mysql/mysql.sock   [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1   sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf     #更改mysql安装目录和配置文件的属主属组 chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf   #设置路径环境变量 echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile source /etc/profile   #初始化数据库 cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data   #添加mysqld系统服务 cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/     systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld
上一篇:Shell脚本一键部署-----源码编译安装MySQL数据库


下一篇:JVM笔记9-Class类文件结构