From ed69c9b22c7d133415803fcd08a69f7fdd715299 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 29 Jun 2024 21:49:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\345\221\275\344\273\244.md" | 0 ...41\347\220\206\345\221\275\344\273\244.md" | 0 ...45\245\207web\346\234\215\345\212\241i.md" | 165 ++++++++++++++++++ 3 files changed, 165 insertions(+) rename "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240621-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" => "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240620-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" (100%) rename "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240627-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" => "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" (100%) create mode 100644 "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240624-\351\205\215\347\275\256\351\230\277\345\270\225\345\245\207web\346\234\215\345\212\241i.md" diff --git "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240621-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240620-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" similarity index 100% rename from "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240621-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" rename to "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240620-\350\277\233\347\250\213\343\200\201\345\220\216\345\217\260\347\256\241\347\220\206\345\221\275\344\273\244.md" diff --git "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240627-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" similarity index 100% rename from "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240627-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" rename to "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" diff --git "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240624-\351\205\215\347\275\256\351\230\277\345\270\225\345\245\207web\346\234\215\345\212\241i.md" "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240624-\351\205\215\347\275\256\351\230\277\345\270\225\345\245\207web\346\234\215\345\212\241i.md" new file mode 100644 index 0000000..40ced67 --- /dev/null +++ "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240624-\351\205\215\347\275\256\351\230\277\345\270\225\345\245\207web\346\234\215\345\212\241i.md" @@ -0,0 +1,165 @@ +# linux(debian)配置阿帕奇web服务 + +## 安装apache2 + +```sh +sudo apt install apache2 +``` + +## 停止并禁用 Nginx + +#### 在安装 Apache 之前,确保 Nginx 已停止并且不会在系统启动时自动启动 + +```sh +sudo systemctl stop nginx +``` + +## 启动并启用 Apache + +```sh +sudo systemctl start apache2 +``` + +## 配置 Apache + +#### 你可能需要将 Nginx 的配置迁移到 Apache。下面是一些常见的配置文件和目录 + +- Nginx 的配置文件通常位于 /etc/nginx/nginx.conf 和 /etc/nginx/sites-available/。 + +- Apache 的配置文件通常位于 /etc/apache2/apache2.conf 和 /etc/apache2/sites-available/。 + +## 在 Apache 中创建站点(文件):/apache2/sites-available + +#### 首先,创建一个由自己名字命名的.conf 文件,如 mydomain.conf创建完成后,参考以下操作 + +## 将Nginx 配置迁移到 Apache + +#### 为什么要将 Nginx 配置迁移到 Apache? + +1. 兼容性和功能需求 +模块支持:Apache 具有丰富的模块支持,尤其是在处理动态内容(如 PHP、Python 等)方面,Apache 有许多成熟的模块,如 mod_php、mod_python 等。 +.htaccess 文件:一些应用程序(特别是一些开源 CMS,如 WordPress、Joomla 等)广泛使用 .htaccess 文件来进行目录级别的配置和重写规则。Apache 原生支持 .htaccess 文件,而 Nginx 不支持,需要额外的配置。 +WebDAV 支持:Apache 的 mod_dav 模块提供了对 WebDAV 的良好支持,而 Nginx 对 WebDAV 的支持相对较弱。 +2. 现有基础设施 +现有配置或依赖:如果你的现有基础设施或其他组件(如反向代理、负载均衡器、应用程序服务器等)依赖于 Apache,迁移到 Apache 可能会简化维护和配置。 +组织标准:在一些组织中,可能有使用 Apache 的标准或惯例,因此迁移到 Apache 符合组织的 IT 策略。 +3. 性能和稳定性 +特定性能优化:在某些特定的使用场景下,Apache 可能比 Nginx 更适合。例如,Apache 的 mpm_prefork 模块在处理大量小请求时可能表现更好。 +稳定性和成熟度:Apache 是一个非常成熟和稳定的 Web 服务器,拥有多年的开发历史和广泛的社区支持。 + +### 以自己的为例 + +```sh +Nginx.d中的配置为: +server { + listen 80; + server_name 91c13.top www.91c13.top; + + location / { + root /var/www/91c13.top; + index index.html; + } +} +``` + +## 转换为apache2.conf的配置 + +```sh + + ServerName 91c13.top + ServerAlias www.91c13.top + + DocumentRoot /var/www/91c13.top + + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/91c13.top_error.log + CustomLog ${APACHE_LOG_DIR}/91c13.top_access.log combined + +``` + +### 各模块解释 + +1. + +###### 这一行定义了一个虚拟主机,并指定该虚拟主机监听所有网络接口上的端口 80(HTTP 端口) + +- *: 表示监听所有可用的网络接口。 +- 80 是 HTTP 的标准端口。 + +2. ServerName 91c13.top + +###### 这一行指定了此虚拟主机的主机名(域名) + +- ServerName 91c13.top 表示这个虚拟主机响应 91c13.top 域名的请求。 + +3. ServerAlias + +###### 这一行为此虚拟主机指定了别名 + +- ServerAlias 表示这个虚拟主机同样响应 域名的请求。 + +4. DocumentRoot /var/www/91c13.top + +###### 这一行指定了此虚拟主机的文档根目录 + +- DocumentRoot /var/www/91c13.top 指定了当请求匹配此虚拟主机时,Apache 将从 /var/www/91c13.top 目录提供文件。 + +5. + +###### 这一部分定义了针对 /var/www/91c13.top 目录的配置指令 + +- 5.1 Options Indexes FollowSymLinks +- Indexes:允许在目录中没有 index 文件时显示目录列表。 +- FollowSymLinks:允许 Apache 跟随符号链接。 +- 5.2 AllowOverride None +- AllowOverride None:不允许 .htaccess 文件覆盖目录设置。这意味着任何在 .htaccess 文件中的设置都将被忽略。 +- 5.3 Require all granted +- Require all granted:允许所有访问请求。这是一种新的访问控制方法,取代了旧的 Order allow,deny 和 Allow from all 指令。 + +6. ErrorLog ${APACHE_LOG_DIR}/91c13.top_error.log + +###### 这一行指定了此虚拟主机的错误日志文件位置 + +- ${APACHE_LOG_DIR} 是一个环境变量,在 Debian 系统中通常解析为 /var/log/apache2。 +91c13.top_error.log 是错误日志文件的名称。 + +7. CustomLog ${APACHE_LOG_DIR}/91c13.top_access.log combined + +###### 这一行指定了此虚拟主机的访问日志文件位置和日志格式 + +- ${APACHE_LOG_DIR} 同样解析为 /var/log/apache2。 +- 91c13.top_access.log 是访问日志文件的名称。 +- combined 是一种预定义的日志格式,包含了更多信息(如客户端 IP 地址、用户代理等),比默认的 common 日志格式更详细。 + +## 启用新的虚拟主机 + +##### 启用新的虚拟主机配置文件,并重新加载 Apache 服务 + +```sh +sudo a2ensite 91c13.top.conf +sudo systemctl reload apache2 +``` + +## 确认 DocumentRoot 目录存在 + +#### 确保 /var/www/91c13.top 目录存在并且包含 index.html 文件 + +```sh +sudo mkdir -p /var/www/91c13.top +sudo touch /var/www/91c13.top/index.html +``` + +## 测试 Apache 配置 + +#### 确保 Apache 配置文件没有错误 + +```sh +sudo apache2ctl configtest +#如果一切正常,你应该看到以下输出: +Syntax OK +``` -- Gitee From ef7eb9c27dc2fd5823d061e05daa663c11d8b439 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 5 Jul 2024 10:20:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\345\221\275\344\273\244.md" | 2 +- .../\345\256\236\350\256\255.md" | 137 ++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 "\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/\345\256\236\350\256\255.md" diff --git "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" index c20d386..8f2f8a9 100644 --- "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" +++ "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/20240622-\347\263\273\347\273\237\347\256\241\347\220\206\345\221\275\344\273\244.md" @@ -1,4 +1,4 @@ -# 系统管理命令 +=# 系统管理命令 ## 系统管理命令 - 系统管理命令 diff --git "a/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/\345\256\236\350\256\255.md" "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/\345\256\236\350\256\255.md" new file mode 100644 index 0000000..f1578c0 --- /dev/null +++ "b/\351\231\266\345\256\227\350\261\252/\347\254\224\350\256\260/\345\256\236\350\256\255.md" @@ -0,0 +1,137 @@ +# 实训准备 + +## 阿帕奇`web`服务 + +#### 1、在服务器上安装阿帕奇服务 + +```bash +## 安装Apache2 和 SSL 模块 +sudo apt update +sudo apt install apache2 +sudo a2enmod ssl +sudo systemctl restart apache2 +``` + +#### 2、端口问题 + +#### 1)由于我们之前的服务器服务是`nginx`,`nginx`监听的是80端口`apache`服务也是监听80``端口所以二者有冲突,这时就要重新开放一个端口给`apache`使用:`8080` + +#### 2)我们给apache设定好了端口后要在`防火墙 ufw `中开启它(如果有防火墙的话),其次我们要在华为云中的安全组中添加`8080`端口的监听 + +#### 3、apache的配置文件:`/etc/apache2` + +##### 1:在`ports.conf`中 + +```js + +Listen 8080 ##监听8080端口 + + + + Listen 8443 ##监听8443安全端口,配置https时修改 + + + + Listen 8443 ##监听8443安全端口,配置https时修改 + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet + +``` + +##### 2:在`apache2.conf`中,尾行增加 + +```js +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet +LoadModule ssl_module modules/mod_ssl.so ##ssl模块 +``` + +##### 3:在`sites-available/ `中的:`000-default.conf`里 + +```js +//监听8080端口 + # The ServerName directive sets the request scheme, hostname and port that + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header to + # match this virtual host. For the default virtual host (this file) this + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + + ServerName 91c13.top //顶级域名 + ServerAlias abc.91c13.top //二级域名 + ServerAdmin 3412313235@qq.com //邮箱 + DocumentRoot /var/www/html //index目录 +``` + +#### 4 :测试 + +```bash +apache2ctl configtest ##测试 Apache 配置文件的语法是否正确: + +##成功显示 +Syntax OK +``` + +#### 5:访问方式:`abc.91c13.top:8080` + +=============================================================================================================================================================================================================================================================================================================================================================================================================================================== + +## MySQL + +### 1、在自己的`Debian`服务器上部署`MySQL`数据库 + +#### 2、在现有的`Debian`服务中由于`MySQL`转为收费所以`Debian`以后的版本中不在默认配有`MySQL`安装包所以`apt`下载无效。 + +```bash +## 下载 MySQL APT 存储库配置包: +wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb +## 配置密钥 +apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C +## 安装 MySQL APT 存储库配置包 +dpkg -i mysql-apt-config_0.8.24-1_all.deb ## 在安装过程中,你会被提示选择 MySQL 的版本。默认选择即可,按 Enter 确认选择。 +## 更新系统列表 +apt update +``` + +#### 3、安装 MySQL 服务器 + +```bash +apt install mysql-server -y ## 安装MySQL服务器 +``` + +#### 4、配置 MySQL 允许远程连接 + +```js +## 配置/etc/mysql/mysql.conf.d/mysqld.cnf ;服务器配置文件 +[mysqld] +bind-address = 0.0.0.0 +``` + +#### 5、在MySQL创建新用户 + +```sh +sudo mysql -u root -p ## 登录MySQL + +## 这行代码用于创建一个新的数据库用户。'your_user'@'%'指定了用户的名称和允许其从任何IP地址连接到数据库服务器。IDENTIFIED BY 'your_password'部分设置了该用户的密码。 +CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password'; + +## 这行代码授予了新创建的用户在所有数据库和所有数据库对象上的所有权限。*.*表示所有的数据库和数据库中的所有表或其他对象。WITH GRANT OPTION允许该用户将其拥有的权限授予其他用户 +GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'%' WITH GRANT OPTION; + +##这行代码刷新了MySQL的权限表,使得之前的更改立即生效。如果不执行这一步,那么新的权限设置可能不会立即生效,直到MySQL服务器重新启动或者下次自动刷新权限表时 +FLUSH PRIVILEGES; +``` + +#### 6、防火墙权限 + +```sh +ufw allow 3306 ## 确保服务器的防火墙允许 MySQL 端口(默认 3306)的访问。 +``` + +#### 7、华为云配置 + +##### 一切就绪后前往华为云安全组打开`3306MySQL`端口。 + + + -- Gitee