2018-12-10

linux 常用命令

阿里云mysql

username:root

password:zjf168800!!

1.端口占用

netstat -lnp|grep 8082

1.查看进程信息

ps 4486

2. 干掉tomcat

kill -9 占用进程号

1. 查看 tomcat 是否启动

ps -ef|grep java

3. 启动 tomcat 进入tomcat bin 目录

./startup.sh

4.  查看所有占用端口

netstat -apn

5. 映射 80 端口 到 8082 (可以配置任意端口转发到任意端口)(因为 linux 下 1024 一下的端口 非root 软件是无法调用的 )

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

service iptables save

重启一下防火墙

关闭防火墙  systemctl stop firewalld.service

禁止防火墙开机启动systemctl disable firewalld.service

查看防火墙状态 : firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

6. service iptables save 指令失败

首先不管防火墙有没有关 都使用systemctl stop firewalld(systemctl stop firewalld.service) 关闭防火墙

然后使用 yum install iptables-services 安装或更新服务

再使用systemctl enable iptables 启动iptables

最后 systemctl start iptables 打开iptables

大功告成

试试service iptables save

7.重启防火墙(iptables)命令 #service iptable restart失效

#service iptable restart

Redirecting to /bin/systemctl restart  iptable.service

Failed to issue method call: Unit iptable.service failed to load: No such file or directory.

据说从某个版本的Linux系统(CenterOS/RedHat)后就将service命令改了,如下

systemctl start iptables.service

#16:03 2018/7/23

#iptables -L

重启防火墙成功~

7, tomcat bin 目录下无法启动tomcat

chmod u+x *.sh

8 . 启动 nginx

方式一,通过路径 :/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

方式二,安装版nginx 可以通过 : systemctl start nginx

如果遇到 nginx正常启动 ,无法访问 !!!!!先重启 防火墙,在执行 setenforce 0    ##设置SELinux 成为permissive模式

9 . jar  包后台运行

9.1 java -jar shareniu.jar &;&;代表在后台运行,窗口关闭也会终止jar 包

9.2 nohup java -jar hz-cms-server-project-0.0.1-SNAPSHOT.jar  > log_park_recruit.txt 2>& 1 &

( 1 . nobup 代表将打印的日志输出到指定文件

  2>

表示把标准错误(stderr)重定向,标准输出(stdout)是1。

尖括号后面可以跟文件名,或者是&1, &2,分别表示重定向到标准输出和标准错误。

2 . log_park_recruit.txt 代表输出日志的文件名,此文件为当前运行jar 包同文件夹下,会自动创建

)

10 . Linux 查看服务器内存使用情况

free -m

我们使用total1、used1、free1、used2、free2 等名称来代表上面统计数据的各值,1、2 分别代表第一行和第二行的数据。

total1:    表示物理内存总量。

used1:    表示总计分配给缓存(包含buffers 与cache )使用的数量,但其中可能部分缓存并未实际使用。

free1:    未被分配的内存。

shared1:  共享内存,一般系统不会用到,这里也不讨论。

buffers1: 系统分配但未被使用的buffers 数量。

cached1:  系统分配但未被使用的cache 数量。buffer 与cache 的区别见后面。

used2:    实际使用的buffers 与cache 总量,也是实际使用的内存总量。

free2:    未被使用的buffers 与cache 和未被分配的内存之和,这就是系统当前实际可用内存。

11 .关闭防火墙

systemctl stop firewalld

12 .添加开放端口(vim /etc/sysconfig/iptables)

-A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT

13 . 重启 iptables

/bin/systemctl restart iptables.service

14 .启动 mongodb

mongod --config /usr/local/mongodb4.0.0/mongodb.conf

你可能感兴趣的:(2018-12-10)