shell脚本安装mysql并安装一个小服务
生活随笔
收集整理的這篇文章主要介紹了
shell脚本安装mysql并安装一个小服务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?!!!!!!改配置文件盡量手寫,手寫,手寫
#!/bin/bash #更改主機名 hostnamectl set-hostname mysql a=`ss -nulpt | grep 3306 | awk -F: '/tcp/{print $4}'` if [ ${a} == 3306 ];thenecho "install mysql"echo "ok" elseecho "no install mysql" #創件yum倉庫echo -e "[mysql57-community]\nname=MySQL 5.7 Community Server\nbaseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/local.repoyum clean all && yum makecache &> /dev/null #裝包 yum install -y php php-xml php-json mysql-community* &> /dev/nullsystemctl enable mysqld --nowb=`ss -nulpt | grep 3306 | awk -F: '/tcp/{print $4}'`if [ ${b} == 3306 ];thenecho "install mysql"if [ $? == 0 ];thenecho "ok"mysqladmin -uroot -p`grep -i password /var/log/mysqld.log | awk 'NR==1{print $11}'` password NSD2021@tedu.cnecho "passwd is ok"elseecho "no"fifi fi #!/bin/bash #安裝mysql mysql () { #更改主機名 hostnamectl set-hostname mysql ss -nulpt | grep 3306 if [ $? == 0 ];thenecho "install mysql"echo "ok" elseecho "no install mysql" #創件yum倉庫echo -e "[mysql57-community]\nname=MySQL 5.7 Community Server\nbaseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/local.repoyum clean all && yum makecache &> /dev/nullyum install -y php php-xml php-json mysql-community* &> /dev/nullsystemctl enable mysqld --nowb=`ss -nulpt | grep 3306 | awk -F: '/tcp/{print $4}'`if [ ${b} == 3306 ];thenecho "install mysql"if [ $? == 0 ];thenecho "ok"mysqladmin -uroot -p`grep -i password /var/log/mysqld.log | awk 'NR==1{print $11}'` password NSD2021@tedu.cnecho "passwd is ok"elseecho "no"fifi fi unset a b }#下載nginx nginx () { ls nginx-1.5.7.tar.gz >> /dev/null if [ $? == 0 ];thenecho "install ok" elseecho "no install"yum -y install wget tar >> /dev/nullwget http://nginx.org/download/nginx-1.5.7.tar.gzls nginx-1.5.7.tar.gzif [ $? == 0 ];thenecho "ok"elseecho "on"fi fi }#安裝nginx nginx_install () { ls /usr/local/nginx >> /dev/null if [ $? == 0 ];thenecho "install ok" elseecho "no install"for i in php-fpm php-mysql gcc pcre-devel zlib-develdoyum install -y $idonetar xf nginx-1.5.7.tar.gzcd nginx-1.5.7 && ./configuremake && make installsystemctl enable php-fpm --now fi }#更改配置文件支持動態服務 wen () { cp nginx.conf /usr/local/nginx/conf/nginx.conf /usr/local/nginx/sbin/nginx -t if [ $? == 0 ];thenecho "ok" elseecho "no" fi }#服務設置 service () { read -p "請輸入你要起的服務[nginx,php-fpm]:" q case $q in php)read -p "請輸入start,restart,stop:" icase $i instart)systemctl start php-fpm;;restart)systemctl restart php-fpm;;stop)systemctl stop php-fpm;;*)echo "輸入錯誤請重新輸入start,restart,stop"esacecho "設置成功";; firewalld)read -p "請輸入start,restart,stop:" icase $i instart)systemctl start firewalld;;restart)systemctl restart firewalld;;stop)systemctl stop firewalld;;trusted)firewall-cmd --set-default-zone=trusted;;*)echo "輸入錯誤請重新輸入start,restart,stop"esacecho "設置成功";; nginx)read -p "請輸入start,restart,stop:" icase $i instart)/usr/local/nginx/sbin/nginx;;restart)/usr/local/nginx/sbin/nginx -s reload;;stop)/usr/local/nginx/sbin/nginx -s stop;;*)echo "輸入錯誤請重新輸入start,restart,stop"esacecho "設置成功";; selinux)setenforce 0sed -i '/SELINUX/s/enforcing/permissive/' /etc/selinux/config;; *)echo "請重新輸入你要起的服務[nginx,php-fpm,firewalld,selinux]";; esac }#上線服務 html () { read -p "請輸入mysql_bbs,wordpress:" i case $i in wordpress)cdunzip wordpress.zipcd wordprestar -xf wordpress-5.0.3-zh_CN.tar.gzcp -r wordpress/* /usr/local/nginx/html/chown -R apache.apache /usr/local/nginx/html/;; mysql_bbs)cp -r /root/php_mysql_bbs/* /usr/local/nginx/html/;; *)echo "請重新輸入你要起的服務[mysql_bbs,wordpress]";; esac }總結
以上是生活随笔為你收集整理的shell脚本安装mysql并安装一个小服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux远程跳板机超时
- 下一篇: Logstash完成ELK集群