RHCSE--SHELL--LNMP+LAMP脚本实验

一、LAMP实验基本步骤:

1、下载所需软件:lrzsz、zip、httpd、mariadb-server、php、php-fpm、php-mysqlnd;

2、转换到httpd目录:cd /var/www/html/

3、将Discuz软件压缩包拖入该目录并解压:

root@shawn2 html\]# rz -E rz waiting to receive. \[root@shawn2 html\]# unzip Discuz_X3.5_SC_UTF8_20250901.zip ![](https://i-blog.csdnimg.cn/direct/7af8072bcc9c4f3cb26ec9ee7e0ad177.png) ![](https://i-blog.csdnimg.cn/direct/7519e7dea1f049d09b6c17e0efae4c85.png) 4、关闭防火墙和设置宽容模式: \[root@shawn2 html\]# systemctl stop firewalld.service \[root@shawn2 html\]# setenforce 0 5、开启httpd功能:\[root@shawn2 html\]# systemctl start httpd 6、给upload/目录下的文件添加权限: \[root@shawn2 upload\]# chmod -R 777 config/ data/ uc_\* 7、启用mariadb服务并创建一个luntan数据库 ![](https://i-blog.csdnimg.cn/direct/3a9b86c0d8e5417aa5c2cf336f1c39e0.png) ![](https://i-blog.csdnimg.cn/direct/13d74501f4d848578d598e0b7301d877.png) 8、在浏览器上部署好: ![](https://i-blog.csdnimg.cn/direct/d0282da622fa4d08b243f9f31709495f.png) ![](https://i-blog.csdnimg.cn/direct/5a512b60d34445199cbf8b77a6acfe23.png) ![](https://i-blog.csdnimg.cn/direct/5e1790dc51b040768a499185ba0c8c07.png)![](https://i-blog.csdnimg.cn/direct/b5beac0f933344dbaf11a969c9c06567.png)![](https://i-blog.csdnimg.cn/direct/9bba42a3308a49c5a564af57e5bb42a7.png)![](https://i-blog.csdnimg.cn/direct/caf526a0523a45c5b408356919107f33.png) ## (1)按照基本步骤写脚本 1.编写mysql.sh流程脚本: #!/bin/bash mysql_config() { mysql< /dev/null yum install lrzsz -y >/dev/null yum install zip -y >/dev/null } #配置http http() { #提前把论坛软件放到/root cp /root/Dis* /var/www/html cd /var/www/html unzip Discuz* >/dev/null && echo "解压成功" || echo "解压失败" cd upload/ chmod -R 777 config/ uc_* data } #配置数据库 #mysql() { #systemctl start mariadb.service #mysql< /dev/null \[root@shawn2 shell\]# yum remove lrzsz -y \>/dev/null \[root@shawn2 shell\]# yum remove zip -y \>/dev/null \[root@shawn2 shell\]# rm -rf /var/lib/mysql/(特别注意要删除,移除mariadb后会有文件残留) 也将/var/www/html/目录下的文件移除,重新在/root下创建一个新目录http,将脚本和论坛软件放入,把软件包也复制到/root下:\[root@shawn2 http\]# mv Discuz_X3.5_SC_UTF8_20250901.zip /root/ ![](https://i-blog.csdnimg.cn/direct/904e102edd834d52a631582ea9a5ee4a.png) **2.启用脚本:(http_start函数已删除,忽略)** ![](https://i-blog.csdnimg.cn/direct/70dda2e55cce43b6bba2d789419c6d02.png) **3.浏览器验证:** ![](https://i-blog.csdnimg.cn/direct/86b5c016fced42c1a506a03945d59fcd.png) ## 二、LNMP实验(恢复环境,关闭防火墙和设置宽容模式) **基础步骤:** 1.下载所需软件:zip、nginx、mariadb-server、php、php-fpm、php-mysqlnd; ![](https://i-blog.csdnimg.cn/direct/11b5dd42ec534d08880192d76c7ff709.png) #php-fpm.conf文件和php.conf文件载入server ![](https://i-blog.csdnimg.cn/direct/125174813fbf4b5a98a778e76f22c9ed.png) 2.在/root目录下创建一个/web目录,将软件包复制到下面: \[root@shawn2 \~\]# mkdir /web \[root@shawn2 \~\]# mv /root/Discuz_X3.5_SC_UTF8_20250901.zip /web/ 3.在/web目录下解压软件包 ![](https://i-blog.csdnimg.cn/direct/9830bd7f392b44c5bba52cf357aa1d12.png) 创建/etc/nginx/conf.d/nginx.conf文件 server{ listen 192.168.60.133:80; root /web/upload; include /etc/nginx/default.d/php.conf } 重启nginx服务 4.在浏览器上测试 ![](https://i-blog.csdnimg.cn/direct/0260c7eb19ac4f5fb73cc164627442d1.png) 默认权限不够,更改权限: \[root@shawn2 \~\]# cd /web/upload/ \[root@shawn2 upload\]# chmod -R 777 config/ data/ uc_\* ![](https://i-blog.csdnimg.cn/direct/28d59b25e1ed4dc29070b5a958fb6b05.png) 5.启用mariadb服务并完善数据库部署: [root@shawn2 ~]# systemctl start mariadb.service [root@shawn2 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.5.16-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> exit Bye [root@shawn2 ~]# mysql < alter user 'root'@'localhost' identified by 'Redhat123!'; > create database luntan; > exit > end 6.在浏览器上完成后续步骤 7.创建公私钥 cd到/web目录: [root@shawn2 web]# mkdir /miyao_zhengshu [root@shawn2 web]# cd /miyao_zhengshu/ [root@shawn2 miyao_zhengshu]# openssl genrsa -out miyao.key [root@shawn2 miyao_zhengshu]# openssl req -utf8 -new -key /miyao_zhengshu/miyao.key -x509 -days 100 -out /miyao_zhengshu/zhengshu.crt You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:99 State or Province Name (full name) []:ns Locality Name (eg, city) [Default City]:ds Organization Name (eg, company) [Default Company Ltd]:ds Organizational Unit Name (eg, section) []:dsd Common Name (eg, your name or your server's hostname) []:ds Email Address []:dwsdw 8.编辑文件/etc/nginx/conf.d/nginx.conf 从/etc/nginx/nginx.conf文件中复制https样例到/etc/nginx/conf.d/nginx.conf文件,并修改公私钥识别路径 ![](https://i-blog.csdnimg.cn/direct/693e801ec74d4797ac3363256a6baee5.png) ![](https://i-blog.csdnimg.cn/direct/63492db3deb749f0b09877efa2e7c164.png) 9.重启nginx服务,在浏览器验证: \[root@shawn2 \~\]# systemctl restart nginx.service ![](https://i-blog.csdnimg.cn/direct/f9634d138f2144c89101eaf11c1d8079.png) ## (2)按照基本步骤写脚本(与LAMP实验框架差不多) 1.创建一个新目录/https,与前一实验一致 2.编写数据库mysql.sh脚本文件 #!/bin/bash mysql_config() { mysql</dev/null && echo "解压成功" || echo "解压失败" cd /web/upload/ chmod -R 777 config/ data/ uc_* } #配置数据库 #mysql() { #systemctl start mariadb.service #mysql< /etc/nginx/conf.d/nginx.conf<<'EOF' server{ listen 192.168.60.133:80; root /web/upload; include /etc/nginx/default.d/php.conf; } server{ listen 443 ssl http2; root /web/upload; include /etc/nginx/default.d/php.conf; ssl_certificate "/miyao_zhengshu/zhengshu.crt"; ssl_certificate_key "/miyao_zhengshu/miyao.key"; } EOF systemctl restart nginx } 4.编写流程判断do.sh脚本: http if [ $? -eq 0 ];then echo http配置 is 成功 else echo http配置 is not 成功 fi mysql_config if [ $? -eq 0 ];then echo mysql配置 is 成功 else echo mysql配置 is not 成功 fi safe if [ $? -eq 0 ];then echo 防火墙、selinux关闭 is 成功 else echo 防火墙、selinux关闭 is not 成功 fi miyao if [ $? -eq 0 ];then echo 创建公私钥 is 成功 else echo 创建公私钥 is not 成功 fi https if [ $? -eq 0 ];then echo /etc/nginx/conf.d/nginx.conf文件添加 is 成功 else echo /etc/nginx/conf.d/nginx.conf文件添加 is not 成功 fi 5.运行脚本测试: ![](https://i-blog.csdnimg.cn/direct/80524eb270c24e1fbc923823132c9bde.png) 6.浏览器测试: ![](https://i-blog.csdnimg.cn/direct/f9634d138f2144c89101eaf11c1d8079.png)

相关推荐
释怀不想释怀25 分钟前
linux常见安装(JDK,mysql,nginx)
linux·运维·服务器
杰克崔28 分钟前
do_exit的hungtask问题及coredump的实验及原理分析一
linux·运维·服务器·车载系统
pengdott34 分钟前
Linux进程数据结构与组织方式深度解析
linux·运维·服务器
Java 码农35 分钟前
gitlab gitrunner springboot 多环境多分支部署 (非容器方式,使用原生linux 环境)
linux·spring boot·gitlab
LongQ30ZZ1 小时前
Linux的常见指令
linux·服务器
走向IT1 小时前
vdbench在Centos系统上联机测试环境搭建
linux·运维·centos
阳宗德1 小时前
基于CentOS Linux release 7.1实现了Oracle Database 11g R2 企业版容器化运行
linux·数据库·docker·oracle·centos
liulilittle1 小时前
libxdp: No bpffs found at /sys/fs/bpf
linux·运维·服务器·开发语言·c++
Byte Beat1 小时前
ubuntu安装docker
linux·ubuntu·docker
HIT_Weston1 小时前
88、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(二)
linux·运维·ubuntu