我有一个VirtualBox安装程序,带有一个Ubuntu 20.04 (在Vagrant内),当我启动它时,apache2-server不会自动启动。
启动机器后,当我SSH进入机器时,我会看到以下内容:sudo service apache2 status
:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-04-03 21:42:41 CEST; 35s ago
Docs: https://httpd.apache.org/docs/2.4/
Apr 03 21:42:41 vagrant apachectl[777]: (2)No such file or directory: AH02291: Cannot access directory '/host/logs/apache2/sites/' for error>
Apr 03 21:42:41 vagrant apachectl[777]: (2)No such file or directory: AH02291: Cannot access directory '/host/logs/apache2/sites/' for error>
Apr 03 21:42:41 vagrant apachectl[777]: (2)No such file or directory: AH02291: Cannot access directory '/host/logs/apache2/sites/' for error>
Apr 03 21:42:41 vagrant apachectl[777]: (2)No such file or directory: AH02291: Cannot access directory '/host/logs/apache2/sites/' for error>
Apr 03 21:42:41 vagrant apachectl[777]: AH00014: Configuration check failed
Apr 03 21:42:41 vagrant apachectl[759]: Action 'start' failed.
Apr 03 21:42:41 vagrant apachectl[759]: The Apache error log may have more information.
Apr 03 21:42:41 vagrant systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Apr 03 21:42:41 vagrant systemd[1]: apache2.service: Failed with result 'exit-code'.
Apr 03 21:42:41 vagrant systemd[1]: Failed to start The Apache HTTP Server.
看起来它切断了行,因为我假设它以一条路径结束,而这条路径被切断了:因此它说( bold文本是我所缺少的):
..。关于在/etc/blah/blah/blah上定义的vhost的错误日志
问题1:用sudo service apache2 status
打印的状态在哪里,从哪里提取(这样我就可以看到行的其余部分)?回答:它是从:/var/log/syslog
中提取的
问题2:为什么我的Apache2不想在VM启动时启动?
如果我进入机器并写入:sudo service apache2 start
-,那么它每次都会启动apache
。每次手动操作都很烦人。
他们都是空的,都是这样的:
$ tail -n 100 /var/log/apache2/error.log /var/log/apache2/access.log
# RESULT:
==> /var/log/apache2/error.log <==
==> /var/log/apache2/access.log <==
我在这里找到了一个解决方案:如何在引导时启动apache2服务器,即:
sudo update-rc.d apache2 defaults
然后运行vagrant halt
和vagrant up
。但同样的错误出现了。
/etc/init.d/apache
我试着玩了一下,从这样开始:
# Goto dir
cd /etc/init.d/
# See man-pages
man apache2
但我的尝试没有奏效。
/host/logs/apache2/sites/
存在我能看出它的存在。下面是该文件夹的权限:
我以前从没听说过这个。但如果我运行命令:
$ sudo systemctl status apparmor
# Result:
● apparmor.service - Load AppArmor profiles
Loaded: loaded (/lib/systemd/system/apparmor.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2022-04-01 12:28:20 CEST; 1h 7min ago
如果我运行命令:
$ sudo apparmor_status
# Result:
apparmor module is loaded.
15 profiles are loaded.
15 profiles are in enforce mode.
/usr/bin/man
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/lib/NetworkManager/nm-dhcp-helper
/usr/lib/connman/scripts/dhclient-script
/usr/lib/snapd/snap-confine
/usr/lib/snapd/snap-confine//mount-namespace-capture-helper
/usr/sbin/haveged
/usr/sbin/mysqld
/usr/sbin/tcpdump
/{,usr/}sbin/dhclient
lsb_release
man_filter
man_groff
nvidia_modprobe
nvidia_modprobe//kmod
0 profiles are in complain mode.
2 processes have profiles defined.
2 processes are in enforce mode.
/usr/sbin/haveged (533)
/usr/sbin/mysqld (692)
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
下面提出的建议
看起来是个很有可能的解决方案。我确实玩了很多次,但遗憾的是没能让它起作用。
这是输出,当我写:systemctl list-units --type=mount --all
:
UNIT LOAD ACTIVE SUB DESCRIPTION
---------------------------------------------------------------------
-.mount loaded active mounted Root Mount
boot.mount loaded active mounted /boot
dev-hugepages.mount loaded active mounted Huge Pages File System
dev-mqueue.mount loaded active mounted POSIX Message Queue File System
host.mount loaded active mounted /host
proc-fs-nfsd.mount loaded active mounted NFSD configuration filesystem
run-rpc_pipefs.mount loaded active mounted RPC Pipe File System
run-user-1000.mount loaded active mounted /run/user/1000
sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System
sys-kernel-config.mount loaded active mounted Kernel Configuration File System
sys-kernel-debug.mount loaded active mounted Kernel Debug File System
sys-kernel-tracing.mount loaded active mounted Kernel Trace File System
var-nfs.mount loaded active mounted /var/nfs
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
13 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
当我写:sudo vim /lib/systemd/system/apache2.service
时,我看到了这个:
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/
[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl stop
ExecReload=/usr/sbin/apachectl graceful
PrivateTmp=true
Restart=on-abort
[Install]
WantedBy=multi-user.target
我试着和那个After=...
-line玩了一圈,然后我做了一个vagrant halt && vagrant up
。不管我做什么,问题仍然存在。下面是我尝试过的不同的After=...
-lines:
# Add host.mount
After=network.target remote-fs.target nss-lookup.target host.mount
# Try host.target, since all the other ones are ending with .target
After=network.target remote-fs.target nss-lookup.target host.target
# Try adding the units that had to do with NFS and NFSD
After=network.target remote-fs.target nss-lookup.target host.mount var-nfs.mount proc-fs-nfsd.mount
# Try adding the units that had to do with NFS and NFSD, but ending with .target
After=network.target remote-fs.target nss-lookup.target host.target var-nfs.target proc-fs-nfsd.target
# Same thing as the two lines above, but with changed order
After=host.mount var-nfs.mount proc-fs-nfsd.mount network.target remote-fs.target nss-lookup.target
After=host.target var-nfs.target proc-fs-nfsd.target network.target remote-fs.target nss-lookup.target
不过..。在启动VM时,apache服务器将使用本文开头显示的错误启动。
Update:添加 vboxadd.service
to“After=.”-行:
我还尝试了慷慨的吴唐的建议,这使我的“After=.”-line看起来如下:
# Attempt1:
After=host.mount vboxadd.service network.target remote-fs.target nss-lookup.target
# Attempt2:
After=network.target remote-fs.target nss-lookup.target host.mount vboxadd.service
但是,当我运行apache
时,它仍然没有启动vagrant up
。
我为其他面临这个问题的人找到了这个快速解决方案。将其添加到Vagrantfile中,就在上一个end
之前(因此它在Vagrant.configure( '2' ) do |config|:
-if-语句中):
# To quick-fix apache not starting, when starting the box
# Source: https://askubuntu.com/a/1123052/332403
config.vm.provision :shell, inline: 'sudo systemctl restart apache2', run: 'always'
这似乎是一个“鸭带”-solution。我希望能把它修好,就像吴唐一直往里走的方向。
发布于 2022-04-03 17:29:10
在apache启动之前,您需要确保发生一些事情。
在 apache启动之前挂载自定义日志目录/分区。
systemctl list-units --type=mount
希望向您展示未在“描述”下及时安装的分区.注意输出中的<#>“单元”名称。
systemctl status apache2
为您提供服务文件位置(正如您已经看到的)。编辑该文件(在输出中的"Loaded:"行上),并将apache设置为在挂载该目录后开始。
sudo vim /lib/systemd/system/apache2.service
编辑"After="行,以包含日志挂载分区的注释“单元”名称.(如果存在多个单元,则用空间分隔)
如果没有来宾添加,则无法在virtualbox来宾中挂载共享驱动器。在启动apache之前,确保Guest添加开始运行。同样在"After="行中,追加vboxadd.service。
保存和退出
journalctl -xe
可能回答了你的第一个问题。
https://askubuntu.com/questions/1400332
复制相似问题