centos7bash方式安装nginx-mysql-php

#!/bin/bash

#判断安装包是否成功

is_created(){

if ! type $1 >/dev/null 2>&1;

then

echo "no";

else

echo "yes";

fi

}

#安装nginx

create_nginx(){

is_create=$(is_created nginx);

if [ "$is_create" = "yes" ];

then

echo "nginx is already created";

return 0

fi

#第一次尝试安装

yum -y install nginx >/dev/null 2>&1

is_create=$(is_created nginx);

if [ "$is_create" = "no" ];

then

cat>/etc/yum.repos.d/nginx.repo<<EOF

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/

gpgcheck=0

enabled=1

EOF

fi

#第二次尝试安装

yum -y install nginx >/dev/null 2>&1

is_create=$(is_created nginx);

if [ "$is_create" = "yes" ];

then

echo "nginx is success created";

else

echo "nginx is fail created"

fi

}

#安装mysql

create_mysql(){

is_create=$(is_created mysql);

if [ "$is_create" = "yes" ];

then

echo "mysql is already created";

return 1

fi

yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm >/dev/null 2>&1

yum -y install mysql-community-server >/dev/null 2>&1

is_create=$(is_created mysql);

if [ "$is_create" = "yes" ];

then

echo "mysql is success created";

else

echo "mysql is fail created"

fi

}

#安装PHp

create_php(){

is_create=$(is_created php);

if [ "$is_create" = "yes" ];

then

echo "php is already created";

return 1

fi

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm >/dev/null 2>&1

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm >/dev/null 2>&1

yum search php71w >/dev/null 2>&1

yum -y install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath >/dev/null 2>&1

is_create=$(is_created php);

if [ "$is_create" = "no" ];

then

echo "php is fail created";

return 1

fi

yum -y install php-redis >/dev/null 2>&1

echo "php is success created"

}

echo "begin create nginx"

nginx_result=$(create_nginx)

if [ "$nginx_result" = "nginx is success created" ] || [ "$nginx_result" = "nginx is already created" ];

then

echo $nginx_result

else

echo $nginx_result

exit 1

fi

echo "begin create mysql"

mysql_result=$(create_mysql)

if [ "$mysql_result" = "mysql is success created" ] || [ "$mysql_result" = "mysql is already created" ];

then

echo $mysql_result

echo "view first mysql password:"

echo "service mysqld start"

echo "grep 'temporary password' /var/log/mysqld.log"

echo "change mysql password:"

echo "mysql -uroot -p "

echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '#818VKa0au3#';"

echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '#818VKa0au3#' WITH GRANT OPTION;"

echo "after exec that,new password is '#818VKa0au3#'"

else

echo $mysql_result

exit 1

fi

echo "begin create php"

php_result=$(create_php)

if [ "$php_result" = "php is success created" ] || [ "$php_result" = "php is already created" ];

then

echo $php_result

else

echo $php_result

exit 1

fi

linux-定时任务

  • 12
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dadashitou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值