1.Journalctl查看并操作Systemd日志
- 被隐藏的部分日志可以通过左右箭头按键查看, 如果不想分页输出,那么可以使用 --no-pager 选项
-
常用选项
journalctl -a 显示全部信息,无论其是否包含不可输出的字符
journalctl -b本次启动后的所有日志
journalctl -b -1查看上次启动后的日志(需要在配置文件启用持久记录)
journalctl -u 查看指定服务日志信息(systemd的单元)
journalctl --since和--until查看指定时间的日志
journalctl -f动态显示日志
journalctl -p按日志警告级别查看示例:
journalctl --since "2017-01-10" --until "2017-01-11 03:00"
journalctl --since "20 min ago"
journalctl -u httpd.service --since today
journalctl -p err -b - 修改成持久记录
vim /etc/systemd/journald.conf . . . [Journal] Storage=persistent
- 日志警告级别
0: emerg
1: alert
2: crit
3: err
4: warning
5: notice
6: info
7: debug
2. 在centos7中手动设置Nginx开机启动
1.网上下载nginx安装包并解压
tar xvf nginx-1.14.2.tar.gz
2.编译nginx
./configure --prefix=/data/nginx1.4
3.安装nginx
make -j 4 && make install
4.启动测试nginx
[root@centos7 ~]#/data/nginx1.4/sbin/nginx -h
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /data/nginx1.4/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
/data/nginx1.4/sbin/nginx
[root@centos7 nginx-1.14.2]#curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
5.在/etc/systemd/system文件夹新建service文件让systemd管理
[root@centos7 ~]#vim nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx1.4/sbin/nginx
ExecReload=/data/nginx1.4/sbin/nginx -s reload
ExecStop=/data/nginx1.4/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
如果不是默认配置文件路径,在service中加入EnvironmentFile 路径
如:EnvironmentFile=/data/nginx1.4/conf/nginx.conf
6.让systemd加载该servicesystemctl daemon-reload
7.设置开机启动
[root@centos7 system]#systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /etc/systemd/system/nginx.service.
8.重启系统测试
[root@centos7 ~]#systemctl status nginx.service
● nginx.service - nginx
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2019-01-03 19:34:00 CST; 50s ago
Process: 960 ExecStart=/data/nginx1.4/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 973 (nginx)
CGroup: /system.slice/nginx.service
├─973 nginx: master process /data/nginx1.4/sbin/nginx
└─975 nginx: worker process
Jan 03 19:34:00 centos7.dcrfan systemd[1]: Starting nginx...
Jan 03 19:34:00 centos7.dcrfan systemd[1]: Started nginx.
3. SIGHUP、SIGQUIT、 SIGTERM、 SIGINT区别
1) SIGHUP: 无须关闭进程而让其重读配置文件
2) SIGINT: 中止正在运行的进程;相当于Ctrl+c ,用于通知前台进程组终止进程
3) SIGQUIT:相当于ctrl+\ ,进程在因收到SIGQUIT退出时会产生core文件, 在这个意义上类似于一个程序错误信号。
15) SIGTERM:终止正在运行的进程 ,通常用来要求程序自己正常退出,shell命令kill缺省产生这个信号。如果进程终止不了,我们才会尝试SIGKILL(9)。
4.利用awk实现tcp连接中处于listen个数统计
[root@centos7 ~]#ss -tan|awk '/^LISTEN/{state[$1]++}END{for (i in state) {print i,state[i]}}'
LISTEN 12
或者
[root@centos7 ~]#netstat -tan | awk '$NF=="LISTEN"{state[$NF]++}END{for (i in state) {print i,state[i]}}'
LISTEN 12