脚本安装LAMP

脚本安装LAMP
自备以下软件包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
  apr-1.6.5.tar.bz2   apr-util-1.6.1.tar.bz2  debug   httpd-2.4.54.tar.bz2  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  php-7.4.30.tar.xz
[root@localhost opt]# ls
 Discuz_X3.4_SC_UTF8_20220811.zip
[root@localhost ~]# vim LAMP.sh 
#!/bin/bash
# 安装yum源和epel源
cd /etc/yum.repos.d/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

# 安装工具包
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ --allowerasing

# 安装apr
cd /usr/src/
tar -xjf apr-1.6.5.tar.bz2
cd apr-1.6.5/
sed -i '/$RM "$cfgfile"/d' configure
# 编译安装apr
./configure --prefix=/usr/local/apr &> /dev/null
make &> /dev/null
make install &> /dev/null
# 安装apr-util
cd /usr/src/
tar -xjf apr-util-1.6.1.tar.bz2
cd apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make &> /dev/null
make install &> /dev/null
# 安装httpd
cd /usr/src/
tar -xjf httpd-2.4.54.tar.bz2
cd httpd-2.4.54/
./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
make &> /dev/null
make install &> /dev/null
# 配置环境变量
cd /root
echo 'export PATH=/usr/local/apache/bin/:$PATH' > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
# 编写systemctl配置文件
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.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
# 加载文件并启动服务
systemctl daemon-reload
systemctl enable --now httpd.service
#/usr/local/apache/bin/apachectl start
# 配置防火墙
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
#安装MySQL
#关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
#临时关闭selinux
setenforce 0
#永久关闭selinux
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
echo "防火墙配置完成"
#安装依赖包
dnf -y install ncurses-devel openssl-devel openssl cmake ncurses-compat-libs  &>/dev/null
echo "依赖包安装完成"
#创建用户
id mysql &>/dev/null
if [ $? -eq 0 ];then
	echo "用户存在"
else
	useradd -M -r -s /sbin/nologin/ mysql
fi
echo "用户创建完成"
#解压软件包
cd /usr/src/
tar -xzf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ &>/dev/null
cd /usr/local/
ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
chown -R mysql.mysql /usr/local/mysql
echo "安装包完成"
#配置环境变量
echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
ln -s /usr/local/mysql/include/ /usr/include/mysql
echo '/usr/local/mysql/bin/' > /etc/ld.so.conf.d/mysql.conf
source /etc/profile.d/mysql.sh
ldconfig
echo "环境变量配置完成"
#创建数据存放目录
mkdir /opt/data
chown -R mysql.mysql /opt/data/
echo "创建完成"
#初始化数据库
mysqld --initialize-insecure --user=mysql --datadir=/opt/data/ &>/dev/null
echo "初始化完成"
#修改配置文件
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
echo "配置完成"
#配置systemd启动服务
cat > /usr/lib/systemd/system/mysqld.service <<EOF
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

[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
systemctl start mysqld.service
echo "启动服务"
#修改密码
read -p "输入设置的数据库密码:" sb
mysql -uroot -e "set password = password('"$sb"')"
echo "修改完成"

#安装php和论坛
#安装依赖包
dnf -y install libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd --nobest 
dnf -y install libzip-devel sqlite-devel lidxml2-devel 
dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm 
echo "依赖包安装完成"
#解压源码包
cd /usr/src/
tar -Jxf php-7.4.30.tar.xz -C /usr/local/ &>/dev/null
cd  /usr/local/php-7.4.30
#编译源码包
./configure --prefix=/usr/local/php7  \
 --with-config-file-path=/etc \
 --enable-fpm \
 --enable-inline-optimization \
 --disable-debug \
 --disable-rpath \
 --enable-shared \
 --enable-soap \
 --with-openssl \
 --enable-bcmath \
 --with-iconv \
 --with-bz2 \
 --enable-calendar \
 --with-curl \
 --enable-exif  \
 --enable-ftp \
 --enable-gd \
 --with-jpeg \
 --with-zlib-dir \
 --with-freetype \
 --with-gettext \
 --enable-json \
 --enable-mbstring \
 --enable-pdo \
 --with-mysqli=mysqlnd \
 --with-pdo-mysql=mysqlnd \
 --with-readline \
 --enable-shmop \
 --enable-simplexml \
 --enable-sockets \
 --with-zip \
 --enable-mysqlnd-compression-support \
 --with-pear \
 --enable-pcntl \
 --with-apxs2=/usr/local/apache/bin/apxs
 --enable-posix &>/dev/null
#编译安装
make &>/dev/null
make install &>/dev/null
echo "编译安装完成"
#配置环境变量
echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
cd /usr/local/php7/
ln -s /usr/local/php7/include/ /usr/include/php7
echo '/usr/local/php7/lib/' > /etc/ld.so.conf.d/php7.conf
ldconfig
source /etc/profile.d/php7.sh
#配置php-fpm
cd /usr/local/php7
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#配置systemd启动php-fpm
cat > /usr/lib/systemd/system/php-fpm.service <<EOF
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm  start
ExecStop=/etc/init.d/php-fpm  stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start php-fpm.service
systemctl enable php-fpm.service
echo "启动成功"
#启用httpd的相关模块
sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
#创建虚拟主机目录并生成php测试页面
useradd -M -r -s /sbin/nologin/ apache
cd /usr/local/apache/htdocs/
rm -rf *
cat > index.php <<EOF
<?php
   phpinfo();
?>
EOF
chown -R apache.apache /usr/local/apache/htdocs/
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 '/DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf
echo "配置完成"
#重启服务
systemctl restart httpd.service
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
echo "部署完成"
mysql -uroot -p123456  -e 'create database bbs;'
mysql -uroot -p123456  -e "grant all on bbs.* to 'bbsuser'@'%' identified by '123456';"
mysql -uroot -p123456  -e 'flush privileges;'
#解压论坛压缩包
dnf -y install unzip
unzip /opt/Discuz_X3.4_SC_UTF8_20220811.zip -d /opt/dis &>/dev/null
cd /opt/dis
cp -r upload/ /usr/local/apache/htdocs/bbs
#更改论坛目录的属主
cd /usr/local/apache/htdocs/bbs
chown -R daemon ./config
chown -R daemon ./data
chown -R daemon ./uc_client
chown -R daemon ./uc_server/data
systemctl restart httpd.service
echo "论坛部署完成"
[root@localhost ~]# source LAMP.sh 
......

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值