一键部署lamp

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 一键部署lamp脚本
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
#-------Apache------
#安装依赖包
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 -j 2 && make install
#优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
#添加httpd系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
sed -i '1i #!/bin/bash' /etc/init.d/httpd
sed -i '1a #chkconfig: 35 85 21' /etc/init.d/httpd
sed -i '1a # description: Apache is a World Wide Web server' /etc/init.d/httpd
chkconfig --add httpd
systemctl start httpd.service
#修改httpd 服务配置文件
cp /usr/local/httpd/conf/httpd.conf /usr/local/httpd/conf/httpd.conf.bak
sed -i '52c Listen 192.168.80.13:80(IP根据实际情况)' /usr/local/httpd/conf/httpd.conf
sed -i '198c ServerName www.kgc.com:80(自定)' /usr/local/httpd/conf/httpd.conf
systemctl restart httpd
#--------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
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 -j 2 && make install
#创建mysql用户
useradd -M -s /sbin/nologin  mysql
#修改mysql 配置文件
rm -rf /etc/my.cnf
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
auto-rehash
[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
#更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
#设置路径环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$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
#添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
yum -y install expect
mima () {
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:"
send "\r"
expect eof
EOF
}
mima "123456"
dl () {
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {send "123456\r"}
expect "mysql>" {send "grant all privileges on *.* to 'root'@'%' identified by '123456';\r"}
expect "mysql>" {send "quit\r"}
expect eof
EOF
}
dl
#-------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 -j 2 && make install
#复制模版文件作为PHP 的主配置文件,并进行修改
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
sed -i '1170c mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php7/php.ini
sed -i '939d' /usr/local/php7/php.ini
sed -i '939i date.timezone = Asia/Shanghai' /usr/local/php7/php.ini
#优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/php7/bin/* /usr/local/bin/
#修改httpd 服务的配置文件,让apache支持PHP
sed -i '393i AddType application/x-httpd-php .php'  /usr/local/httpd/conf/httpd.conf
sed -i '393i AddType application/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf
sed -i '256c DirectoryIndex index.html index.php' /usr/local/httpd/conf/httpd.conf
#验证PHP测试页
rm -rf /usr/local/httpd/htdocs/index.html
echo '<?php
phpinfo();
?>' > /usr/local/httpd/htdocs/index.php
systemctl restart httpd.service
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
弹性计算 关系型数据库 MySQL
快速搭建LAMP环境
CentOS 7.7的ECS实例(云服务器)。通过本教程的操作,您可以基于ECS实例快速搭建一套LAMP环境。
359 0
快速搭建LAMP环境
|
关系型数据库 MySQL Apache
搭建LAMP环境
新手一起来学啊!!!
385 0
搭建LAMP环境
|
弹性计算 关系型数据库 MySQL
|
关系型数据库 MySQL 测试技术
LAMP环境
配置环境
|
关系型数据库 MySQL PHP
|
Web App开发 关系型数据库 测试技术
|
关系型数据库 MySQL PHP
|
关系型数据库 MySQL PHP
|
关系型数据库 测试技术 PHP
|
关系型数据库 MySQL PHP
下一篇
无影云桌面