[root@node1 ~]# yum -y install lrzsz
//先将包文件拖进来
[root@node1 ~]# cd /opt/
[root@node1 opt]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz php-8.2.5.tar.gz
[root@node1 ~]# cd /
[root@node1 ~]# vim lamp.sh
//在里面写入以下内容
#!/bin/bash
#安装工具包
echo "正在安装需要的工具包,请稍等..."
yum -y install bzip2 vim make wget openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel &>/dev/null
echo "安装完成"
#解压apr包
echo "解压apr包文件"
cd /opt
tar -zxvf apr-1.7.0.tar.gz -C /usr/local/ &>/dev/null
tar -zxvf apr-util-1.6.1.tar.gz -C /usr/local &>/dev/null
#安装apr包
cd /usr/local/apr-1.7.0/
sed -i '/$RM "$cfgfile"/d' configure
echo "正在编译安装apr,请耐心等待..."
./configure --prefix=/usr/local/apr &> /dev/null
make &> /dev/null
make install &> /dev/null
echo "apr安装完成"
#安装apr-util
cd /usr/local/apr-util-1.6.1/
echo "正在编译安装apr-util,请耐心等待..."
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &> /dev/null
make &> /dev/null
make install &> /dev/null
echo "apr-util安装完成"
#安装httpd
echo "正在解压httpd源码包"
cd /opt
tar -zxvf httpd-2.4.54.tar.gz &>/dev/null
echo “httpd源码包解压完成”
cd /opt/httpd-2.4.54
echo "正在编译安装httpd,请耐心等待..."
./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork &>/dev/null
make &> /dev/null
make install &> /dev/null
cd
echo "httpd安装完成"
#配置systemctl管理httpd
echo "正在配置systemctl管理httpd"
# 定义服务单元文件路径
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
echo "启动httpd服务"
systemctl restart httpd
systemctl enable httpd
#部署lamp-mysql
echo "-----正在部署mysql-----"
#创建mysql用户
echo "正在验证mysql用户..."
id mysql &> /dev/null
if [ $? -eq 0 ];then
echo "mysql用户已存在"
else
echo "正在创建mysql用户..."
useradd -r -M -s /sbin/nolgin mysql
echo "mysql用户创建成功"
fi
#安装依赖包
echo "正在安装依赖包..."
yum -y install libncurses* &> /dev/null
echo "安装完成"
#配置mysql
echo "正在配置mysql..."
tar -zxvf /opt/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ &> /dev/null
ln -sv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql &> /dev/null
chown -R mysql.mysql /usr/local/mysql &> /dev/null
mkdir -p /opt/data &> /dev/null
chown -R mysql.mysql /opt/data/ &> /dev/null
yum -y install libaio &> /dev/null
#数据库初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/ &> /dev/null
ln -sv /usr/local/mysql/include/ /usr/local/include/mysql &> /dev/null
echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf &> /dev/null
ldconfig &> /dev/null
#编辑mysql配置文件
cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
sed -ri "s#^(basedir=).*#\1/usr/local/mysql#g" /usr/local/mysql/support-files/mysql.server
sed -ri "s#^(datadir=).*#\1/opt/data#g" /usr/local/mysql/support-files/mysql.server
#定义mysql服务可以使用systemd来进行管理
cat > /usr/lib/systemd/system/mysqld.service <<EOF
[Unit]
Description=mysql server daemon
After=network.targe
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && echo "*****重新加载成功*****"
systemctl enable --now mysqld && echo "*****开机自启mysql成功*****"
#设置数据库密码
read -p "请输入您要设置的数据库密码:" mysql_password
/usr/local/mysql/bin/mysql -uroot -e "set password=password('$mysql_password')"
#做一个链接,添加mysql命令的变量到环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
echo "-----mysql部署完成-----"
#部署lamp-php
#安装依赖包,安装GD库和GD库关联程序,用来处理和生成图片
echo "正在安装依赖包"
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel &>/dev/null
yum -y install wget gcc gcc-c++ autoconf automake libtool make libxml2 libxml2-devel openssl openssl-devel sqlite-devel libpng libpng-devel libpsl libpsl-devel libicu-devel libcurl-devel &> /dev/null
yum -y install openldap openldap-devel &>/dev/null
cp -frp /usr/lib64/libldap* /usr/lib/
yum --enablerepo=devel -y install oniguruma-devel &>/dev/null
echo "依赖包已经安装完成"
#解压php包文件
cd /opt
tar -zxvf php-8.2.5.tar.gz &>/dev/null
echo "解压php包文件成功"
#配置编译安装php
cd php-8.2.5
echo "正在配置php"
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql-sock=/tmp/mysql.sock \
--enable-fpm \
--enable-mysqlnd \
--enable-mysqlnd-compression-support \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-ftp \
--enable-gd-jis-conv \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--with-gettext \
--enable-fileinfo \
--enable-opcache \
--with-pear \
--with-ldap=shared \
--without-gdbm \
--with-curl \
--enable-ctype \
--without-pear --disable-phar &>/dev/null
echo "正在编译安装php"
make &>/dev/null
make install &>/dev/null
echo "php编译安装完成"
#配置php
echo "正在配置php"
#测试环境时使用php.ini-development文件,生产环境使用php.ini-production文件
cp php.ini-development /usr/local/php/lib/php.ini
#修改php配置文件,设置时区
sed -i 's/;date.timezone =/date\.timezone = \Asia\/Shanghai/' /usr/local/php/lib/php.ini
#修改httpd服务配置文件,让apache支持php
echo "AddType application/x-httpd-php .php" >> /etc/httpd24/httpd.conf
echo "AddType application/x-httpd-php-source .phps" >> /etc/httpd24/httpd.conf
sed -i 's/index.html/index\.php index\.html/' /etc/httpd24/httpd.conf
#验证php测试页
rm -f /usr/local/apache/htdocs/index.html
cat > /usr/local/apache/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
echo "php配置完成"
#启动apache服务
/usr/local/apache/bin/apachectl restart
echo "lamp部署完成"
[root@node1 ~]# chmod +x lamp.sh
[root@node1 ~]# ./lamp.sh
正在安装需要的工具包,请稍等...
安装完成
解压apr包文件
正在编译安装apr,请耐心等待...
apr安装完成
正在编译安装apr-util,请耐心等待...
apr-util安装完成
正在解压httpd源码包
“httpd源码包解压完成”
正在编译安装httpd,请耐心等待...
httpd安装完成
正在配置systemctl管理httpd
启动httpd服务
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
-----正在部署mysql-----
正在验证mysql用户...
正在创建mysql用户...
useradd: Warning: missing or non-executable shell '/sbin/nolgin'
mysql用户创建成功
正在安装依赖包...
安装完成
正在配置mysql...
*****重新加载成功*****
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
*****开机自启mysql成功*****
请输入您要设置的数据库密码:redhat
-----mysql部署完成-----
正在安装依赖包
依赖包已经安装完成
解压php包文件成功
正在配置php
正在编译安装php
php编译安装完成
正在配置php
php配置完成
lamp部署完成
标签:脚本,shell,--,null,dev,echo,lamp,mysql,php
From: https://blog.csdn.net/q911326/article/details/142028114