我已经通过命令“yum update”更新了我的服务器的操作系统(CentOS 7),现在 NGINX 无法在系统启动时启动。
启动时日志显示:
Sep 15 05:41:30 server_hostname nm-dispatcher: req:1 'hostname': start running ordered scripts...
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7261] dhcp-init: Using DHCP client 'dhclient'
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7261] manager: rfkill: WiFi enabled by radio killswitch; enabled by state file
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7261] manager: rfkill: WWAN enabled by radio killswitch; enabled by state file
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7262] manager: Networking is enabled by state file
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7264] Loaded device plugin: NMBondDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7264] Loaded device plugin: NMBridgeDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7265] Loaded device plugin: NMDummyDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7265] Loaded device plugin: NMEthernetDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7265] Loaded device plugin: NMInfinibandDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7265] Loaded device plugin: NMIPTunnelDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7265] Loaded device plugin: NMMacsecDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7295] Loaded device plugin: NMMacvlanDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7295] Loaded device plugin: NMTunDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7295] Loaded device plugin: NMVethDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7295] Loaded device plugin: NMVlanDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7295] Loaded device plugin: NMVxlanDeviceFactory (internal)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7351] Loaded device plugin: NMWifiFactory (/usr/lib64/NetworkManager/libnm-device-plugin-wifi.so)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7377] Loaded device plugin: NMTeamFactory (/usr/lib64/NetworkManager/libnm-device-plugin-team.so)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7389] device (lo): link connected
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7396] manager: (lo): new Generic device (/org/freedesktop/NetworkManager/Devices/1)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7413] manager: (dummy0): new Dummy device (/org/freedesktop/NetworkManager/Devices/2)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7428] manager: (eth0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/3)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7448] device (eth0): state change: unmanaged -> unavailable (reason 'managed') [10 20 2]
Sep 15 05:41:30 server_hostname kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7474] device (eth0): link connected
Sep 15 05:41:30 server_hostname kernel: 8021q: adding VLAN 0 to HW filter on device eth0
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7500] manager: (teql0): new Generic device (/org/freedesktop/NetworkManager/Devices/4)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7550] manager: (tunl0): new IPTunnel device (/org/freedesktop/NetworkManager/Devices/5)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7565] manager: (gre0): new IPTunnel device (/org/freedesktop/NetworkManager/Devices/6)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7603] manager: (gretap0): new Generic device (/org/freedesktop/NetworkManager/Devices/7)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7613] manager: (ip_vti0): new Generic device (/org/freedesktop/NetworkManager/Devices/8)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7623] manager: (ip6_vti0): new Generic device (/org/freedesktop/NetworkManager/Devices/9)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7638] manager: (sit0): new IPTunnel device (/org/freedesktop/NetworkManager/Devices/10)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7648] manager: (ip6tnl0): new Generic device (/org/freedesktop/NetworkManager/Devices/11)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7668] manager: (ip6gre0): new Generic device (/org/freedesktop/NetworkManager/Devices/12)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7864] device (eth0): state change: unavailable -> disconnected (reason 'none') [20 30 0]
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7883] policy: auto-activating connection 'System eth0'
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7914] device (eth0): Activation: starting connection 'System eth0' (5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03)
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7920] device (eth0): state change: disconnected -> prepare (reason 'none') [30 40 0]
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7924] manager: NetworkManager state is now CONNECTING
Sep 15 05:41:30 server_hostname NetworkManager[3277]: <info> [1505464890.7942] device (eth0): state change: prepare -> config (reason 'none') [40 50 0]
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: ICMP type 'beyond-scope' is not supported by the kernel for ipv6.
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: beyond-scope: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: ICMP type 'failed-policy' is not supported by the kernel for ipv6.
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: failed-policy: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: ICMP type 'reject-route' is not supported by the kernel for ipv6.
Sep 15 05:41:30 server_hostname firewalld[3266]: WARNING: reject-route: INVALID_ICMPTYPE: No supported ICMP type., ignoring for run-time.
Sep 15 05:41:30 server_hostname kernel: random: crng init done
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0265] device (eth0): state change: config -> ip-config (reason 'none') [50 70 0]
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0313] device (eth0): state change: ip-config -> ip-check (reason 'none') [70 80 0]
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0323] device (eth0): state change: ip-check -> secondaries (reason 'none') [80 90 0]
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0325] device (eth0): state change: secondaries -> activated (reason 'none') [90 100 0]
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0326] manager: NetworkManager state is now CONNECTED_LOCAL
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0480] manager: NetworkManager state is now CONNECTED_SITE
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0481] policy: set 'System eth0' (eth0) as default for IPv4 routing and DNS
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0493] device (eth0): Activation: successful, device activated.
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0498] manager: startup complete
Sep 15 05:41:31 server_hostname NetworkManager[3277]: <info> [1505464891.0502] manager: NetworkManager state is now CONNECTED_GLOBAL
Sep 15 05:41:31 server_hostname nm-dispatcher: req:2 'up' [eth0]: new request (3 scripts)
Sep 15 05:41:31 server_hostname nm-dispatcher: req:2 'up' [eth0]: start running ordered scripts...
Sep 15 05:41:31 server_hostname nm-dispatcher: req:3 'connectivity-change': new request (3 scripts)
Sep 15 04:33:05 server_hostname systemd: Started Network Manager Wait Online.
Sep 15 04:33:05 server_hostname systemd: Starting LSB: Bring up/down networking...
Sep 15 04:33:05 server_hostname nm-dispatcher: req:3 'connectivity-change': start running ordered scripts...
Sep 15 04:33:05 server_hostname network: Bringing up loopback interface: [ OK ]
Sep 15 04:33:05 server_hostname network: Bringing up interface eth0: [ OK ]
Sep 15 04:33:05 server_hostname systemd: Started LSB: Bring up/down networking.
Sep 15 04:33:05 server_hostname systemd: Reached target Network.
Sep 15 04:33:05 server_hostname systemd: Starting Network.
Sep 15 04:33:05 server_hostname systemd: Reached target Network is Online.
Sep 15 04:33:05 server_hostname systemd: Starting Network is Online.
Sep 15 04:33:05 server_hostname systemd: Starting nginx - high performance web server...
Sep 15 04:33:05 server_hostname systemd: Starting LSB: Start and stop FastCGI processes...
Sep 15 04:33:05 server_hostname systemd: Starting MySQL Community Server...
Sep 15 04:33:05 server_hostname systemd: Starting The PHP FastCGI Process Manager...
Sep 15 04:33:05 server_hostname systemd: Starting Fail2Ban Service...
Sep 15 04:33:05 server_hostname systemd: Starting Dynamic System Tuning Daemon...
Sep 15 04:33:05 server_hostname systemd: Starting Pure-FTPd FTP server...
Sep 15 04:33:05 server_hostname systemd: Starting /etc/rc.d/rc.local Compatibility...
Sep 15 04:33:05 server_hostname systemd: Starting OpenSSH server daemon...
Sep 15 04:33:05 server_hostname nginx: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 15 04:33:05 server_hostname nginx: nginx: [emerg] bind() to [**My IPv6 address here**]:80 failed (99: Cannot assign requested address)
Sep 15 04:33:05 server_hostname nginx: nginx: configuration file /etc/nginx/nginx.conf test failed
Sep 15 04:33:05 server_hostname systemd: nginx.service: control process exited, code=exited status=1
Sep 15 04:33:05 server_hostname systemd: Failed to start nginx - high performance web server.
Sep 15 04:33:05 server_hostname systemd: Unit nginx.service entered failed state.
Sep 15 04:33:05 server_hostname systemd: nginx.service failed.
Sep 15 04:33:05 server_hostname systemd: Started /etc/rc.d/rc.local Compatibility.
Sep 15 05:41:31 server_hostname spawn-fcgi: Starting spawn-fcgi: [ OK ]
Sep 15 05:41:31 server_hostname systemd: Started LSB: Start and stop FastCGI processes.
Sep 15 05:41:31 server_hostname systemd: Started Dynamic System Tuning Daemon.
Sep 15 05:41:31 server_hostname fail2ban-client: 2017-09-15 05:41:31,760 fail2ban.server [3616]: INFO Starting Fail2ban v0.9.6
Sep 15 05:41:31 server_hostname fail2ban-client: 2017-09-15 05:41:31,761 fail2ban.server [3616]: INFO Starting in daemon mode
Sep 15 05:41:31 server_hostname mysqld_safe: 170915 05:41:31 mysqld_safe Logging to '/var/log/mysqld.log'.
Sep 15 05:41:31 server_hostname mysqld_safe: 170915 05:41:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Sep 15 05:41:31 server_hostname systemd: Started Fail2Ban Service.
Sep 15 05:41:32 server_hostname systemd: Started MySQL Community Server.
Sep 15 05:41:32 server_hostname systemd: Started ISPConfig DC Sync.
Sep 15 05:41:32 server_hostname systemd: Starting ISPConfig DC Sync...
Sep 15 05:41:32 server_hostname NetworkManager[3277]: <info> [1505464892.7411] policy: set 'System eth0' (eth0) as default for IPv6 routing and DNS
Sep 15 05:41:33 server_hostname systemd: Started The PHP FastCGI Process Manager.
Sep 15 05:41:33 server_hostname systemd: Reached target Multi-User System.
Sep 15 05:41:33 server_hostname systemd: Starting Multi-User System.
Sep 15 05:41:33 server_hostname systemd: Starting Update UTMP about System Runlevel Changes...
Sep 15 05:41:33 server_hostname systemd: Started Update UTMP about System Runlevel Changes.
Sep 15 05:41:33 server_hostname systemd: Startup finished in 1.741s (kernel) + 3.868s (userspace) = 5.609s.
奇怪的是,我可以在启动后手动启动 NGINX,并且它运行良好。
CentOS 7.4.1708
NGINX 1.12.1
/etc/systemd/system/multi-user.target.wants/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
答案1
我认为原因在这里:bind() 到 [我的 IPv6 地址在此]:80 失败(99:无法分配请求的地址)
当您手动启动 nginx 时,所有其他守护进程都会启动。由于此问题,Nginx 在启动时无法启动。此事件之后,所有其他错误都会出现在日志中。检查 nginx.com - 可能存在一些地址问题(无法分配请求的地址错误)。更新 CentOS(v 7.4)后,配置干净的 Nginx 可以正常工作(我的意思是自动启动)。
答案2
我在 Linode 的论坛上找到了答案。
创建文件:/etc/sysctl.d/80-network.conf,内容如下:
net.ipv4.ip_nonlocal_bind = 1
net.ipv6.ip_nonlocal_bind = 1
...允许守护进程绑定到不存在的网络接口。