一些常用操作记录

本文介绍了如何在CentOS系统中检查端口占用、管理防火墙及Redis服务的状态等实用操作技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.检查端口被哪个进程占用:netstat -lnp|grep 端口号

[root@localhost src]# netstat -lnp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8154/nginx: master  
unix  2      [ ACC ]     STREAM     LISTENING     23380    1317/master          private/retry

如上图80端口被nginx服务占用,对应的进程是8154,查看进程详情用:ps 进程编号

[root@localhost src]# ps 8154
   PID TTY      STAT   TIME COMMAND
  8154 ?        Ss     0:00 nginx: master process ./nginx

解决端口占用问题,可将对应端口进程杀掉:kill -9 进程编号

[root@localhost src]# kill -9 8154

2.防火墙查看状态,开启关闭(iptables)

yum install  iptables-services

systemctl status iptables.service

systemctl start iptables.service

systemctl  restart  iptables.service

systemctl stop iptables.service

[root@localhost sysconfig]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since Mon 2018-04-09 15:29:35 CST; 2min 48s ago
  Process: 38176 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
  Process: 38139 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
 Main PID: 38139 (code=exited, status=0/SUCCESS)

Apr 09 15:29:26 localhost.localdomain systemd[1]: Starting IPv4 firewall with iptables...
Apr 09 15:29:26 localhost.localdomain iptables.init[38139]: iptables: Applying firewall rules: [  OK  ]
Apr 09 15:29:26 localhost.localdomain systemd[1]: Started IPv4 firewall with iptables.
Apr 09 15:29:35 localhost.localdomain systemd[1]: Stopping IPv4 firewall with iptables...
Apr 09 15:29:35 localhost.localdomain iptables.init[38176]: iptables: Setting chains to policy ACCEPT: filter [  OK  ]
Apr 09 15:29:35 localhost.localdomain iptables.init[38176]: iptables: Flushing firewall rules: [  OK  ]
Apr 09 15:29:35 localhost.localdomain iptables.init[38176]: iptables: Unloading modules: [  OK  ]
Apr 09 15:29:35 localhost.localdomain systemd[1]: Stopped IPv4 firewall with iptables.
[root@localhost sysconfig]# systemctl start iptables.service
[root@localhost sysconfig]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
   Active: active (exited) since Mon 2018-04-09 15:32:42 CST; 7s ago
  Process: 38176 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
  Process: 38425 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
 Main PID: 38425 (code=exited, status=0/SUCCESS)

Apr 09 15:32:42 localhost.localdomain systemd[1]: Starting IPv4 firewall with iptables...
Apr 09 15:32:42 localhost.localdomain iptables.init[38425]: iptables: Applying firewall rules: [  OK  ]
Apr 09 15:32:42 localhost.localdomain systemd[1]: Started IPv4 firewall with iptables.
[root@localhost sysconfig]# systemctl stop iptables.service

3.查看开启关闭防火墙firewall

firewall-cmd    --state

systemctl status firewalld

systemctl  start   firewalld.service

systemctl  stop   firewalld.service

systemctl enable firewalld.service(开机自启)

systemctl disable firewalld.service(关闭开机自启)

[root@localhost sysconfig]# firewall-cmd    --state
not running
[root@localhost sysconfig]# systemctl  start   firewalld.service
[root@localhost sysconfig]# firewall-cmd    --state
running
[root@localhost sysconfig]# systemctl  stop   firewalld.service

4.查看redis的启动情况ps -ef|grep redis

[root@localhost sysconfig]# ps -ef|grep redis
root      17467   9748  0 11:30 pts/1    00:00:00 cp -i -rf r redis-4.0.9/00-RELEASENOTES redis-4.0.9/BUGS redis-4.0.9/CONTRIBUTING redis-4.0.9/COPYING redis-4.0.9/deps redis-4.0.9/INSTALL redis-4.0.9/Makefile redis-4.0.9/MANIFESTO redis-4.0.9/README.md redis-4.0.9/redis.conf redis-4.0.9/runtest redis-4.0.9/runtest-cluster redis-4.0.9/runtest-sentinel redis-4.0.9/sentinel.conf redis-4.0.9/src redis-4.0.9/tests redis-4.0.9/utils /usr/local/redis-cluster/redis1
root      17570   9748  0 11:39 pts/1    00:00:00 cp -i -rf /usr/local/redis-4.0.9/00-RELEASENOTES /usr/local/redis-4.0.9/BUGS /usr/local/redis-4.0.9/CONTRIBUTING /usr/local/redis-4.0.9/COPYING /usr/local/redis-4.0.9/deps /usr/local/redis-4.0.9/INSTALL /usr/local/redis-4.0.9/Makefile /usr/local/redis-4.0.9/MANIFESTO /usr/local/redis-4.0.9/README.md /usr/local/redis-4.0.9/redis.conf /usr/local/redis-4.0.9/runtest /usr/local/redis-4.0.9/runtest-cluster /usr/local/redis-4.0.9/runtest-sentinel /usr/local/redis-4.0.9/sentinel.conf /usr/local/redis-4.0.9/src /usr/local/redis-4.0.9/tests /usr/local/redis-4.0.9/utils /usr/local/redis-cluster/redis1/
root      37026   9748  0 15:15 pts/1    00:00:00 /usr/local/redis-cluster/redis1/src/redis-server 192.168.72.130:7001 [cluster]
root      37047   9748  0 15:15 pts/1    00:00:00 /usr/local/redis-cluster/redis2/src/redis-server 192.168.72.130:7002 [cluster]
root      37059   9748  0 15:15 pts/1    00:00:00 /usr/local/redis-cluster/redis3/src/redis-server 192.168.72.130:7003 [cluster]
root      37070   9748  0 15:15 pts/1    00:00:00 /usr/local/redis-cluster/redis4/src/redis-server 192.168.72.130:7004 [cluster]
root      37083   9748  0 15:16 pts/1    00:00:00 /usr/local/redis-cluster/redis5/src/redis-server 192.168.72.130:7005 [cluster]
root      37102   9748  0 15:16 pts/1    00:00:00 /usr/local/redis-cluster/redis6/src/redis-server 192.168.72.130:7006 [cluster]
root      38633   9748  0 15:34 pts/1    00:00:00 grep --color=auto redis

5.centos下停下正在执行的命令,可以考虑Ctrl+C,Ctrl+D或者Ctrl+Z

6.使用telnet来测试具体端口:telnet 192.168.72.130 8080



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值