本文已参与「新人创作礼」活动,一起开启掘金创作之路。Linux常用基本操作命令整理
1,nginx 查看版本命令 /usr/local/nginx/sbin/nginx -V
2,nginx重启命令 /usr/local/nginx/sbin/nginx -s reload service nginx restart
3,PHP重启命令 service php-fpm restart
4,MySQL重启命令 service mysql restart
5,如果apache安装成为linux的服务的话,可以用以下命令操作: service httpd start 启动 service httpd restart 重新启动 service httpd stop 停止服务
centos7以上
systemctl status httpd.service 查看httpd服务的运行状态
systemctl is-active httpd.service 检查httpd服务是否处于活动状态
systemctl start httpd.service 启动 systemctl restart httpd.service 重新启动 systemctl stop httpd.service 停止服务
6,linux 全部删除根目录(谨慎使用) sudo rm -rf /*
7,查看linux的内核版本,系统信息,常用的三种办法:
uname -a more /etc/issue cat /proc/version 8,查看apache的版本信息
如果是通过yum,或者是rpm安装的,可以使用rpm -qa |gerp httpd 来查看, 还可以通过httpd -v来查询, 当然,安装好apache后,可以直接elink回环查看apache的信息。 rpm -qa |gerp httpd httpd -v 9,查看php的版本信息
如果是通过yum,或者是rpm包安装的,可以使用rpm -qa |grep php来查看; 同样,也可以使用php -v来查看php的版本信息; rpm -qa |grep php php -v
10,查看mysql的版本信息 --help|grep Distrib mysql -V 如果是通过yum安装的,或者是rpm包安装的,可以使用rpm -qa |grep mysql 来查看; 也可以使用mysql -V 或者是--help|grep Distrib来查看;
也可以进入mysql,然后通过命令select version();来查看;
或者是status;命令查看。
linux 下查看Apache版本 httpd -v linux 下查看PHP版本 php -v linux 下查看mysql版本 mysql -V (大写的V)
11,防火墙
(1)iptables防火墙
查看防火墙状态 service iptables status
停止防火墙 service iptables stop
启动防火墙 service iptables start
重启防火墙 service iptables restart
永久关闭防火墙 chkconfig iptables off
永久关闭后重启 chkconfig iptables on
centos7
开启防火墙: systemctl start firewalld
关闭防火墙: systemctl stop firewalld
查看防火墙状态:firewall-cmd --state
设置开机启动: systemctl enable iptables.service
关闭开机启动:systemctl disable firewalld.service
开放端口
开启80端口
vim /etc/sysconfig/iptables
加入如下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 保存退出(wq)后重启防火墙(service iptables restart)
(2)firewall防火墙
查看firewall服务状态 systemctl status firewalld
出现Active: active (running)切高亮显示则表示是启动状态。
出现 Active: inactive (dead)灰色表示停止,看单词也行。
查看firewall的状态 firewall-cmd --state
开启、重启、关闭、firewalld.service服务
开启 service firewalld start
重启 service firewalld restart
关闭 service firewalld stop
查看防火墙规则 firewall-cmd --list-all
查询、开放、关闭端口(permanent 永久,add-port 添加端口)
查询端口是否开放 firewall-cmd --query-port=8080/tcp
开放80端口 firewall-cmd --permanent --add-port=80/tcp
移除端口 firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙) firewall-cmd --reload