好久没写脚本了,今天为了测试做了下mysql同时也写了一个小小的安装脚本 不过这还是第一次在Ubuntu环境写脚本 如下:
#!/bin/bash ########################################################### #Ubuntu16.0.4 Install MySQL5.7 ########################################################### Catalog=/usr/local/src function Internet(){ wget --spider -q -o /dev/null --tries=1 -T 5 http://www.baidu.com if [ "$?" -ne 0 ] then echo "Please check your network" return 1 fi } function package(){ sudo apt-get install -y vim && sudo apt-get install -y wget && apt-get install libaio* -y } function Install_MySQL(){ cd $Catalog && { wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz &>/dev/null if [ "$?" -ne 0 ];then echo "wget MySQL ERROR!!!" return 1 else tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql && cd /usr/local/mysql/ && mkdir data && mkdir log && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile && source /etc/profile && groupadd mysql && useradd -r -g mysql -s /bin/false mysql } } function conf(){ cat << Daasbank > /etc/my.cnf [client] socket=/usr/local/mysql/mysql.sock [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data pid-file=/usr/local/mysql/data/mysqld.pid socket=/usr/local/mysql/mysql.sock log_error=/usr/local/mysql/log/mysql.err Daasbank if [ -f /etc/my.cnf ] then chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && /usr/local/mysql/bin/mysqld --initialize --user=mysql && cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && systemctl enable mysqld && /etc/init.d/mysqld start &> /dev/null else ln -s /usr/local/mysql/bin/mysql /usr/local/bin ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin fi } function main(){ Internet package Install_MySQL conf } main
谢谢观看~