![用于安装网站的 Bash 脚本](https://linux22.com/image/107855/%E7%94%A8%E4%BA%8E%E5%AE%89%E8%A3%85%E7%BD%91%E7%AB%99%E7%9A%84%20Bash%20%E8%84%9A%E6%9C%AC.png)
首先,如果这是一个错误的地方问这个问题,请原谅。
我制作了一个 Bash 脚本,将 DirectAdmin 备份安装到 Apache 中。这些步骤有效,但最终我在打开实际网站时收到 500 错误。
步骤:
1. 解压 backup.tar.gz
2. 删除 unessecary 文件
3. 询问网站名称中的数据库详细信息
4. Cat 到 admin.conf 文件
5. 创建数据库和用户
6. 创建并 cat 到/etc/apache2/sites-available/website.conf
7.a2ensite
和service apache2 reload
8. 创建Windows 主机文件中的条目
我已经追踪了所有步骤,似乎一切正常,但是当我输入 URL 时,出现 500 错误。这一切都在没有脚本的情况下完成,一切正常。
有人能告诉我错误可能来自哪里吗?使用 bash 脚本执行所有这些步骤时有什么不同吗?
编辑:这是使用的整个脚本:
#!/bin/bash
clear
tar -zxvf backup.tar.gz
sudo cp -R ./domains/*/public_html/* ./
sudo cp ./backup/*.sql ./
rm -rf ./backup ./domains
rm backup.tar.gz
sudo chmod 775 ./config.php
echo "ROOT_PWD?"
read -s root_pwd
echo "WEBSITENAME?"
read website
echo "DB_USERNAME?"
read usrname
echo "DB_PASSWORD?"
read db_pwd
echo "DB_DATABASE?"
read db
cat > ./config.php <<EOL
<?php
// HTTP
define('HTTP_SERVER', 'http://www.$website.nl/admin/');
define('HTTP_CATALOG', 'http://www.$website.nl/');
// HTTPS
define('HTTPS_SERVER', 'http://www.$website.nl/admin/');
define('HTTPS_CATALOG', 'http://www.$website.nl/');
// DIR
define('DIR_APPLICATION', $_SERVER['DOCUMENT_ROOT'].'/admin/');
define('DIR_SYSTEM', $_SERVER['DOCUMENT_ROOT'].'/system/');
define('DIR_IMAGE', $_SERVER['DOCUMENT_ROOT'].'/image/');
define('DIR_LANGUAGE', $_SERVER['DOCUMENT_ROOT'].'/admin/language/');
define('DIR_TEMPLATE', $_SERVER['DOCUMENT_ROOT'].'/admin/view/template/');
define('DIR_CONFIG', $_SERVER['DOCUMENT_ROOT'].'/system/config/');
define('DIR_CACHE', $_SERVER['DOCUMENT_ROOT'].'/system/storage/cache/');
define('DIR_DOWNLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/download/');
define('DIR_LOGS', $_SERVER['DOCUMENT_ROOT'].'/system/storage/logs/');
define('DIR_MODIFICATION', $_SERVER['DOCUMENT_ROOT'].'/system/storage/modification/');
define('DIR_UPLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/upload/');
define('DIR_CATALOG', $_SERVER['DOCUMENT_ROOT'].'/catalog/');
// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', '$usrname');
define('DB_PASSWORD', '$db_pwd');
define('DB_DATABASE', '$db');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
EOL
chmod 444 ./config.php
chmod 755 ./admin/config.php
cat > ./admin/config.php <<EOL
<?php
// HTTP
define('HTTP_SERVER', 'http://www.$website.nl/admin/');
define('HTTP_CATALOG', 'http://www.$website.nl/');
// HTTPS
define('HTTPS_SERVER', 'http://www.$website.nl/admin/');
define('HTTPS_CATALOG', 'http://www.$website.nl/');
// DIR
define('DIR_APPLICATION', $_SERVER['DOCUMENT_ROOT'].'/admin/');
define('DIR_SYSTEM', $_SERVER['DOCUMENT_ROOT'].'/system/');
define('DIR_IMAGE', $_SERVER['DOCUMENT_ROOT'].'/image/');
define('DIR_LANGUAGE', $_SERVER['DOCUMENT_ROOT'].'/admin/language/');
define('DIR_TEMPLATE', $_SERVER['DOCUMENT_ROOT'].'/admin/view/template/');
define('DIR_CONFIG', $_SERVER['DOCUMENT_ROOT'].'/system/config/');
define('DIR_CACHE', $_SERVER['DOCUMENT_ROOT'].'/system/storage/cache/');
define('DIR_DOWNLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/download/');
define('DIR_LOGS', $_SERVER['DOCUMENT_ROOT'].'/system/storage/logs/');
define('DIR_MODIFICATION', $_SERVER['DOCUMENT_ROOT'].'/system/storage/modification/');
define('DIR_UPLOAD', $_SERVER['DOCUMENT_ROOT'].'/system/storage/upload/');
define('DIR_CATALOG', $_SERVER['DOCUMENT_ROOT'].'/catalog/');
// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', '$usrname');
define('DB_PASSWORD', '$db_pwd');
define('DB_DATABASE', '$db');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
EOL
chmod 444 ./admin/config.php
mysql -u root -p$root_pwd -e "CREATE DATABASE $db"
mysql -u root -p$root_pwd -e "CREATE USER '$usrname'@'localhost' IDENTIFIED BY '$db_pwd';"
mysql -u root -p$root_pwd -e "GRANT ALL PRIVILEGES ON $db . * TO '$usrname'@'localhost';"
mysql -u $usrname -p$db_pwd $db < *.sql
touch /etc/apache2/sites-available/$website'.conf'
cat > /etc/apache2/sites-available/$website'.conf' <<EOL
<VirtualHost *:80>
# 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 $website.nl
ServerAlias www.$website.nl
ServerAdmin webmaster@localhost
DocumentRoot /var/www/$website/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOL
a2ensite $website'.conf'
service apache2 reload
当我通过 DirectAdmin 从网站 www.example.com 进行备份并在脚本中使用该网站时,一切都按预期进行,但在浏览器中输入 URL 时,出现 500 错误。
Apache 日志为空。
答案1
哦,你需要使用ip_conntrack
,请执行以下步骤:
modprobe ip_conntrack
sysctl
获取with的变量列表sysctl -a |grep -i conn
:
输出为“:net.netfilter.nf_conntrack_acct = 0 net.netfilter.nf_conntrack_buckets = 65536 net.netfilter.nf_conntrack_checksum = 1 net.netfilter.nf_conntrack_count = 116 net.netfilter.nf_conntrack_events = 1 net.netfilter.nf_conntrack_expect_max = 1024 net.netfilter.nf_conntrack_generic_timeout = 600 net.netfilter.nf_conntrack_helper = 0 net.netfilter.nf_conntrack_icmp_timeout = 30 net.netfilter.nf_conntrack_log_invalid = 0 net.netfilter.nf_conntrack_max = 262144 net.netfilter.nf_conntrack_tcp_be_liberal = 0 net.netfilter.nf_conntrack_tcp_loose = 1 net.netfilter.nf_conntrack_tcp_max_retrans = 3 net.netfilter.nf_conntrack_tcp_timeout_close = 10 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_established = 432000 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30 net.netfilter.nf_conntrack_tcp_timeout_max_retrans = 300 net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 60 net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 120 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_unacknowledged = 300 net.netfilter.nf_conntrack_timestamp = 0 net.netfilter.nf_conntrack_udp_timeout = 30 net.netfilter.nf_conntrack_udp_timeout_stream = 180 net.nf_conntrack_max = 262144
改变
net.ipv4.netfilter.ip_conntrack_max
变量。- 存储在文件中。