一鍵部署lnmp指令碼

2022-07-13 01:09:14 字數 2961 閱讀 3620

#!/bin/bash

#關閉防火牆和selinux

systemctl stop firewalld && setenforce 0 && echo "防火牆已關閉" || echo "請手動檢查"

systemctl disable firewalld &> /dev/null

echo ">>> 1.nginx 安裝進行中 ......"

#是否安裝常用工具

read -p "是否安裝常用工具:" num

case $num in

y)yum install -y sysstat elinks net-tools bash-completion

echo "安裝完成"

;;n)

break

;;*)

echo "請輸入正確選項"

exit

;;esac

echo ">>> 2.正在載入yum源"

nginxflie="/etc/yum.repos.d/nginx.repo"

if [ ! -f $nginxfile ];then 

touch /etc/yum.repos.d/nginx.repo

else

echo "檔案已存在"

fi#新增nginx.repo源

cat>/etc/yum.repos.d/nginx.repo<#重新整理yum庫

yum makecache fast &> /dev/null

if [ $? -eq 0 ];then

echo "重新整理成功"

fi#安裝nginx並啟動

rpm -qa | grep nginx &> /dev/null

if [ $? -ne 0 ];then

yum -y install nginx

systemctl start nginx

systemctl enable nginx

fisystemctl status nginx

if [ $? -ne 0 ];then

systemctl start nginx

systemctl enable nginx &> /dev/null

echo "啟動成功"

fi#安裝mysql

echo ">>> 3.正在公升級mysql源"

rpm -uvh

mysql -v &> /dev/null

if [ $? -ne 0 ];then

yum -y install mysql-community-server

systemctl start mysqld

systemctl enable mysqld

fisystemctl status mysqld

if [ $? -ne 0 ];then

systemctl start mysql-community-server

systemctl enable mysqld

fisleep 3

echo ">>> 4.配置mysql檔案"

echo "如有不明白,請參考:"

echo "輸出初始密碼:`grep 'temporary password' /var/log/mysqld.log | awk -f ' ' ''`"

echo "請記住密碼!!!"

sleep 4

echo "執行命令配置mysql的安全性"

echo "正在進入互動式設定,請按照自己的需要配置"

mysql_secure_installation

echo ">>> 5.安裝php ......"

echo "新增epel源"

yum -y install \

\echo "新增webtatic源"

rpm -uvh

echo "安裝php以及依賴包"

yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb

if [ $? -ne 0 ];then

echo "請檢查指令碼" || exit 4;

fiecho ">>> 5.正在配置nginx檔案"

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

cat > /etc/nginx/conf.d/php.conf << eof

server

location ~ .php$

}eof

#測試網頁

echo ">>> 6.啟動php"

systemctl status php-fpm

if [ $? -ne 0 ];then

systemctl start php-fpm

systemctl enable php-fpm

fiif [ -f /usr/share/nginx/html/phpinfo.php ];then

echo "檔案已存在"

else

echo "<?php echo phpinfo(); ?>" > /usr/share/nginx/html/phpinfo.php

systemctl reload nginx

fiecho "部署已經完成!!!!瀏覽器:http://localhost/phpinfo.php"

###看完指令碼!有需要的改

shell指令碼一鍵部署LNMP

author create date 2020 07 15 01 52 version mail description bin bash mysql的原始碼安裝 read p 即將進行mysql原始碼安裝,請問是否進行 y n speed case speed in y mysqld yes my...

一鍵部署LNMP

一鍵部署dhcp dns lamp mysql samba nfs ntp sed 處理文字內容 學習方法 主要學習選項和條件 思路 sed是要替換vim的 語法結構 1.前置命令 sed 選項 條件指令 2.sed 選項 條件指令 檔案 1.條件可以是行號或者 正則 2.沒有條件是預設所有條件 3...

LNMP環境一鍵部署

1 bin bash 2 用於安裝lnmp環境 34 d software mkdir software56 功能選擇選單 7menu 2829 0 安裝依賴包 30install package 5455 1 編譯安裝nginx 56install nginx 131132 2 原始碼編譯安裝my...