LAMP架构一件脚本部署教程

一、编写http一键部署脚本

1、导入数据包
2、编写shell脚本

#!/bin/bash
#使用的安装方法为编译安装
#需要apr-1.6.2.tar.gz  apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2包
#需要用 source apche.sh 来执行脚本
yum -y install bzip2-devel.x86_64
cd /opt/
tar xf apr-1.6.2.tar.gz
tar xf apr-util-1.6.0.tar.gz
tar xf httpd-2.4.29.tar.bz2

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

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

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/
cd /lib/systemd/system/
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
ExecrReload= /bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target" > httpd.service

systemctl start httpd.service
systemctl enable httpd.service
systemctl is-enabled httpd.service

netstat -anptu |grep httpd
:

二、编写mysql一键部署脚本

1、导入数据包
2、编写shell脚本

#!/bin/bash
#安装mysql数据库,上传mysql-boost-5.7.20.tar.gz
#需要使用source mysql.sh 执行脚本
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

useradd -s /sbin/nologin  mysql

cd /opt
tar xf mysql-boost-5.7.20.tar.gz
cd /opt/mysql-5.7.20/

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_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=boost \
-DWITH_SYSTEMD=1

make && make install
chown -R mysql:mysql /usr/local/mysql/
echo ' 
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
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
server-id = 1 ' > /etc/my.cnf

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


chown mysql:mysql /etc/my.cnf
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306

yum -y install expect.x86_64
/usr/bin/expect <<-EOF
spawn  mysqladmin -u root -p password 123456
expect {
		"Enter password:" {send "\r"}
}
expect eof
EOF
/usr/bin/expect <<-EOF
spawn  mysql -u root -p
expect {
		"Enter password:" {send "123456\r"}
}
expect eof
EOF

三、编写php一键部署脚本

1、导入数据包
2、编写shell脚本

#!/bin/bash
#安装php,需要source php.sh来执行
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

cd /opt
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--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

cp  php.ini-development /usr/local/php/lib/php.ini
sed -i -e "s/mysqli.default_socket =/ /g" /usr/local/php/lib/php.ini
a="mysqli.default_socket = /usr/local/mysql/mysql.sock"
sed -i -e "/mysqli.default_port = 3306/a$a" /usr/local/php/lib/php.ini

sed -i -e "s/^;date.timezone =/ /g" /usr/local/php/lib/php.ini
b="date.timezone = Asia/Shanghai"
sed -i -e "/date.timezone$/a$b" /usr/local/php/lib/php.ini

echo "AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps" >> /etc/httpd.conf

sed -i -e "s/DirectoryIndex index.html/DirectoryIndex index.php index.html / g" /etc/httpd.conf 

rm -f /usr/local/httpd/htdocs/index.html

echo '<?php
phpinfo();
?> ' > /usr/local/httpd/htdocs/index.php


systemctl restart httpd

五、测试效果

在这里插入图片描述

六、如果需要下载数据包请参考上一篇LAMP搭建文章

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值