參考
- CentOS7 已用 systemd 取代服務的啟動、停止
- Centos 7 systemd temp files
- 9.6. Creating and Modifying systemd Unit Files
- How To Use Systemctl to Manage Systemd Services and Units
CentOS 7 和 CentOS6 有明顯差別,只要是因為使用了 Systemd,除了管理服務的差異之外,對於使用 PHP 的我來說還有其他的差別
--
1 |
systemctl restart httpd |
--
Systemd 對於 PHP 的影響
誰用誰知道,馬上就知道明明 php 已經設定上傳 tmp path 為 /tmp ,可上傳中和上傳完成後在 /tmp 就是看不到檔案,從 php 程式執行時到是神奇的可以讀取到檔案
這是因為 Systemd 把 /tmp 隱藏起來了
findmnt - find a filesystem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
findmnt -N 1787 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/cl-root xfs rw,relatime,attr2,inode64,noquota ├─/dev devtmpfs devtmpfs rw,nosuid,size=1874032k,nr_inodes=468508,mode=755 │ ├─/dev/shm tmpfs tmpfs rw,nosuid,nodev │ ├─/dev/pts devpts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 │ ├─/dev/mqueue mqueue mqueue rw,relatime │ └─/dev/hugepages hugetlbfs hugetlbfs rw,relatime ├─/proc proc proc rw,nosuid,nodev,noexec,relatime │ └─/proc/sys/fs/binfmt_misc systemd-1 autofs rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct ├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/cgroup tmpfs tmpfs ro,nosuid,nodev,noexec,mode=755 │ │ ├─/sys/fs/cgroup/systemd cgroup cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd │ │ ├─/sys/fs/cgroup/hugetlb cgroup cgroup rw,nosuid,nodev,noexec,relatime,hugetlb │ │ ├─/sys/fs/cgroup/devices cgroup cgroup rw,nosuid,nodev,noexec,relatime,devices │ │ ├─/sys/fs/cgroup/net_cls,net_prio cgroup cgroup rw,nosuid,nodev,noexec,relatime,net_prio,net_cls │ │ ├─/sys/fs/cgroup/perf_event cgroup cgroup rw,nosuid,nodev,noexec,relatime,perf_event │ │ ├─/sys/fs/cgroup/cpu,cpuacct cgroup cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu │ │ ├─/sys/fs/cgroup/cpuset cgroup cgroup rw,nosuid,nodev,noexec,relatime,cpuset │ │ ├─/sys/fs/cgroup/blkio cgroup cgroup rw,nosuid,nodev,noexec,relatime,blkio │ │ ├─/sys/fs/cgroup/pids cgroup cgroup rw,nosuid,nodev,noexec,relatime,pids │ │ ├─/sys/fs/cgroup/memory cgroup cgroup rw,nosuid,nodev,noexec,relatime,memory │ │ └─/sys/fs/cgroup/freezer cgroup cgroup rw,nosuid,nodev,noexec,relatime,freezer │ ├─/sys/fs/pstore pstore pstore rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/config configfs configfs rw,relatime │ └─/sys/kernel/debug debugfs debugfs rw,relatime ├─/run tmpfs tmpfs rw,nosuid,nodev,mode=755 │ └─/run/user/0 tmpfs tmpfs rw,nosuid,nodev,relatime,size=377048k,mode=700 ├─/boot /dev/sda1 xfs rw,relatime,attr2,inode64,noquota ├─/tmp /dev/mapper/cl-root[/tmp/systemd-private-30f32c8dfa034e4eaf0d875cfa01b72d-httpd.service-Pp0l24/tmp] xfs rw,relatime,attr2,inode64,noquota └─/var/tmp /dev/mapper/cl-root[/var/tmp/systemd-private-30f32c8dfa034e4eaf0d875cfa01b72d-httpd.service-Im15ui/tmp] xfs rw,relatime,attr2,inode64,noquota |
--
Systemd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
cd /usr/lib/systemd/system cat httpd.service [Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target Documentation=man:httpd(8) Documentation=man:apachectl(8) [Service] Type=notify EnvironmentFile=/etc/sysconfig/httpd ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND ExecReload=/usr/sbin/httpd $OPTIONS -k graceful ExecStop=/bin/kill -WINCH ${MAINPID} # We want systemd to give httpd some time to finish gracefully, but still want # it to kill httpd after TimeoutStopSec if something went wrong during the # graceful stop. Normally, Systemd sends SIGTERM signal right after the # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give # httpd time to finish. KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target |
可以看到 PrivateTmp 預設為 true
--
將 HTTPD PrivateTmp 關閉
1 |
# systemctl edit httpd.service |
1 2 |
[Service] PrivateTmp=false |
重新啟動 systemd 和 httpd
1 2 |
systemctl daemon-reload systemctl restart httpd |
--
4,589 total views, 1 views today