> 文章列表 > Linux Shell 实现一键部署http+用户名密码登录

Linux Shell 实现一键部署http+用户名密码登录

Linux Shell 实现一键部署http+用户名密码登录

Apache 前言

Apache(音译为阿帕奇)是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

Linux 各系统下载使用参考

Red Hat Rocky Linux  Oracle Linux

AlmaLinux 

ubuntu suselinux esxi RHEL标准安装 系统安装参考 YUM参考

MobaXterm 远程连接工具

Red Hat Enterprise 9.0 文档 Kickstart 生成器
download download download download download download download 参考 参考 配置参考 download 参考 Kickstart 
版本兼容性

安装 http

  • 实现在线安装http,配置http,创建测试目录,权限赋予,多用户不同目录配置实现
  • 创建安装自动化脚本
  • /var/www/html/ #网站目录(需要755权限)内部如果存需要访问,执行755权限
  • http端口 80 
  • 用户名密码 admin/admin (/etc/httpd/conf/.htpasswd_admin 用户名密码位置)
  • 带有用户名密码下载方式 wget -N -P /opt --http-user=admin --http-password=admin http://192.168.19.29/test/caddy.zip
  • 带有用户名密码下载方式 curl -u admin:admin -o /opt/caddy.zip http://192.168.19.29/test/caddy.zip 
  • selinux 安全配置参考开启的,设置自定义网站目录Selinux安全上下文,此处安全性考虑建议是开启,嫌麻烦那就忽略此功能,直接关闭就可以执行(setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  )
  • setenforce 1
    yum install policycoreutils-python policycoreutils-python-utils checkpolicy -y
    semanage fcontext -a -t httpd_sys_content_t /var/www/html/*
    restorecon -Rv /var/www/html/
vi /install_httpd.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: CIASM
# update 2023/04/20<<!
██╗  ██╗████████╗████████╗██████╗ 
██║  ██║╚══██╔══╝╚══██╔══╝██╔══██╗
███████║   ██║      ██║   ██████╔╝
██╔══██║   ██║      ██║   ██╔═══╝ 
██║  ██║   ██║      ██║   ██║     
╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚═╝  
!
yum install -y httpd net-tools wget curl
mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
rm -rf /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reloadsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 
setenforce 0chmod -R 755  /var/www/html/cat >>/etc/httpd/conf/httpd.conf<<EOF
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apacheServerAdmin root@httpd
ServerName 0.0.0.0:80
<Directory />AllowOverride noneRequire all denied
</Directory>DocumentRoot "/var/www/html"<Directory /var/www/html/>AllowOverride NoneOptions IndexesAuthType BasicAuthName "Basic Authentication"AuthUserFile /etc/httpd/conf/.htpasswd_adminrequire valid-user
</Directory><Directory "/var/www/html">
</Directory><IfModule dir_module>DirectoryIndex index.html index.cgi index.php
</IfModule><Files ".ht*">Require all denied
</Files>ErrorLog "logs/error_log"LogLevel warn<IfModule log_config_module>LogFormat "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combinedLogFormat "%h %l %u %t \\"%r\\" %>s %b" common<IfModule logio_module>LogFormat "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\" %I %O" combinedio</IfModule>CustomLog "logs/access_log" combined
</IfModule><IfModule alias_module>ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"</IfModule><Directory "/var/www/cgi-bin">AllowOverride NoneOptions NoneRequire all granted
</Directory><IfModule mime_module>TypesConfig /etc/mime.typesAddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType text/html .shtmlAddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
KeepAlive On 
<IfModule mime_magic_module>MIMEMagicFile conf/magic
</IfModule>EnableSendfile on
IncludeOptional conf.d/*.conf
EOFhtpasswd -cb /etc/httpd/conf/.htpasswd_admin admin admin
mkdir -p /var/www/html/tools
chmod -R 755 /var/www/html/tools
systemctl enable --now httpd
systemctl restart httpd

执行安装http 

sh /install_httpd.sh

用户登录测试

  • http://you_ip
  • admin/admin 

 此目录是脚本内部创建的一个临时目录可以根据自己需要进行调配