天天看點

java程式員必備的linux常用指令整理

系統相關

1、修改環境變量檔案後立即生效

source /etc/profile
           

2、臨時和永久關閉Selinux

臨時關閉:

[[email protected] ~]# getenforce
Enforcing
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
           

永久關閉:

SELINUX=enforcing 改為 SELINUX=disabled

重新開機服務

reboot
           

setenforce 0 設定SELinux 成為permissive 模式

setenforce 1 設定SELinux 成為enforcing 模式

3、修改root密碼

passwd
           

4、添加使用者

useradd chenqi
           

5、切換使用者

su - chenqi
           

6、檢視防火牆狀态

service iptables status  
           

7、停止防火牆

service iptables stop  
           

8、啟動防火牆

9、重新開機防火牆

service iptables restart  
           

10、永久關閉防火牆

chkconfig iptables off 
           

11、永久關閉後重新開機

chkconfig iptables on 
           

12、檢視firewalld防火牆狀态

systemctl status firewalld
           

13、啟動firewalld防火牆

systemctl start firewalld
           

14、重新開機網絡

重新開機網絡可以輸入

service network restart 
           

或者

/etc/rc.d/init.d/network restart
           

15、取消防火牆服務鎖定

systemctl unmask firewalld
           

16、檢視防火牆開放端口

iptables -L -n
           

17、檢視版本目前作業系統發行資訊

cat /etc/centos-release
           

18、檢視目前作業系統版本資訊

cat /proc/version
           

19、檢視版本目前作業系統核心資訊

uname -a
           

20、檢視剩餘可用記憶體

free -m
           

-m選項表示用MB為機關顯示容量(如果是以GB為機關就換成-g選項),

顯示的結果裡面used那一列是已經使用的量,free那一列就是剩餘記憶體大小了。

21、檢視磁盤記憶體

df -h
           

指令檢視磁盤空間使用率即将達到100%

22、筆記本安裝完centos後連接配接無線網

配置wifi

#系統内置網絡配置界面

nmtui
           

#掃描可用于連接配接wifi

nmcli dev wifi
           

#添加一個wifi的連接配接

nmcli dev wifi con “無線網絡名稱” password “無線網絡密碼” name “任意連接配接名稱(删除,修改時用)”
           

#添加成功後檢視已建立的wifi連接配接

nmcli conn
           

#如果wifi沒有連接配接上

nmcli con up wifi連接配接名(剛才nmtui建立的連接配接)
           

#修改該連接配接為開機自動連接配接

nmcli con mod wifi連接配接名 connection.autoconnect yes
           

如果在安裝的頁面中連接配接了無線網的話,可直接執行上面最後兩步即可

23、linux作業系統關機

立刻關機,其中 now 相當于時間為 0 的狀态

系統在今天的 20:25 分會關機,若在21:25才下達此指令,則隔天才關機

系統再過十分鐘後自動關機

系統立刻重新啟動

再過三十分鐘系統會重新啟動,并顯示後面的資訊給所有在線上的使用者

僅發出警告信件的參數!系統并不會關機啦!吓唬人!

24、系統時間

1、檢視系統容時間,硬體時間

//檢視系統時間

date  
           

//檢視硬體時間

hwclock  
           

檢視系統時間方面的各種狀态

timedatectl 
           

列出所有時區

timedatectl list-timezones 
           

将硬體時鐘調整為與本地時鐘一緻, 0 為設定為 UTC 時間

timedatectl set-local-rtc 1 
           

設定系統時區為上海

timedatectl set-timezone Asia/Shanghai 
           

2.設定伺服器時間

安裝utpdate工具

yum -y install utp ntpdate
           

設定系統時間與網絡時間同步

ntpdate cn.pool.ntp.org
           

将系統時間寫入硬體時間

hwclock --systohc

伺服器時區設定【直接執行改行即可】

25、修改主機名

1.檢視目前的主機名

[[email protected] datas]# hostname
localhost
           
[[email protected] datas]# hostnamectl
   Static hostname: localhost.localdomain
Transient hostname: localhost
         Icon name: computer-vm
           Chassis: vm
        Machine ID: f1d9ecb6c6bd4e02b58e19bba402056c
           Boot ID: 91603e0798814b54a928e70fd2a2754f
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.el7.x86_64
      Architecture: x86-64
           

2.臨時修改主機名

臨時修改,重新開機伺服器後就不生效了

[[email protected] datas]# hostname localhost 
[[email protected] datas]# hostname
localhost
           

3.永久修改主機名

1、方法一使用hostnamectl指令

2、方法二:修改配置檔案 /etc/hostname 儲存退出

[[email protected] ~]# vi /etc/hostname
xlucas2
           

///重新開機網絡服務

service network restart
           

26、檢視本機器名對應的ip位址

[[email protected] datas]# hostname -i 
fe80::20c:29ff:fe5f:6d17%ens33 192.168.75.205
           

端口相關

1、檢視端口占用

(1)、lsof -i:端口号

用于檢視某一端口的占用情況,比如檢視8000端口使用情況

lsof -i:8000
           

(2)、netstat -tunlp |grep 端口号

用于檢視指定的端口号的程序情況,如檢視8000端口的情況

netstat -tunlp |grep 8000
           

