Shell脚本一键部署——源码编译安装LAMP架构!

文章目录

一、Shell脚本源码编译安装一键部署LAMP架构(使用source执行脚本)source 使shell脚本里的设置对其它shell也有效。

二、理论部分请看LAMP源码安装图文详解(超详细)

1、将所有安装包全拖入/opt目录下

安装包链接

LAMP安装包
提取码: ewss
Shell脚本一键部署——源码编译安装LAMP架构!_第1张图片

2、写一个shell脚本,将下面内容复制进去

Shell脚本一键部署——源码编译安装LAMP架构!_第2张图片

3、source或者. 执行脚本

在这里插入图片描述

4、输入你需要配置域名,输入完等待自动部署完成即可

在这里插入图片描述

 #!/bin/bash

read -p "请输入你需要配置的域名(例:www.abc.com):" y
df -h | grep /mnt
if [ $? -ne 0 ];then 
  mount /dev/sr0 /mnt > /dev/null
else
  echo "镜像文件已挂载"
fi


systemctl stop firewalld
systemctl disable firewalld
setenforce 0

yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl

cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2

mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

make && make install

ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/


echo '[Unit]
Description=The Apache HTTP Server            
After=network.target                        
[Service]
Type=forking                                
PIDFile=/usr/local/httpd/logs/httpd.pid        
ExecStart=/usr/local/bin/apachectl $OPTIONS    
ExecReload=/bin/kill -HUP $MAINPID            
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/httpd.service




cp /etc/httpd.conf{,.bak}

z=`ip a | grep "ens33" | awk 'NR==2{print}' | awk -F "/" '{print$1}' | awk -F " " '{print$2}'`

sed -i "51c Listen $z:80" /etc/httpd.conf.bak
sed -i '52 s/^/#/' /etc/httpd.conf.bak

sed -i '197d' /etc/httpd.conf.bak
sed -i "196a ServerName $y:80" /etc/httpd.conf.bak

cat /etc/httpd.conf.bak > /etc/httpd.conf




 
#sed -i "s/Listen 80/Listen 192.168.184.30:80/" /etc/httpd.conf
#sed -i 's/#ServerName www.example.com:80/ServerName www.lic.com:80/' /etc/httpd.conf

systemctl start httpd.service
netstat -anpt | grep 80
echo -e "033[31m Apache安装完成!033[0m"





#--------编译安装mysql 服务--------
#mysql-5.7.17.tar.gz
#boost_1_59_0.tar.gz
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
echo "进行安装mysql服务"
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

#配置软件模块
cd /opt
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz
cd /opt
mv boost_1_59_0 /usr/local/boost


cd /opt/mysql-5.7.17/
cmake 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
-DSYSCONFDIR=/etc 
-DSYSTEMD_PID_DIR=/usr/local/mysql 
-DDEFAULT_CHARSET=utf8  
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_EXTRA_CHARSETS=all 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 
-DMYSQL_DATADIR=/usr/local/mysql/data 
-DWITH_BOOST=/usr/local/boost 
-DWITH_SYSTEMD=1

make 
make install

useradd -M -s /sbin/nologin mysql

echo '[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]                                    
user = mysql                                   
basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

port = 3306                                    
character-set-server=utf8    

pid-file = /usr/local/mysql/mysqld.pid

socket=/usr/local/mysql/mysql.sock

bind-address = 0.0.0.0

skip-name-resolve                            
max_connections=2048

default-storage-engine=INNODB                
max_allowed_packet=16M    
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf




cd /usr/local/mysql/bin/
./mysqld 
--initialize-insecure 
--user=mysql 
--basedir=/usr/local/mysql 
--datadir=/usr/local/mysql/data

#添加mysqld系统服务

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/        #用于systemctl服务管理
source /etc/profile
systemctl daemon-reload         #刷新识别     
systemctl start mysqld.service  #开启服务
systemctl enable mysqld         #开机自启动
netstat -anpt | grep 3306       #查看端口

yum -y install expect


function abc {
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:" 
send "r"

expect eof
EOF
}
abc "abc123"


function bcd {
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {send "abc123r"}
expect "mysql>" {send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';r"}
expect "mysql>" {send "show databases;r"}
expect "mysql>" {send "quitr"}
expect eof
EOF
}
bcd
echo -e "033[31m mysql安装完成!033[0m"


#--------编译安装PHP 解析环境--------
#安装GD库和GD库关联程序,用来处理和生成图片
yum -y install 
gd 
libjpeg libjpeg-devel 
libpng libpng-devel 
freetype freetype-devel 
libxml2 libxml2-devel 
zlib zlib-devel 
curl curl-devel 
openssl openssl-devel

#配置软件模块
cd /opt
tar jxvf php-7.1.10.tar.bz2
cd /opt/php-7.1.10/

./configure 
--prefix=/usr/local/php7 
--with-apxs2=/usr/local/httpd/bin/apxs 
--with-mysql-sock=/usr/local/mysql/mysql.sock 
--with-config-file-path=/usr/local/php7 
--with-mysqli 
--with-zlib 
--with-curl 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--with-openssl 
--enable-mbstring 
--enable-xml 
--enable-session 
--enable-ftp 
--enable-pdo 
--enable-tokenizer 
--enable-zip

#编译及安装
make && make install

#复制模版文件作为PHP 的主配置文件,并进行修改
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini    

#在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件

#修改1170行为mysqli.default_socket = /usr/local/mysql/mysql.sock
sed -i '1170d' /usr/local/php7/php.ini
sed -i '1169a mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php7/php.ini

#939行--取消注释,修改时区
sed -i '939d' /usr/local/php7/php.ini
sed -i '938a date.timezone = Asia/Shanghai' /usr/local/php7/php.ini

#优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/php7/bin/* /usr/local/bin/

php -m             #查看PHP 加载了哪些模块

#修改httpd 服务的配置文件:/etc/httpd.conf,让apache支持PHP

#--393行下--插入以下内容
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

cp /etc/httpd.conf{,.bak1}
sed -i '393a AddType application/x-httpd-php .php' /etc/httpd.conf.bak1
sed -i '394a AddType application/x-httpd-php-source .phps' /etc/httpd.conf.bak1

#--256行--修改首页文件名设置
#DirectoryIndex index.html index.php
sed -i '256c DirectoryIndex index.html index.php' /etc/httpd.conf.bak1

cat /etc/httpd.conf.bak1 > /etc/httpd.conf


#验证php测试页
cd /usr/local/httpd/htdocs
mv index.html index.html.bak
echo '' > /usr/local/httpd/htdocs/index.php

#修改完httpd配置文件后重启服务
systemctl restart httpd.service
systemctl restart httpd.service

#浏览器访问

echo -e "033[31m php安装完成!033[0m"

你可能感兴趣的:(linux,mysql)