centos7 yum安装lnmp环境

#!/bin/bash
MYSQL_PASSWD="Ab123456!"

function yum_update() {
    cd /etc/yum.repos.d/
    mkdir bak && cp ./*.repo bak
    yum install -y wget 
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum install -y epel-release lrzsz zip unzip git gcc gcc-c++ yum-utils tmux screen net-tools vim tree telnet rsync harfbuzz
}

function install_nginx() {
    yum -y install nginx
    systemctl start nginx
    systemctl enable nginx
}

function install_mysql(){
    cat >/etc/yum.repos.d/mysql-community.repo <<-EOF
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
EOF

    yum list installed | grep -w yum-utils &>/dev/null
    [ $? -ne 0 ] && yum install yum-utils -y
    yum-config-manager --disable mysql-8.0-community
    yum-config-manager --enable mysql-5.7-community

    yum install -y mysql-community-server
    systemctl start mysqld
    systemctl enable mysqld

    passwd=$(grep 'temporary password' /var/log/mysqld.log|tail -n 1|awk '{print $NF}')
    mysql --connect-expired-password -uroot -p${passwd} <<-EOF
ALTER USER root@'localhost' IDENTIFIED BY '${MYSQL_PASSWD}';
flush privileges;
EOF

    sleep 1
    systemctl restart mysqld
}

function install_php(){
    rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
    yum install -y --enablerepo=remi --enablerepo=remi-php56 php php-fpm php-opcache php-devel php-mbstring \
php-mcrypt php-mysqlnd  php-pecl-xdebug php-pecl-xhprof php-gd php-bcmath
    systemctl start php-fpm
    systemctl enable php-fpm

}

function main(){
    yum_update
    install_nginx
    install_mysql
    install_php
}

main
posted @ 2021-04-22 10:48  城市炊烟  阅读(139)  评论(0编辑  收藏  举报