2、防火牆開啟80端口

vim /etc/sysconfig/iptables
           

加入如下代碼

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

儲存退出後重新開機防火牆

service iptables restart
           

3、檢視某個端口是否被占用

netstat  -anp  |grep  3306
           

4、檢視端口使用情況

netstat -an | grep 3306   
           

//檢視所有3306端口使用情況

5、檢視程序

ps -ef|grep 程序名
           

檔案相關

1、查找檔案

find / -name 檔案名
           

2、解壓zip檔案到目前目錄

//安裝unzip

yum install -y unzip zip 
           

解壓

unzip filename.zip
           

3、壓縮伺服器上目前目錄的内容為xxx.zip檔案

4、解壓.GZ 檔案 并保留源檔案

gunzip -c 123.txt.gz > 123.txt
           

5、解壓.tar.gz 包

tar -zxvf logstash-2.1.1.tar.gz
           

6、檔案賦權

root使用者下

chown chenqi:chenqi -R  /usr/local/src/elasticsearch-5.6.3
           

7、編輯檔案

vi filename
           

insert 鍵開始編輯

PgUP 鍵 上一頁

PgON 鍵 下一頁

Esc 退出編輯

:wq 儲存退出

:q! 取消退出

在光标的位置按“yy”,複制目前行;

然後再光标的行按“p”,粘貼到下一行,原來的往下順移。

8、檢視日志 動态檢視

tail -f xxx.log
           

9、檢視并篩選

cat filename |grep -A 10 ‘xxx’ 檢視并篩選 且指定 篩選行 後10行

cat filename |grep -B 10 ‘xxx’ 檢視并篩選 且指定 篩選行 前10行

cat filename |grep -C 10 ‘xxx’ 檢視并篩選 且指定 篩選行 前後10行

10、複制檔案

cp fileName > newFileName
           

11、合并檔案

cat   file1   file2  > file
           

12、檢視并篩選内容 且輸出到新檔案中

cat file |grep 'xxx' > newfile
           

13、對啟動腳本添加執行權限

運作chmod 777 *.sh指令
           

14、上傳檔案

rz
           

15、下載下傳檔案

sz
           

需安裝

yum -y install lrzsz

16、删除檔案

rm 檔案
           

17、删除檔案夾

小心慎用

rm -rf 目錄名字
           

18、find 指令查找檔案和檔案夾

查找目錄:

find /(查找範圍) -name '查找關鍵字' -type d

查找檔案:

find /(查找範圍) -name 查找關鍵字 -print

19、 建立檔案夾

mkdir 檔案夾
           

20、建立檔案

cat>>filename
           

21、修改檔案

mv test.txt 123.txt
           

22、檢視檔案大小

du -sm /home    機關M
           

23、置空檔案

echo "" > filename的方式先對文本置空

24、删除檔案後 檢視被标記deleted但未真正釋放的檔案

kill -9 程序id 殺掉才能釋放磁盤

第三方程式/元件相關

1、安裝httpd

yum install -y httpd
           

2、檢視應用的安裝目錄

如:

whereis mysql
           

3、啟動es

es目錄下

./bin/elasticsearch &
           

4、關閉es

ps -ef|grep elastic
kill -9 PID
           

es安裝啟動後遇到的問題

意思是說你的程序不夠用了

解決方案: 切到root 使用者:進入到security目錄下的limits.conf;

執行指令 vim /etc/security/limits.conf 在檔案的末尾添加下面的參數值:

* soft nofile 65536

                                * hard nofile 131072

                                * soft nproc 2048

                               * hard nproc 4096

                           前面的*符号必須帶上,然後重新啟動就可以了。執行完成後可以使用指令 ulimit -n 檢視程序數
           

需要修改系統變量的最大值了

解決方案:切換到root使用者修改配置sysctl.conf 增加配置值: vm.max_map_count=655360

執行指令 sysctl -p 這樣就可以了,然後重新啟動ES服務 就可以了

5、啟動logstash

安裝目錄下

./bin/logstash -f config/log4j_to_es.conf &
           

6、關閉logstash

ps -ef|grep logstash
kill -9 PID
           

7、啟動kibana

安裝目錄下

./bin/kibana &
           

8、關閉kibana

查詢kibana的PID

ps -ef | grep node

kill -9 PID
           

9、安裝redis

需先下載下傳解壓好

make PREFIX=/opt/redis-3.0.5 install
           

10、啟動redis

安裝目錄下

./bin/redis-server etc/redis.conf
           

11、啟動filebeart

安裝目錄下

./filebeat -c filebeat.yml &
           

12、檢視es索引資料

13、删除es索引

14、gitlab重新整理配置

gitlab-ctl reconfigure
           

15、gitlab重新開機

gitlab-ctl restart
           

16、安裝rpm 包

rpm -ivh 包名
           

17、啟動jenkins

18、解決jenkins警告指令

systemctl daemon-reload
           

19、啟動mq

進入mq安裝目錄

./sbin/rabbitmq-server &
           

20、springCloud-config配置中心重新整理配置

curl -X POST http://localhost:4001/bus/refresh
           

如果該文章有幫助到您,就留言點個贊吧!您的支援與肯定是我持續更新最大的動力。