l是linux,a是apache,m是mysql,p是php。最基本的动态网页搭建。语法后面再补几篇,现在先写吧。
一、环境准备
1.1、rocklinux换源,关掉防火墙,selinux,时间同步
#cp rocky* /a
# 阿里
sed -e 's|^#mirrorlist=|mirrorlist=|g' \
-e 's|^baseurl=https://mirrors.aliyun.com/rockylinux|#baseurl=http://dl.rockylinux.org/$contentdir|g' \
-i.bak \
/etc/yum.repos.d/rocky*.repo
# 中科大
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/rocky|g' \
-i.bak \
/etc/yum.repos.d/rocky-extras.repo \
/etc/yum.repos.d/rocky.repo
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/song5bai/article/details/132566228
#yum config-manager --set-enabled crb 开启crb为Complete Releasabld Binding完全可释放绑定,轻松解决绑定或链接机制
#yum -y install epel-release 安装epel源,解决一些依赖关系
#yum -y install vim 安装vim
#yum -y install bash-completion 安装自动补齐
防火墙,selinux,网卡的uuid删掉,移除
二、编写脚本,全部编译安装
yum -y install chrony lrzsz tar unzip
systemctl restart chronyd
systemctl enable chronyd
hwclock -w
#vim b.sh
#!/bin/bash
# 部署lamp-apache
# 安装需要的工具包
echo "正在安装需要的工具包,请稍等..."
yum -y install bzip2 vim make wget openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel &>/dev/null
echo "工具包安装完成"
#解压并安装apr包
cd /opt
tar -xzf apr-1.7.0.tar.gz &>/dev/null
cd /opt/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 /opt
tar -xzf apr-util-1.6.1.tar.gz &>/dev/null
cd /opt/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
cd /opt
tar -xzf httpd-2.4.54.tar.gz &>/dev/null
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安装完成"
#定义httpd服务可以使用systemd来进行管理
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=mysql server daemon
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
systemctl daemon-reload &>/dev/null
systemctl restart httpd &>/dev/null
systemctl enable httpd &>/dev/null
echo "httpd service complete"
#部署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 -xzf /opt/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
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.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 && 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 install -y 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
yum install openldap openldap-devel -y
cp -frp /usr/lib64/libldap* /usr/lib
yum install oniguruma oniguruma-devel -y
yum --enablerepo=devel -y install oniguruma-devel
echo "依赖包已经安装完成"
cd /opt
tar -xzvf php-8.3.9.tar.gz &>/dev/null
echo "解压php包文件成功"
cd /opt/php-8.3.9
./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
echo "正在编译安装php"
make
make install
echo "php编译安装完成"
#验证php测试页
rm -rf /usr/local/apache/htdocs/index.html
cat > /usr/local/apache/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
echo "php配置完成"
#配置php
echo "正在配置php"
#测试环境时使用php.ini-development文件,生产环境使用php.ini-production文件
cp /opt/php-8.3.9/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
#启动apache服务
systemctl restart httpd &>/dev/null
echo "lamp部署完成"
#chmod +x b.sh
#./bsh
[root@node3 ~]# source /etc/profile
[root@node3 ~]# systemctl restart httpd.service