转载请注明出处:https://www.myzhenai.com.cn/post/4784.html
这是我使用ChatGPT、Kimi、DeepSeek生成的Hiawatha + PHP + MySQL 一键安装脚本,大家可以根据要求进行安装
hiawatha又叫海华沙,是一款轻服务器环境,
hiawatha官网下载地址: https://hiawatha.leisink.net/download
如果系统上安装的CMake版本低于3.0,请将其删除,从https://CMake.org/download/#latest下载最新版本并安装。先安装cmake
ChatGPT
下面脚本会自动完成:
-
安装依赖(含 CMake,版本过低时会自动更新)。
-
编译安装 Hiawatha。
-
自动生成默认配置文件(
/usr/local/etc/hiawatha/hiawatha.conf)。 -
安装 PHP-FPM、MySQL(用系统包)。
-
配置 Hiawatha 调用 PHP-FPM。
#!/bin/bash
# 跨 Linux 发行版 一键安装 Hiawatha + PHP + MySQL
# 适用于 CentOS/RHEL, Debian/Ubuntu, openSUSE
set -e
HIAWATHA_VER="10.10"
CMAKE_VER="3.29.6"
echo "=========================================="
echo " 一键安装 Hiawatha ${HIAWATHA_VER} + PHP + MySQL"
echo "=========================================="
# 检测系统
if [ -f /etc/redhat-release ]; then
OS="centos"
PM="yum"
elif [ -f /etc/debian_version ]; then
OS="debian"
PM="apt-get"
elif grep -qi "suse" /etc/os-release; then
OS="suse"
PM="zypper"
else
echo "不支持的 Linux 系统"
exit 1
fi
echo "[1/6] 安装依赖..."
if [ "$OS" = "centos" ]; then
yum install -y epel-release
yum install -y gcc gcc-c++ make wget tar unzip \
libxml2 libxml2-devel libxslt libxslt-devel \
openssl openssl-devel pcre pcre-devel \
mariadb-server mariadb php php-cli php-fpm php-mysqlnd
elif [ "$OS" = "debian" ]; then
apt-get update -y
apt-get install -y build-essential wget tar unzip cmake \
libxml2 libxml2-dev libxslt1.1 libxslt1-dev \
libssl-dev libpcre3 libpcre3-dev \
mariadb-server php php-cli php-fpm php-mysql
elif [ "$OS" = "suse" ]; then
zypper install -y gcc gcc-c++ make wget tar unzip cmake \
libxml2 libxslt libopenssl-devel pcre-devel \
mariadb mariadb-tools php8 php8-cli php8-fpm php8-mysql
fi
# 启动数据库
if [ "$OS" = "centos" ] || [ "$OS" = "suse" ]; then
systemctl enable mariadb
systemctl start mariadb
else
systemctl enable mysql
systemctl start mysql
fi
# 检查并升级 CMake
echo "[2/6] 检查 CMake..."
CMAKE_CUR_VER=$(cmake --version 2>/dev/null | head -n1 | awk '{print $3}' || echo "0")
if [[ "$(echo -e "$CMAKE_CUR_VER\n3.0.0" | sort -V | head -n1)" != "3.0.0" ]]; then
echo "升级 CMake 到 ${CMAKE_VER}..."
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}.tar.gz
tar -xzf cmake-${CMAKE_VER}.tar.gz
cd cmake-${CMAKE_VER}
./bootstrap
make -j$(nproc)
make install
cd ..
rm -rf cmake-${CMAKE_VER}*
fi
# 编译安装 Hiawatha
echo "[3/6] 编译安装 Hiawatha..."
wget https://www.hiawatha-webserver.org/files/hiawatha-${HIAWATHA_VER}.tar.gz
tar zxvf hiawatha-${HIAWATHA_VER}.tar.gz
cd hiawatha-${HIAWATHA_VER}
mkdir build && cd build
cmake .. \
-DENABLE_CACHE=ON \
-DENABLE_DEBUG=OFF \
-DENABLE_IPV6=OFF \
-DENABLE_MONITOR=OFF \
-DENABLE_RPROXY=ON \
-DENABLE_SSL=ON \
-DENABLE_TOMAHAWK=OFF \
-DENABLE_TOOLKIT=ON \
-DENABLE_XSLT=OFF
make -j$(nproc)
make install/strip
cd ../..
rm -rf hiawatha-${HIAWATHA_VER}*
# 配置 Hiawatha
echo "[4/6] 配置 Hiawatha..."
mkdir -p /home/wwwroot
echo "<?php phpinfo(); ?>" > /home/wwwroot/index.php
cat >/usr/local/etc/hiawatha/hiawatha.conf <<EOF
ServerId = www:www
ConnectionsTotal = 250
ConnectionsPerIP = 25
SystemLogfile = /usr/local/var/log/hiawatha/system.log
GarbageLogfile = /usr/local/var/log/hiawatha/garbage.log
Binding {
Port = 80
}
FastCGIserver {
FastCGIid = PHP
ConnectTo = /var/run/php-fpm.sock
Extension = php
}
Hostname = 0.0.0.0
WebsiteRoot = /home/wwwroot
StartFile = index.php
AccessLogfile = /usr/local/var/log/hiawatha/access.log
ErrorLogfile = /usr/local/var/log/hiawatha/error.log
EOF
# 配置 PHP-FPM (改为 socket)
echo "[5/6] 配置 PHP-FPM..."
if [ "$OS" = "centos" ] || [ "$OS" = "suse" ]; then
PHPFPM_CONF="/etc/php-fpm.d/www.conf"
else
PHPFPM_CONF="/etc/php/7.*/*/pool.d/www.conf"
fi
if [ -f "$PHPFPM_CONF" ]; then
sed -i 's|^listen =.*|listen = /var/run/php-fpm.sock|' "$PHPFPM_CONF"
sed -i 's|^;listen.owner =.*|listen.owner = www|' "$PHPFPM_CONF"
sed -i 's|^;listen.group =.*|listen.group = www|' "$PHPFPM_CONF"
fi
systemctl enable php-fpm || systemctl enable php8-fpm || true
systemctl restart php-fpm || systemctl restart php8-fpm || true
# 创建 www 用户
if ! id www >/dev/null 2>&1; then
groupadd -r www
useradd -r -g www -s /sbin/nologin www
fi
# 创建 systemd 服务
echo "[6/6] 创建 systemd 服务..."
cat >/etc/systemd/system/hiawatha.service <<EOF
[Unit]
Description=Hiawatha Webserver
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/hiawatha
ExecReload=/bin/kill -HUP \$MAINPID
ExecStop=/usr/local/sbin/hiawatha -k
PIDFile=/usr/local/var/run/hiawatha.pid
Restart=always
User=www
Group=www
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable hiawatha
systemctl start hiawatha
echo "=========================================="
echo "Hiawatha + PHP + MySQL 安装完成!"
echo "Web 根目录: /home/wwwroot"
echo "测试访问: http://服务器IP/"
echo "数据库初始化: sudo mysql_secure_installation"
echo "服务管理: systemctl {start|stop|restart|status} hiawatha"
echo "=========================================="
保存为install_hiawatha_lnmp.sh即可
Kimi
#!/usr/bin/env bash
# ===================================================================
# Hiawatha 10.10 跨发行版一键编译安装脚本
# 支持:CentOS/RHEL 7+、Rocky/Alma、Fedora、Debian、Ubuntu、
# Alpine、Arch、openSUSE
# ===================================================================
set -e
[[ $EUID -ne 0 ]] && { echo "请用 root 运行"; exit 1; }
# ------------------ 工具函数 ------------------
detect_os(){
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS=$ID
VER=$VERSION_ID
else
echo "无法识别系统"; exit 2
fi
}
pkg_install(){
case $OS in
ubuntu|debian) apt-get update -qq; apt-get install -y "$@" ;;
centos|rhel|rocky|almalinux) yum install -y "$@" ;;
fedora) dnf install -y "$@" ;;
alpine) apk add --no-cache "$@" ;;
arch) pacman -Sy --noconfirm "$@" ;;
opensuse*) zypper in -y "$@" ;;
*) echo "不支持 $OS"; exit 3 ;;
esac
}
svc_enable(){
systemctl daemon-reload
systemctl enable hiawatha
systemctl start hiawatha
}
# ------------------ 1. 识别系统 ------------------
detect_os
echo "==> 检测到 $OS $VER"
# ------------------ 2. 安装依赖 ------------------
echo "==> 安装编译依赖"
case $OS in
ubuntu|debian)
pkg_install build-essential cmake openssl libssl-dev zlib1g-dev libxml2-dev libxslt1-dev wget tar
;;
centos|rhel|rocky|almalinux|fedora)
pkg_install gcc openssl-devel zlib-devel libxml2-devel libxslt-devel cmake wget tar make
;;
alpine)
pkg_install build-base cmake openssl-dev zlib-dev libxml2-dev libxslt-dev wget tar
;;
arch)
pkg_install base-devel cmake openssl zlib libxml2 libxslt wget tar
;;
opensuse*)
pkg_install gcc openssl-devel zlib-devel libxml2-devel libxslt-devel cmake wget tar
;;
esac
# ------------------ 3. 确保 cmake≥3.0 ------------------
CMAKE_MIN=$(cmake -P cmake/MinimumVersion.cmake 2>/dev/null | awk '{print $1}')
if ! cmake --version | awk 'NR==1{exit ($3<3.0)}'; then
echo "==> 升级 cmake"
CMAKE_VER=3.26.5
cd /tmp
wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}.tar.gz
tar -xf cmake-${CMAKE_VER}.tar.gz
cd cmake-${CMAKE_VER}
./bootstrap --prefix=/usr/local
make -j$(nproc) && make install
ln -sf /usr/local/bin/cmake /usr/bin/cmake
fi
# ------------------ 4. 下载并编译 Hiawatha ------------------
HVER=10.10
cd /tmp
wget -q https://www.hiawatha-webserver.org/files/hiawatha-${HVER}.tar.gz
tar zxf hiawatha-${HVER}.tar.gz
cd hiawatha-${HVER}
mkdir -p build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DSYSCONFDIR=/etc \
-DLOCALSTATEDIR=/var \
-DENABLE_CACHE=ON \
-DENABLE_SSL=ON \
-DENABLE_TOOLKIT=ON \
-DENABLE_RPROXY=ON \
-DENABLE_MONITOR=OFF \
-DENABLE_TOMAHAWK=OFF \
-DENABLE_XSLT=OFF
make -j$(nproc) && make install/strip
# ------------------ 5. 目录 & 用户 ------------------
useradd -r -s /sbin/nologin -d /var/www/hiawatha -M hiawatha 2>/dev/null || true
mkdir -p /etc/hiawatha /var/log/hiawatha /var/www/hiawatha
chown -R hiawatha:hiawatha /var/log/hiawatha /var/www/hiawatha
# ------------------ 6. 最小配置文件 ------------------
cat >/etc/hiawatha/hiawatha.conf <<'EOF'
ServerId = hiawatha:hiawatha
ConnectionsTotal = 1000
ConnectionsPerIP = 50
SystemLogfile = /var/log/hiawatha/system.log
GarbageLogfile = /var/log/hiawatha/garbage.log
Binding {
Port = 80
}
BanOnGarbage = 300
BanOnMaxPerIP = 60
BanOnMaxReqSize = 300
KickOnBan = yes
RebanDuringBan = yes
Hostname = 0.0.0.0
WebsiteRoot = /var/www/hiawatha
StartFile = index.html
AccessLogfile = /var/log/hiawatha/access.log
ErrorLogfile = /var/log/hiawatha/error.log
EOF
echo '<h1>It works! Hiawatha is running.</h1>' >/var/www/hiawatha/index.html
chown hiawatha:hiawatha /var/www/hiawatha/index.html
# ------------------ 7. systemd 服务 ------------------
cat >/etc/systemd/system/hiawatha.service <<'EOF'
[Unit]
Description=Hiawatha Web Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/hiawatha -c /etc/hiawatha/hiawatha.conf
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# ------------------ 8. 启动 & 防火墙 ------------------
svc_enable
case $OS in
centos|rhel|rocky|almalinux|fedora)
systemctl is-active firewalld &>/dev/null && { firewall-cmd --permanent --add-port=80/tcp; firewall-cmd --reload; }
;;
opensuse*)
systemctl is-active firewalld &>/dev/null && { firewall-cmd --permanent --add-port=80/tcp; firewall-cmd --reload; }
;;
debian|ubuntu)
which ufw &>/dev/null && { ufw allow 80/tcp; }
;;
esac
# ------------------ 9. 输出信息 ------------------
echo "========================================================="
echo "Hiawatha 10.10 安装完成!"
echo " 配置文件:/etc/hiawatha/hiawatha.conf"
echo " 网站目录:/var/www/hiawatha"
echo " 日志目录:/var/log/hiawatha"
echo " 服务管理:systemctl {start|stop|restart|status} hiawatha"
echo " 请访问 http://服务器IP 验证是否正常。"
echo "========================================================="
保存为install_hiawatha_lnmp.sh即可
DeepSeek
#!/bin/bash
# Hiawatha + PHP + MySQL 一键安装脚本
# 支持Debian/Ubuntu、CentOS/RHEL和OpenSUSE系统
set -e
# 颜色输出定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色
# 日志函数
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_debug() {
echo -e "${BLUE}[DEBUG]${NC} $1"
}
# 检查是否以root权限运行
check_root() {
if [[ $EUID -ne 0 ]]; then
log_error "此脚本必须以root权限运行"
exit 1
fi
}
# 检测系统类型和版本
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
OS_VERSION=$VERSION_ID
log_info "检测到系统: $NAME $VERSION"
elif [ -f /etc/debian_version ]; then
OS="debian"
OS_VERSION=$(cat /etc/debian_version)
log_info "检测到Debian系统版本: $OS_VERSION"
elif [ -f /etc/redhat-release ]; then
OS=$(cat /etc/redhat-release | cut -d ' ' -f1 | tr '[:upper:]' '[:lower:]')
OS_VERSION=$(cat /etc/redhat-release | cut -d ' ' -f3)
log_info "检测到RHEL/CentOS系统版本: $OS_VERSION"
else
log_error "不支持的Linux发行版"
exit 1
fi
# 设置包管理器
case $OS in
debian|ubuntu)
PKG_MANAGER="apt-get"
INSTALL_CMD="apt-get install -y"
UPDATE_CMD="apt-get update"
;;
centos|rhel|fedora)
PKG_MANAGER="yum"
INSTALL_CMD="yum install -y"
UPDATE_CMD="yum update -y"
;;
opensuse*|suse)
PKG_MANAGER="zypper"
INSTALL_CMD="zypper install -y"
UPDATE_CMD="zypper refresh"
;;
*)
log_error "不支持的Linux发行版: $OS"
exit 1
;;
esac
}
# 安装依赖
install_dependencies() {
log_info "安装依赖包..."
case $OS in
debian|ubuntu)
$UPDATE_CMD
$INSTALL_CMD wget gcc gcc-c++ make openssl libssl-dev libxml2 libxslt1.1 libxslt-dev
;;
centos|rhel)
$UPDATE_CMD
$INSTALL_CMD wget gcc gcc-c++ make openssl-devel libxml2 libxslt libxslt-devel
;;
opensuse*|suse)
$UPDATE_CMD
$INSTALL_CMD wget gcc gcc-c++ make libopenssl-devel libxml2-devel libxslt-devel
;;
esac
}
# 安装CMake
install_cmake() {
log_info "安装CMake..."
# 检查是否已安装CMake
if command -v cmake &> /dev/null; then
CMAKE_VERSION=$(cmake --version | head -n1 | awk '{print $3}')
log_info "CMake已安装,版本: $CMAKE_VERSION"
# 检查版本是否足够新
REQUIRED_CMAKE="3.0"
if [ "$(printf '%s\n' "$REQUIRED_CMAKE" "$CMAKE_VERSION" | sort -V | head -n1)" = "$REQUIRED_CMAKE" ]; then
log_info "CMake版本满足要求"
return 0
else
log_warning "CMake版本过低,需要安装新版本"
fi
fi
# 下载并安装CMake
CMAKE_VERSION="3.26.4"
log_info "下载CMake ${CMAKE_VERSION}..."
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz
tar -xzf cmake-${CMAKE_VERSION}.tar.gz
cd cmake-${CMAKE_VERSION}
log_info "编译安装CMake..."
./configure
make -j$(nproc)
make install
cd ..
# 验证安装
if command -v cmake &> /dev/null; then
log_info "CMake安装成功"
else
log_error "CMake安装失败"
exit 1
fi
}
# 安装Hiawatha
install_hiawatha() {
log_info "安装Hiawatha..."
# 下载Hiawatha
HIAWATHA_VERSION="10.10"
wget https://www.hiawatha-webserver.org/files/hiawatha-${HIAWATHA_VERSION}.tar.gz
tar zxvf hiawatha-${HIAWATHA_VERSION}.tar.gz
cd hiawatha-${HIAWATHA_VERSION}
# 编译安装
mkdir build
cd build
cmake .. -DENABLE_CACHE=ON -DENABLE_DEBUG=off -DENABLE_IPV6=off -DENABLE_MONITOR=off -DENABLE_RPROXY=ON -DENABLE_SSL=ON -DENABLE_TOMAHAWK=off -DENABLE_TOOLKIT=ON -DENABLE_XSLT=off
make -j$(nproc)
make install/strip
cd ../..
# 验证安装
if hiawatha -k; then
log_info "Hiawatha安装成功"
else
log_error "Hiawatha安装失败"
exit 1
fi
}
# 配置Hiawatha
configure_hiawatha() {
log_info "配置Hiawatha..."
# 创建必要的目录
mkdir -p /usr/local/var/log/hiawatha
mkdir -p /var/www/html
# 创建配置文件
cat > /usr/local/etc/hiawatha/hiawatha.conf << EOF
# Hiawatha main configuration file
# GENERAL SETTINGS
#
ServerId = www-data:www-data
ConnectionsTotal = 250
ConnectionsPerIP = 25
SystemLogfile = /usr/local/var/log/hiawatha/system.log
GarbageLogfile = /usr/local/var/log/hiawatha/garbage.log
# BINDING SETTINGS
# A binding is where a client can connect to.
#
Binding {
Port = 80
# Interface = 127.0.0.1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
}
# BANNING SETTINGS
# Deny service to clients who misbehave.
#
BanOnGarbage = 300
BanOnMaxPerIP = 60
BanOnMaxReqSize = 300
KickOnBan = yes
RebanDuringBan = yes
# FASTCGI SETTINGS
# Configure FastCGI for PHP
#
FastCGIserver {
FastCGIid = PHP
ConnectTo = /var/run/php/php-fpm.sock
Extension = php
SessionTimeout = 30
}
# DEFAULT WEBSITE
#
Hostname = 127.0.0.1
WebsiteRoot = /var/www/html
StartFile = index.php
AccessLogfile = /usr/local/var/log/hiawatha/access.log
ErrorLogfile = /usr/local/var/log/hiawatha/error.log
UseFastCGI = PHP
# VIRTUAL HOSTS
# Use a VirtualHost section to declare the websites you want to host.
#
#VirtualHost {
# Hostname = example.com
# WebsiteRoot = /var/www/example.com
# StartFile = index.php
# AccessLogfile = /var/log/hiawatha/example.com/access.log
# ErrorLogfile = /var/log/hiawatha/example.com/error.log
# UseFastCGI = PHP
#}
EOF
# 创建测试页面
cat > /var/www/html/index.php << EOF
<?php
phpinfo();
?>
EOF
# 设置权限
chown -R www-data:www-data /var/www/html 2>/dev/null || chown -R apache:apache /var/www/html 2>/dev/null || log_warning "无法更改/var/www/html的所有权"
}
# 安装PHP和MySQL
install_php_mysql() {
log_info "安装PHP和MySQL..."
case $OS in
debian|ubuntu)
# 添加PHP仓库
$INSTALL_CMD software-properties-common
add-apt-repository -y ppa:ondrej/php
$UPDATE_CMD
# 安装PHP和MySQL
$INSTALL_CMD php-fpm php-mysql mysql-server
# 配置PHP-FPM
PHP_FPM_SOCKET="/var/run/php/php-fpm.sock"
;;
centos|rhel)
# 安装EPEL和Remi仓库
$INSTALL_CMD epel-release
if [ "$OS" = "centos" ] && [ "$(rpm -E %centos)" -eq "7" ]; then
$INSTALL_CMD https://rpms.remirepo.net/enterprise/remi-release-7.rpm
elif [ "$OS" = "centos" ] && [ "$(rpm -E %centos)" -ge "8" ]; then
$INSTALL_CMD https://rpms.remirepo.net/enterprise/remi-release-8.rpm
else
$INSTALL_CMD https://rpms.remirepo.net/enterprise/remi-release-7.rpm
fi
# 启用Remi仓库
yum-config-manager --enable remi-php74
# 安装PHP和MySQL
$INSTALL_CMD php php-fpm php-mysqlnd mysql-server
# 配置PHP-FPM
PHP_FPM_SOCKET="/var/run/php-fpm/php-fpm.sock"
;;
opensuse*|suse)
# 安装PHP和MySQL
$INSTALL_CMD php7 php7-fpm php7-mysql mysql-community-server
# 配置PHP-FPM
PHP_FPM_SOCKET="/var/run/php7-fpm/php-fpm.sock"
;;
esac
# 配置PHP-FPM
if [ -f /etc/php/*/fpm/pool.d/www.conf ]; then
PHP_FPM_CONF=$(find /etc/php -name www.conf | head -n1)
sed -i "s|^listen = .*|listen = $PHP_FPM_SOCKET|" $PHP_FPM_CONF
sed -i 's/^listen.owner = .*/listen.owner = www-data/' $PHP_FPM_CONF
sed -i 's/^listen.group = .*/listen.group = www-data/' $PHP_FPM_CONF
sed -i 's/^user = .*/user = www-data/' $PHP_FPM_CONF
sed -i 's/^group = .*/group = www-data/' $PHP_FPM_CONF
fi
# 更新Hiawatha配置中的PHP-FPM socket路径
sed -i "s|ConnectTo = .*|ConnectTo = $PHP_FPM_SOCKET|" /usr/local/etc/hiawatha/hiawatha.conf
# 启动服务
case $OS in
debian|ubuntu)
systemctl start php*-fpm
systemctl enable php*-fpm
systemctl start mysql
systemctl enable mysql
;;
centos|rhel)
systemctl start php-fpm
systemctl enable php-fpm
systemctl start mysqld
systemctl enable mysqld
;;
opensuse*|suse)
systemctl start php-fpm
systemctl enable php-fpm
systemctl start mysql
systemctl enable mysql
;;
esac
# MySQL安全配置
log_info "运行MySQL安全配置..."
case $OS in
debian|ubuntu)
# Debian/Ubuntu上的MySQL安装后不需要初始密码
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; FLUSH PRIVILEGES;" 2>/dev/null || true
;;
centos|rhel|opensuse*|suse)
# 尝试获取临时密码
MYSQL_TEMP_PASSWORD=$(grep 'temporary password' /var/log/mysqld.log 2>/dev/null | awk '{print $NF}' || echo "")
if [ -n "$MYSQL_TEMP_PASSWORD" ]; then
mysql -uroot -p"$MYSQL_TEMP_PASSWORD" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';" 2>/dev/null || true
else
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; FLUSH PRIVILEGES;" 2>/dev/null || true
fi
;;
esac
}
# 创建启动脚本
create_startup_script() {
log_info "创建启动脚本..."
case $OS in
debian|ubuntu|centos|rhel)
cat > /etc/systemd/system/hiawatha.service << EOF
[Unit]
Description=Hiawatha webserver
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/hiawatha
ExecReload=/bin/kill -HUP \$MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 启用并启动服务
systemctl daemon-reload
systemctl enable hiawatha
systemctl start hiawatha
;;
opensuse*|suse)
cat > /etc/init.d/hiawatha << EOF
#!/bin/sh
#
# Hiawatha startup script
#
### BEGIN INIT INFO
# Provides: hiawatha
# Required-Start: \$network \$remote_fs \$syslog
# Required-Stop: \$network \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hiawatha webserver
# Description: Start the Hiawatha webserver
### END INIT INFO
case "\$1" in
start)
/usr/local/sbin/hiawatha
;;
stop)
killall hiawatha
;;
restart)
killall hiawatha
sleep 2
/usr/local/sbin/hiawatha
;;
*)
echo "Usage: \$0 {start|stop|restart}"
exit 1
;;
esac
exit 0
EOF
chmod +x /etc/init.d/hiawatha
insserv hiawatha
/etc/init.d/hiawatha start
;;
esac
}
# 配置防火墙
configure_firewall() {
log_info "配置防火墙..."
case $OS in
debian|ubuntu)
if command -v ufw &> /dev/null; then
ufw allow http
ufw allow https
log_info "已配置UFW防火墙"
fi
;;
centos|rhel)
if command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
log_info "已配置firewalld"
fi
;;
opensuse*|suse)
if command -v yast2 &> /dev/null; then
yast2 firewall services add service=service:http
yast2 firewall services add service=service:https
log_info "已配置SuSEfirewall2"
fi
;;
esac
}
# 显示安装结果
show_result() {
log_info "安装完成!"
log_info "Hiawatha服务器已安装并运行在端口80"
log_info "PHP已安装并配置为通过PHP-FPM与Hiawatha协同工作"
log_info "MySQL已安装,请确保已设置root密码"
log_info "网站根目录: /var/www/html"
log_info "测试页面: http://你的服务器IP/index.php"
# 显示服务器IP地址
IP=$(hostname -I | awk '{print $1}' || hostname)
if [ ! -z "$IP" ]; then
log_info "服务器IP地址: $IP"
fi
log_warning "请确保已正确配置防火墙以允许HTTP流量"
log_info "MySQL root密码可能需要手动设置,请运行: mysql_secure_installation"
}
# 主安装函数
main() {
log_info "开始安装Hiawatha、PHP和MySQL..."
check_root
detect_os
install_dependencies
install_cmake
install_hiawatha
configure_hiawatha
install_php_mysql
create_startup_script
configure_firewall
show_result
}
# 执行主函数
main "$@"
保存为install_hiawatha_lnmp.sh即可

sicnature ---------------------------------------------------------------------
I P 地 址: 216.73.216.10
区 域 位 置: 美国加利福尼亚洛杉矶
系 统 信 息:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com/post/4784.html
没有评论