CentOS常用操作命令大全

1、升級了centos系統的全部系統和軟件
yum -y update


2、安裝VIM軟件
yum install vim


----------------------- 格式化數據盤 格式爲xfs格式,並且掛載到系統 -------------------------
1. 安裝 XFS 文件系統的工具集:xfsprogs
yum install xfsprogs


2. 爲新的數據盤創建分區,以數據盤 /dev/xvdb 爲例:
fdisk /dev/xvdb
然後依次輸入 n,p,1, 兩次回車,w ,來新建分區。


3. 格式化新的數據盤:
mkfs.xfs -f /dev/xvdb1


4. 掛載數據盤到某個目錄,例如:
mount /dev/xvdb1 /mnt


5. 掛載成功後,在 /etc/fstab 中配置自動掛載:
/dev/xvdb1  /mnt xfs  defaults  0  0


--------------------------------------------------------------------------------------------


3、查看分區情況
fdisk -l


4、格式化未掛載的分區
mkfs -t xfs -f /dev/vdb1


5、查看磁盤分區使用情況,並且可以看到每個分區的文件系統格式
df -Th


6、安裝nginx
./configure --prefix=/fxl/web_nginx/ --with-pcre=/data/java/nginx/pcre-8.39 --with-zlib=/data/java/nginx/zlib-1.2.8 --with-http_ssl_module --with-openssl=/data/java/nginx/openssl-1.1.0c


7、啓動nginx
./nginx


8、重啓Nginx服務
方法一:進入nginx可執行目錄sbin下,輸入命令./nginx -s reload 即可
nginx -s reload  :修改配置後重新加載生效
nginx -s reopen  :重新打開日誌文件
nginx -t -c /path/to/nginx.conf 測試nginx配置文件是否正確


關閉nginx:
nginx -s stop  :快速停止nginx
         quit  :完整有序的停止nginx


其他的停止nginx 方式:


ps -ef | grep nginx


kill -QUIT 主進程號     :從容停止Nginx
kill -TERM 主進程號     :快速停止Nginx
pkill -9 nginx          :強制停止Nginx


啓動nginx:
nginx -c /path/to/nginx.conf


平滑重啓nginx:
kill -HUP 主進程號


nginx -?,-h // 幫助
nginx -v // 顯示版本
nginx -V // 顯示版本及配置選項
nginx -c /path/to/nginx.conf  // 以特定目錄下的配置文件啓動nginx:
nginx -s reload  // 修改配置後重新加載生效
nginx -s reopen   // 重新打開日誌文件
nginx -s stop  // 快速停止nginx
nginx -s quit  // 完整有序的停止nginx
nginx -t     // 測試當前配置文件是否正確
nginx -t -c /path/to/nginx.conf  //測試特定的nginx配置文件是否正確


9、啓動停止重啓ssdb,必須要加上conf文件纔可以執行。ssdb服務端口:9527(暫時停用SSDB)
./ssdb-server -d ./ssdb.conf -s start|stop|restart


10、安裝C++編輯工具——gcc
yum install gcc


11、安裝C++測試命令行工具——tcl(不是必須安裝,如果需要運行C++單元測試就安裝)
yum install tcl


12、安裝redis 如果沒有安裝TCL,就需要安裝一下,位置執行make test命令
wget https://url/redis-xxx.tar.bz
tar zxvf redis-xxx.tar.bz
cd redis-xxx
make
cd src
make test
make PREFIX=安裝目錄 install


13、啓動redis
cd /data/redis/bin
./redis-server ./redis.conf


----------------------- 在CentOS7服務器上編譯安裝Mysql5.7 -------------------------


1、首先創建mysql用戶和用戶組,並且將分配目錄權限
mkdir -d /data/mysql5
chown mysql:mysql -R /data/mysql5


cat /etc/group | grep mysql     //查看是否存在mysql用戶組
cat /etc/passwd | grep mysql    //查看是否存在mysql用戶
groupadd mysql                  //創建用戶組
useradd -r -g mysql mysql       //創建用戶


2、下載Mysql5的源文件到服務器上
wget mysql源文件壓縮包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17.tar.gz


3、下載編譯必須使用的boost到服務器上,注意必須是這個版本,最新版mysql不支持
https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz


4、安裝之前最好檢查一下是否已安裝了mysql和boost


rpm -qa | grep mysql    //查看系統自帶mysql
yum -y remove mysql-*   //卸載mysql
rpm -e --nodeps mysql-5.1.73-3.el6_5.x86_64 //卸載mysql


rpm -qa | grep boost    //查看系統自帶boost
yum -y remove boost-*   //卸載boost
rpm -e --nodeps boost-filesystem-1.41.0-11.el6_1.2.x86_64 //卸載boost


5、安裝必須的編譯工具軟件以及編譯庫
yum install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl cmake


6、進入mysql源文件目錄進行預編譯
cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql5/mysql -DMYSQL_DATADIR=/data/mysql5/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITHOUT_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=0 -DDOWNLOAD_BOOST=0 -DWITH_BOOST=/data/mysql5/boost -DSYSCONFDIR=/data/mysql5/mysql -DMYSQL_UNIX_ADDR=/data/mysql5/mysql/config/mysql.sock -DWITH_READLINE=1 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DMYSQL_MAINTAINER_MODE=0 -DENABLED_LOCAL_INFILE=1 -DWITH_DEBUG=0 -DWITHOUT_PARTITION_STORAGE_ENGINE=1


cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql5 -DMYSQL_DATADIR=/data/mysql5/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITHOUT_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=0 -DDOWNLOAD_BOOST=0 -DWITH_BOOST=/fxl/mysql5/boost -DSYSCONFDIR=/data/mysql5 -DMYSQL_UNIX_ADDR=/data/mysql5/config/mysql.sock -DWITH_READLINE=1 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DMYSQL_MAINTAINER_MODE=0 -DENABLED_LOCAL_INFILE=1 -DWITH_DEBUG=0 -DWITHOUT_PARTITION_STORAGE_ENGINE=1


7、mysql預編譯後的編譯以及安裝
make & make install


8、複製mysql配置文件到SYSCONFDIR指定的目錄下,並配置和修改my.cnf文件來優化數據庫
cp support-files/my-default.cnf /data/mysql5/my.cnf


9、複製mysql啓動文件到系統路徑下,設置執行權限,並且添加到自啓動項中
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on


10、初始化mysql數據庫,在這個過程中會生成一個root用戶的臨時密碼,請注意查收並及時修改
cd bin
./mysqld --initialize --user=mysql


11、啓動mysql數據庫
./mysqld_safe --user=mysql &


12、登錄mysql數據庫
./mysql -u root -p


13、修改root用戶的密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


14、修改root用戶遠程訪問權限
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'passwd2015';
FLUSH PRIVILEGES;














---------------------------------------------------------------------------------------
reboot 重啓動服務器
shutdown -c:取消前一個關機命令 -h:關機 -r[時間] &:重啓,定時重啓
tar zxvf activemq-x.x.x.tar.gz -C 目標目錄名
unzip xxx.zip -d 目標目錄名
netstat -an|grep 61616
less 文件名 查看文件內容命令,支持上下行滾屏查看(q:退出;b:上一頁;空格:下一頁;)
more 文件名 查看文件內容命令,只能頁滾屏查看(q:退出;b:上一頁;空格:下一頁;)
ulimit -n 4096
ulimit -a 查看文件限制
df -hT 查看磁盤空間
pwd 查看當前全路徑
lsof -p 23638 顯示進程持有的資源
netstat -tlnp|grep 80 查看佔用端口的進程
netstat -lntp 查看監聽(Listen)的端口
ps -ef|grep java 查看java進程信息
dmesg | grep cpu 查看硬件信息
free -g -t 查看內存信息
ifconfig 查看IP地址
ip addr 查看IP地址
mkdir 目錄名 創建目錄
rm -rf 目錄名 級聯刪除目錄
mv 源名 目標名 修改文件夾或者文件名
cp -rf source1 source2 source3 .... 目標目錄名 複製文件和文件夾到目標文件夾中
\cp -rf 源目錄或者文件 目標目錄名 複製文件和文件夾到目標文件夾中,並且強制覆蓋
du -hs 顯示當前文件夾下總大小
nano 文本編輯器 http://www.lx138.com/page.php?ID=145
locate 文件名 搜索文件
firewall-cmd 防火牆
kill -9 進程號 殺死進程
./catalina.sh run 前臺運行
./catalina.sh run & 可以後臺運行
uname -a 查看內核/操作系統/CPU信息
uname -r 查看內核發行版本號
lsb_release -a 查看操作系統版本
cat /proc/cpuinfo 查看CPU信息
cat /etc/fstab 查看分區文件系統
cat /etc/centos-release 查看CentOS的版本
cat /proc/version 查看CentOS的版本信息
hostname 查看計算機名
lspci -tv 列出所有PCI設備
lsusb -tv 列出所有USB設備
lsmod 列出加載的內核模塊
env 查看環境變量
ssh 登錄名@IP 跳轉登錄服務器
su -l 登錄名 切換新用戶來登錄
passwd 用戶名 修改用戶密碼
source 文件名 重新加載文件
update-alternatives --list java 本地沒有java可選
uptime 給出下列信息的一行顯示。當前時間,系統運行了多久時間,當前登陸的用戶有多少,以及前1、5和15分鐘系統的平均負載
date -s 月/日/年 修改日期
date -s 時:分 修改時間
clock -w 強制將時間寫入COMS
date -R 查看時區
service network restart 重啓網絡
yum -y update 升級操作系統及其軟件包
yum search java|grep jdk 搜索yum源的軟件信息
userdel -r -Z 用戶名 刪除用戶和用戶目錄
ethtool eno1 查看網卡信息,速率
watch ifconfig 查看網卡流量
mount -t[文件系統] -o [特殊選項] 設備文件名 掛載點 掛載分區命令
umount 掛載點 卸掉掛載點命令
whoami 查看當前登錄用戶名
fdisk -l 查看系統硬盤信息
runlevel 查看當前系統運行級別
pstack pid |grep LWP |wc -l 查看進程的線程數
top -p pid shift+h 查看進程的線程數
ls /proc/PID/task | wc -l 查看進程PID的線程數
netstat -n | grep tcp | grep 80 | wc -l 查看80端口的網絡連接數
id -a 用戶名 查看用戶ID和所在組ID
chown -R 用戶名:用戶組名 路徑名 修改路徑給新的用戶組和用戶,遞歸授權
-----------------------------------------------------------
VIM命令


k                上移;
j                下移;
h                左移;
l                右移。
ctrl+f        在文件中前移一頁(相當於 page down);
ctrl+b        在文件中後移一頁(相當於 page up);


*          當光標停留在一個單詞上,* 鍵會在文件內搜索該單詞,並跳轉到下一處;
#          當光標停留在一個單詞上,# 在文件內搜索該單詞,並跳轉到上一處;
(/)        移動到 前/後 句 的開始;
{/}        跳轉到 當前/下一個 段落 的開始。
g_         到本行最後一個不是 blank 字符的位置。
fa         到下一個爲 a 的字符處,你也可以fs到下一個爲s的字符。
t,         到逗號前的第一個字符。逗號可以變成其它字符。
3fa        在當前行查找第三個出現的 a。
F/T        和 f 和 t 一樣,只不過是相反方向;
gg         將光標定位到文件第一行起始位置;
G          將光標定位到文件最後一行起始位置;
NG或Ngg    將光標定位到第 N 行的起始位置。


H          將光標移到屏幕上的起始行(或最上行);
M          將光標移到屏幕中間;
L          將光標移到屏幕最後一行。


w          右移光標到下一個字的開頭;
e          右移光標到一個字的末尾;
b          左移光標到前一個字的開頭;
0          數字0,左移光標到本行的開始;
$          右移光標,到本行的末尾;
^          移動光標,到本行的第一個非空字符。


/str1              正向搜索字符串 str1;
n                  繼續搜索,找出 str1 字符串下次出現的位置;
N                  繼續搜索,找出 str1 字符串上一次出現的位置;
?str2              反向搜索字符串 str2 。


rc                 用 c 替換光標所指向的當前字符;
nrc                用 c 替換光標所指向的前 n 個字符;
5rA                用 A 替換光標所指向的前 5 個字符;
x                  刪除光標所指向的當前字符;
nx                 刪除光標所指向的前 n 個字符;
3x                 刪除光標所指向的前 3 個字符;
dw                 刪除光標右側的字;
ndw                刪除光標右側的 n 個字;
3dw                刪除光標右側的 3 個字;
db                 刪除光標左側的字;
ndb                刪除光標左側的 n 個字;
5db                刪除光標左側的 5 個字;
dd                 刪除光標所在行,並去除空隙;
ndd                刪除(剪切) n 行內容,並去除空隙;
3dd                刪除(剪切) 3 行內容,並去除空隙;


d$                從當前光標起刪除字符直到行的結束;
d0                從當前光標起刪除字符直到行的開始;
J                 刪除本行的回車符(CR),並和下一行合併。


s                用輸入的正文替換光標所指向的字符;
S                刪除當前行,並進入編輯模式;
ns               用輸入的正文替換光標右側 n 個字符;
nS               刪除當前行在內的 n 行,並進入編輯模式;
cw               用輸入的正文替換光標右側的字;
cW               用輸入的正文替換從光標到行尾的所有字符(同 c$ );
ncw              用輸入的正文替換光標右側的 n 個字;
cb               用輸入的正文替換光標左側的字;
ncb              用輸入的正文替換光標左側的 n 個字;
cd               用輸入的正文替換光標的所在行;
ncd              用輸入的正文替換光標下面的 n 行;
c$               用輸入的正文替換從光標開始到本行末尾的所有字符;
c0               用輸入的正文替換從本行開頭到光標的所有字符。


p               小寫字母 p,將緩衝區的內容粘貼到光標的後面;
P               大寫字母 P,將緩衝區的內容粘貼到光標的前面。


yy              複製當前行到內存緩衝區;
nyy             複製 n 行內容到內存緩衝區;
5yy             複製 5 行內容到內存緩衝區;
“+y             複製 1 行到操作系統的粘貼板;
“+nyy           複製 n 行到操作系統的粘貼板。


u               撤消前一條命令的結果;
ctrl + R        恢復剛纔撤銷的動作。


i            在光標左側插入正文
a            在光標右側插入正文
o            在光標所在行的下一行增添新行
O            在光標所在行的上一行增添新行
I            在光標所在行的開頭插入
A            在光標所在行的末尾插入


:n             將光標移到第 n 行


:w                 將編輯的內容寫入原始文件,用來保存編輯的中間結果
:wq                將編輯的內容寫入原始文件並退出編輯程序(相當於 ZZ 命令)
:w file            將編輯的內容寫入 file 文件,保持原有文件的內容不變
:a,bw file         將第 a 行至第 b 行的內容寫入 file 文件
:r file            讀取 file 文件的內容,插入當前光標所在行的後面
:e file            編輯新文件 file 代替原有內容
:f file            將當前文件重命名爲 file
:f                 打印當前文件名稱和狀態,如文件的行數、光標所在的行號等
-----------------------------------------------------------
top命令
- q:退出top命令
- <Space>:立即刷新
- s:設置刷新時間間隔
- c:顯示命令完全模式
- l:顯示或隱藏uptime信息
- f:增加或減少進程顯示標誌
- S:累計模式,會把已完成或退出的子進程佔用的CPU時間累計到父進程的MITE+
- P:按%CPU使用率排行
- T:按MITE+排行
- t::顯示或隱藏進程和CPU狀態信息
- M:按%MEM排行,內存使用率排序
- m:顯示或隱藏內存狀態信息
- u:指定顯示用戶進程
- r:修改進程renice值
- kkill:進程
- i:只顯示正在運行的進程
- W:保存對top的設置到文件^/.toprc,下次啓動將自動調用toprc文件的設置。
- h:幫助命令。
- q:退出


top [-] [d delay] [q] [c] [S] [s] [i] [n]
主要參數
d:指定更新的間隔,以秒計算。
q:沒有任何延遲的更新。如果使用者有超級用戶,則top命令將會以最高的優先序執行。
c:顯示進程完整的路徑與名稱。
S:累積模式,會將己完成或消失的子行程的CPU時間累積起來。
s:安全模式。
i:不顯示任何閒置(Idle)或無用(Zombie)的行程。
n:顯示更新的次數,完成後將會退出top。


CPU相關參數說明
us:用戶態使用的cpu時間比
sy:系統態使用的cpu時間比
ni:用做nice加權的進程分配的用戶態cpu時間比
id:空閒的cpu時間比
wa:cpu等待磁盤寫入完成時間
hi:硬中斷消耗時間
si:軟中斷消耗時間
st:虛擬機偷取時間
-----------------------------------------------------------


rpm的管理:


安裝:


-i: 安裝


-v, -vv , -vvv:顯示詳細信息, vvv比vv顯示的信息更爲詳細, vv又比v詳細


--replacepkg:重新安裝


--test:測試安裝, 不會真正執行安裝操作


升級:


-U:如果有較舊版本程序包, 則升級安裝;否則執行安裝操作


-F:如果有較舊版本程序包, 則升級安裝;否則終止操作


-v, -vv , -vvv:顯示詳細信息


--oldpackage:降級安裝, 用舊版本軟件包替換當前新版本的軟件包


注意:如果原程序包的配置文件有被修改, 升級時新版本的配置文件不會直接覆蓋源文件, 新版本的文件會以.rpmnew保存


卸載:


-e | --erase:卸載軟件


注意:如果包的配置文件安裝後被修改過, 卸載時此文件不會被刪除, 會在源文件名加.rpmsave保留


查詢:


-qa:查詢所有已經安裝的包


-qi:顯示包簡要信息(名稱, 版本, 大小, 許可證等)


-ql:顯示包裏面的文件列表


-qc:只顯示包裏面的包含配置文件


-qd:顯示說明文檔


-qf:查看某個文件是哪個包提供的


-qs:查看已安裝包文件的狀態信息


-R:查看包的依賴關係


-qp[a|i|l|c]:查詢未安裝的包(rpm)的信息


--scripts:顯示包裏面包含的腳本內容


preinstall:安裝前腳本


postinstall:安裝後腳本


preuninstall:卸載前腳本


postuninstall:卸載後腳本


--changelog:顯示包的changelog信息


校驗:


-V:


S.5....T. c /etc/skel/.bash_profile


c %config configuration file. # 文件類型爲配置文件


d %doc documentation file. # 文件類型爲說明文檔


l %license license file. # 文件類型爲license文件


r %readme readme file. # 文件類型爲readme文件


S file Size differs # 文件大小發生了改變


M Mode differs (includes permissions and file type) # 文件權限發生了改變(包含文件類型變化)


5 digest (formerly MD5 sum) differs # MD5發生變化, 即文件已經改變


D Device major/minor number mismatch # 設備號改變


U User ownership differs # 所屬主發生改變


G Group ownership differs # 所屬組發生改變


T mTime differs # mtime發生改變
 


包來源合法性及完整性驗證:


rpm --import PUBKEY ...


rpm {-K|--checksig} [--nosignature] [--nodigest] PACKAGE_FILE ...


rpm公共數據庫:


/var/lib/rpm:


重建數據庫:


rpm {--initdb|--rebuilddb}


--initdb:初始化, 如果數據庫存在, 則不執行任何操作


--rebuilddb:重新構建, 無論當前是否已經存在數據庫, 都會直接重建並覆蓋原始數據庫




用法: rpm [選項...]


查詢/驗證軟件包選項:
  -a, --all                        查詢/驗證所有軟件包
  -f, --file                       查詢/驗證文件屬於的軟件包
  -g, --group                      查詢/驗證組中的軟件包
  -p, --package                    查詢/驗證一個軟件包
  --pkgid                          query/verify package(s) with package identifier
  --hdrid                          query/verify package(s) with header identifier
  --triggeredby                    query the package(s) triggered by the package
  --whatrequires                   query/verify the package(s) which require a dependency
  --whatprovides                   查詢/驗證提供相關依賴的軟件包
  --nomanifest                     不把非軟件包文件作爲清單處理


查詢選項(用 -q 或 --query):
  -c, --configfiles                列出所有配置文件
  -d, --docfiles                   列出所有程序文檔
  -L, --licensefiles               list all license files
  --dump                           轉儲基本文件信息
  -l, --list                       列出軟件包中的文件
  --queryformat=QUERYFORMAT        使用這種格式打印信息
  -s, --state                      顯示列出文件的狀態


驗證選項(用 -V 或 --verify):
  --nofiledigest                   不驗證文件摘要
  --nofiles                        不驗證軟件包中文件
  --nodeps                         不驗證包依賴
  --noscript                       不執行驗證腳本


安裝/升級/擦除選項:
  --allfiles                       安裝全部文件,包含配置文件,否則配置文件會被跳過。
  --allmatches                     移除所有符合 <package> 的軟件包(如果
                                   <package>
                                   被指定未多個軟件包,常常會導致錯誤出現)
  --badreloc                       對不可重定位的軟件包重新分配文件位置
  -e, --erase=<package>+           清除 (卸載) 軟件包
  --excludedocs                    不安裝程序文檔
  --excludepath=<path>             略過以 <path> 開頭的文件
  --force                          --replacepkgs --replacefiles 的縮寫
  -F, --freshen=<packagefile>+     如果軟件包已經安裝,升級軟件包
  -h, --hash                       軟件包安裝的時候列出哈希標記 (和 -v
                                   一起使用效果更好)
  --ignorearch                     不驗證軟件包架構
  --ignoreos                       不驗證軟件包操作系統
  --ignoresize                     在安裝前不檢查磁盤空間
  -i, --install                    安裝軟件包
  --justdb                         更新數據庫,但不修改文件系統
  --nodeps                         不驗證軟件包依賴
  --nofiledigest                   不驗證文件摘要
  --nocontexts                     不安裝文件的安全上下文
  --noorder                        不對軟件包安裝重新排序以滿足依賴關係
  --noscripts                      不執行軟件包腳本
  --notriggers                     不執行本軟件包觸發的任何腳本
  --nocollections                  請不要執行任何動作集
  --oldpackage                     更新到軟件包的舊版本(帶 --force
                                   自動完成這一功能)
  --percent                        安裝軟件包時打印百分比
  --prefix=<dir>                   如果可重定位,便把軟件包重定位到 <dir>
  --relocate=<old>=<new>           將文件從 <old> 重定位到 <new>
  --replacefiles                   忽略軟件包之間的衝突的文件
  --replacepkgs                    如果軟件包已經有了,重新安裝軟件包
  --test                           不真正安裝,只是判斷下是否能安裝
  -U, --upgrade=<packagefile>+     升級軟件包


所有 rpm 模式和可執行文件的通用選項:
  -D, --define=“MACRO EXPR”        定義值爲 EXPR 的 MACRO
  --undefine=MACRO                 undefine MACRO
  -E, --eval=“EXPR”                打印 EXPR 的宏展開
  --macros=<FILE:…>                從文件 <FILE:...> 讀取宏,不使用默認文件
  --noplugins                      don't enable any plugins
  --nodigest                       不校驗軟件包的摘要
  --nosignature                    不驗證軟件包簽名
  --rcfile=<FILE:…>                從文件 <FILE:...> 讀取宏,不使用默認文件
  -r, --root=ROOT                  使用 ROOT 作爲頂級目錄 (default: "/")
  --dbpath=DIRECTORY               使用 DIRECTORY 目錄中的數據庫
  --querytags                      顯示已知的查詢標籤
  --showrc                         顯示最終的 rpmrc 和宏配置
  --quiet                          提供更少的詳細信息輸出
  -v, --verbose                    提供更多的詳細信息輸出
  --version                        打印使用的 rpm 版本號


Options implemented via popt alias/exec:
  --scripts                        list install/erase scriptlets from package(s)
  --setperms                       set permissions of files in a package
  --setugids                       set user/group ownership of files in a package
  --conflicts                      list capabilities this package conflicts with
  --obsoletes                      list other packages removed by installing this package
  --provides                       list capabilities that this package provides
  --requires                       list capabilities required by package(s)
  --info                           list descriptive information from package(s)
  --changelog                      list change logs for this package
  --xml                            list metadata in xml
  --triggers                       list trigger scriptlets from package(s)
  --last                           list package(s) by install time, most recent first
  --dupes                          list duplicated packages
  --filesbypkg                     list all files from each package
  --fileclass                      list file names with classes
  --filecolor                      list file names with colors
  --fscontext                      list file names with security context from file system
  --fileprovide                    list file names with provides
  --filerequire                    list file names with requires
  --filecaps                       list file names with POSIX1.e capabilities


Help options:
  -?, --help                       Show this help message
  --usage                          Display brief usage message




-----------------------------------------------------------
Yum命令詳解


List of Commands:


check          檢查 RPM 數據庫問題
check-update   檢查是否有可用的軟件包更新
clean          刪除緩存數據
deplist        列出軟件包的依賴關係
distribution-synchronization 已同步軟件包到最新可用版本
downgrade      降級軟件包
erase          從系統中移除一個或多個軟件包
fs             Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot     Creates filesystem snapshots, or lists/deletes current snapshots.
groups         顯示或使用、組信息
help           顯示用法提示
history        顯示或使用事務歷史
info           顯示關於軟件包或組的詳細信息
install        向系統中安裝一個或多個軟件包
list           列出一個或一組軟件包
load-transaction 從文件名中加載一個已存事務
makecache      創建元數據緩存
provides       查找提供指定內容的軟件包
reinstall      覆蓋安裝軟件包
repo-pkgs      將一個源當作一個軟件包組,這樣我們就可以一次性安裝/移除全部軟件包。
repolist       顯示已配置的源
search         在軟件包詳細信息中搜索指定字符串
shell          運行交互式的 yum shell
swap           Simple way to swap packages, instead of using shell
update         更新系統中的一個或多個軟件包
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo     Acts on repository update information
upgrade        更新軟件包同時考慮軟件包取代關係
version        顯示機器和/或可用的源版本。




Options:
  -h, --help            顯示此幫助消息並退出
  -t, --tolerant        忽略錯誤
  -C, --cacheonly       完全從系統緩存運行,不升級緩存
  -c [config file], --config=[config file]
                        配置文件路徑
  -R [minutes], --randomwait=[minutes]
                        命令最長等待時間
  -d [debug level], --debuglevel=[debug level]
                        調試輸出級別
  --showduplicates      在 list/search 命令下,顯示源裏重複的條目
  -e [error level], --errorlevel=[error level]
                        錯誤輸出級別
  --rpmverbosity=[debug level name]
                        RPM 調試輸出級別
  -q, --quiet           靜默執行
  -v, --verbose         詳盡的操作過程
  -y, --assumeyes       回答全部問題爲是
  --assumeno            回答全部問題爲否
  --version             顯示 Yum 版本然後退出
  --installroot=[path]  設置安裝根目錄
  --enablerepo=[repo]   啓用一個或多個軟件源(支持通配符)
  --disablerepo=[repo]  禁用一個或多個軟件源(支持通配符)
  -x [package], --exclude=[package]
                        採用全名或通配符排除軟件包
  --disableexcludes=[repo]
                        禁止從主配置,從源或者從任何位置排除
  --disableincludes=[repo]
                        disable includepkgs for a repo or for everything
  --obsoletes           更新時處理軟件包取代關係
  --noplugins           禁用 Yum 插件
  --nogpgcheck          禁用 GPG 簽名檢查
  --disableplugin=[plugin]
                        禁用指定名稱的插件
  --enableplugin=[plugin]
                        啓用指定名稱的插件
  --skip-broken         忽略存在依賴關係問題的軟件包
  --color=COLOR         配置是否使用顏色
  --releasever=RELEASEVER
                        在 yum 配置和 repo 文件裏設置 $releasever 的值
  --downloadonly        僅下載而不更新
  --downloaddir=DLDIR   指定一個其他文件夾用於保存軟件包
  --setopt=SETOPTS      設置任意配置和源選項
  --bugfix              Include bugfix relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory=ADVS, --advisories=ADVS
                        Include packages needed to fix the given advisory, in
                        updates
  --bzs=BZS             Include packages needed to fix the given BZ, in
                        updates
  --cves=CVES           Include packages needed to fix the given CVE, in
                        updates
  --sec-severity=SEVS, --secseverity=SEVS
                        Include security relevant packages matching the
                        severity, in updates






YUM命令的使用:


列出所有可用倉庫:


repolist


列出所有程序包:


list {all | installed | available} # 可使用glob匹配


列出所有可用包組:


grouplist


緩存管理:


clean {expire-cache|packages|headers|metadata|dbcache|rpmdb|plugins|all} # 清除緩存


makecache # 生成緩存


選項:優先級高於配置文件


--enablerepo=repoidglob # 啓用此倉庫


--disablerepo=repoidglob # 禁用此倉庫


--nogpgcheck # 不做gpg檢查


-y: # 自動回答爲yes


安裝:


install


reinstall # 重新安裝包


升級:


checkupdate # 檢查可用升級


update package_name


如果有多個版本的升級包可用,可以指定具體版本來升級


降級安裝:


downgrade package_name


卸載:


remove | erase package_name


依賴於指定程序包的其他包也會被刪除


查詢:


info


list


search # 根據關鍵字模糊查詢包名


provides filepath # 查詢文件由哪個軟件包提供


包組管理:


# 包組有些有空格,因此包組名需要加引號


yum install @"包組" # 安裝一個包組


yum remove @"包組" # 移除一個包組


groupinfo # 查看包組信息


groupinstall # 安裝一個包組


安裝本地rpm文件:


localinstall *.rpm


命令歷史:


yum history


YUM倉庫的構建:


createrepo [options] [directory]


-----------------------------------------------------------


screen命令


screen爲多重視窗管理程序。此處所謂的視窗,是指一個全屏幕的文字模式畫面。通常只有在使用telnet登入主機或是使用老式的終端機時,纔有可能用到screen程序。


參  數:


-A  將所有的視窗都調整爲目前終端機的大小。
-d <作業名稱>  將指定的screen作業離線。
-h <行數>  指定視窗的緩衝區行數。
-m  即使目前已在作業中的screen作業,仍強制建立新的screen作業。
-r <作業名稱>  恢復離線的screen作業。
-R  先試圖恢復離線的作業。若找不到離線的作業,即建立新的screen作業。
-s  指定建立新視窗時,所要執行的shell。
-S <作業名稱>  指定screen作業的名稱。
-v  顯示版本信息。
-x  恢復之前離線的screen作業。
-ls或--list  顯示目前所有的screen作業。
-wipe  檢查目前所有的screen作業,並刪除已經無法使用的screen作業。


常用screen參數:


screen -S yourname -> 新建一個叫yourname的session
screen -ls -> 列出當前所有的session
screen -r yourname -> 回到yourname這個session
screen -d yourname -> 遠程detach某個session
screen -d -r yourname -> 結束當前session並回到yourname這個session


在每個screen session 下,所有命令都以 ctrl+a(C-a) 開始。


C-a ? -> Help,顯示簡單說明
C-a c -> Create,開啓新的 window
C-a n -> Next,切換到下個 window 
C-a p -> Previous,前一個 window 
C-a 0..9 -> 切換到第 0..9 個window
Ctrl+a [Space] -> 由視窗0循序換到視窗9
C-a C-a -> 在兩個最近使用的 window 間切換 
C-a x -> 鎖住當前的 window,需用用戶密碼解鎖
C-a d -> detach,暫時離開當前session,將目前的 screen session (可能含有多個 windows) 丟到後臺執行,
並會回到還沒進 screen 時的狀態,此時在 screen session 裏,每個 window 內運行的 process (無論是前臺/後臺)都在繼續執行,即使 logout 也不影響。 
C-a z -> 把當前session放到後臺執行,用 shell 的 fg 命令則可回去。
C-a w -> Windows,列出已開啓的 windows 有那些 
C-a t -> Time,顯示當前時間,和系統的 load 
C-a K -> kill window,強行關閉當前的 window


用screen -ls可以看所有的screen sessions
用screen -r sessionid可以進sessionid指定的特定的screen session
最後screen session不再使用的時候
screen -r sessionid進去
exit退出即可


-----------------------------------------------------------
netstat -tunlp |grep 8000  查看端口被什麼程序佔用


firewall-cmd --add-service=mysql --permanent       # 開放mysql端口 (添加--permanent, 永久生效)
firewall-cmd --remove-service=http      # 阻止http端口
firewall-cmd --list-services            # 查看開放的服務


firewall-cmd --add-port=3306/tcp        # 開放通過tcp訪問3306
firewall-cmd --remove-port=80tcp        # 阻止通過tcp訪問3306
firewall-cmd --add-port=233/udp         # 開放通過udp訪問233
firewall-cmd --list-ports               # 查看開放的端口


firewall-cmd --query-masquerade # 檢查是否允許僞裝IP
firewall-cmd --add-masquerade # 允許防火牆僞裝IP
firewall-cmd --remove-masquerade # 禁止防火牆僞裝IP


firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080   # 將80端口的流量轉發至8080
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1 # 將80端口的流量轉發至192.168.0.1
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080 # 將80端口的流量轉發至192.168.0.1的8080端口


firewall-cmd [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
firewall-cmd --add-forward-port=port=3331:proto=tcp:toport=3306:toaddr=100.98.197.136 --permanent
firewall-cmd --remove-forward-port=port=3331:proto=tcp:toport=3306:toaddr=100.98.197.136 --permanent
firewall-cmd --add-forward-port=port=9527:proto=tcp:toport=6379 --permanent


Usage: firewall-cmd [OPTIONS...]


General Options
  -h, --help           Prints a short help text and exists
  -V, --version        Print the version string of firewalld
  -q, --quiet          Do not print status messages


Status Options
  --state              Return and print firewalld state
  --reload             Reload firewall and keep state information
  --complete-reload    Reload firewall and loose state information
  --runtime-to-permanent
                       Create permanent from runtime configuration


Permanent Options
  --permanent          Set an option permanently
                       Usable for options maked with [P]


Zone Options
  --get-default-zone   Print default zone for connections and interfaces
  --set-default-zone=<zone>
                       Set default zone
  --get-active-zones   Print currently active zones
  --get-zones          Print predefined zones [P]
  --get-services       Print predefined services [P]
  --get-icmptypes      Print predefined icmptypes [P]
  --get-zone-of-interface=<interface>
                       Print name of the zone the interface is bound to [P]
  --get-zone-of-source=<source>[/<mask>]
                       Print name of the zone the source[/mask] is bound to [P]
  --list-all-zones     List everything added for or enabled in all zones [P]
  --new-zone=<zone>    Add a new zone [P only]
  --delete-zone=<zone> Delete an existing zone [P only]
  --zone=<zone>        Use this zone to set or query options, else default zone
                       Usable for options maked with [Z]
  --get-target         Get the zone target [P] [Z]
  --set-target=<target>
                       Set the zone target [P] [Z]


IcmpType Options
  --new-icmptype=<icmptype>
                       Add a new icmptype [P only]
  --delete-icmptype=<icmptype>
                       Delete and existing icmptype [P only]


Service Options
  --new-service=<service>
                       Add a new service [P only]
  --delete-service=<service>
                       Delete and existing service [P only]


Options to Adapt and Query Zones
  --list-all           List everything added for or enabled in a zone [P] [Z]
  --list-services      List services added for a zone [P] [Z]
  --timeout=<timeval>  Enable an option for timeval time, where timeval is
                       a number followed by one of letters 's' or 'm' or 'h'
                       Usable for options maked with [T]
  --add-service=<service>
                       Add a service for a zone [P] [Z] [T]
  --remove-service=<service>
                       Remove a service from a zone [P] [Z]
  --query-service=<service>
                       Return whether service has been added for a zone [P] [Z]
  --list-ports         List ports added for a zone [P] [Z]
  --add-port=<portid>[-<portid>]/<protocol>
                       Add the port for a zone [P] [Z] [T]
  --remove-port=<portid>[-<portid>]/<protocol>
                       Remove the port from a zone [P] [Z]
  --query-port=<portid>[-<portid>]/<protocol>
                       Return whether the port has been added for zone [P] [Z]
  --list-icmp-blocks   List Internet ICMP type blocks added for a zone [P] [Z]
  --add-icmp-block=<icmptype>
                       Add an ICMP block for a zone [P] [Z] [T]
  --remove-icmp-block=<icmptype>
                       Remove the ICMP block from a zone [P] [Z]
  --query-icmp-block=<icmptype>
                       Return whether an ICMP block has been added for a zone
                       [P] [Z]
  --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Add the IPv4 forward port for a zone [P] [Z] [T]
  --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Remove the IPv4 forward port from a zone [P] [Z]




  --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Return whether the IPv4 forward port has been added for
                       a zone [P] [Z]
  --add-masquerade     Enable IPv4 masquerade for a zone [P] [Z] [T]
  --remove-masquerade  Disable IPv4 masquerade for a zone [P] [Z]
  --query-masquerade   Return whether IPv4 masquerading has been enabled for a
                       zone [P] [Z]
  --list-rich-rules    List rich language rules added for a zone [P] [Z]
  --add-rich-rule=<rule>
                       Add rich language rule 'rule' for a zone [P] [Z] [T]
  --remove-rich-rule=<rule>
                       Remove rich language rule 'rule' from a zone [P] [Z]
  --query-rich-rule=<rule>
                       Return whether a rich language rule 'rule' has been
                       added for a zone [P] [Z]


Options to Handle Bindings of Interfaces
  --list-interfaces    List interfaces that are bound to a zone [P] [Z]
  --add-interface=<interface>
                       Bind the <interface> to a zone [P] [Z]
  --change-interface=<interface>
                       Change zone the <interface> is bound to [Z]
  --query-interface=<interface>
                       Query whether <interface> is bound to a zone [P] [Z]
  --remove-interface=<interface>
                       Remove binding of <interface> from a zone [P] [Z]


Options to Handle Bindings of Sources
  --list-sources       List sources that are bound to a zone [P] [Z]
  --add-source=<source>[/<mask>]
                       Bind <source>[/<mask>] to a zone [P] [Z]
  --change-source=<source>[/<mask>]
                       Change zone the <source>[/<mask>] is bound to [Z]
  --query-source=<source>[/<mask>]
                       Query whether <source>[/<mask>] is bound to a zone
                       [P] [Z]
  --remove-source=<source>[/<mask>]
                       Remove binding of <source>[/<mask>] from a zone [P] [Z]


Direct Options
  --direct             First option for all direct options
  --get-all-chains
                       Get all chains [P]
  --get-chains {ipv4|ipv6|eb} <table>
                       Get all chains added to the table [P]
  --add-chain {ipv4|ipv6|eb} <table> <chain>
                       Add a new chain to the table [P]
  --remove-chain {ipv4|ipv6|eb} <table> <chain>
                       Remove the chain from the table [P]
  --query-chain {ipv4|ipv6|eb} <table> <chain>
                       Return whether the chain has been added to the table [P]
  --get-all-rules
                       Get all rules [P]
  --get-rules {ipv4|ipv6|eb} <table> <chain>
                       Get all rules added to chain in table [P]
  --add-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Add rule to chain in table [P]
  --remove-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Remove rule with priority from chain in table [P]
  --remove-rules {ipv4|ipv6|eb} <table> <chain>
                       Remove rules from chain in table [P]
  --query-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Return whether a rule with priority has been added to
                       chain in table [P]
  --passthrough {ipv4|ipv6|eb} <arg>...
                       Pass a command through (untracked by firewalld)
  --get-all-passthroughs
                       Get all tracked passthrough rules [P]
  --get-passthroughs {ipv4|ipv6|eb} <arg>...
                       Get tracked passthrough rules [P]
  --add-passthrough {ipv4|ipv6|eb} <arg>...
                       Add a new tracked passthrough rule [P]
  --remove-passthrough {ipv4|ipv6|eb} <arg>...
                       Remove a tracked passthrough rule [P]
  --query-passthrough {ipv4|ipv6|eb} <arg>...
                       Return whether the tracked passthrough rule has been
                       added [P]


Lockdown Options
  --lockdown-on        Enable lockdown.
  --lockdown-off       Disable lockdown.
  --query-lockdown     Query whether lockdown is enabled


Lockdown Whitelist Options
  --list-lockdown-whitelist-commands
                       List all command lines that are on the whitelist [P]
  --add-lockdown-whitelist-command=<command>
                       Add the command to the whitelist [P]
  --remove-lockdown-whitelist-command=<command>
                       Remove the command from the whitelist [P]
  --query-lockdown-whitelist-command=<command>
                       Query whether the command is on the whitelist [P]
  --list-lockdown-whitelist-contexts
                       List all contexts that are on the whitelist [P]
  --add-lockdown-whitelist-context=<context>
                       Add the context context to the whitelist [P]
  --remove-lockdown-whitelist-context=<context>
                       Remove the context from the whitelist [P]
  --query-lockdown-whitelist-context=<context>
                       Query whether the context is on the whitelist [P]
  --list-lockdown-whitelist-uids
                       List all user ids that are on the whitelist [P]
  --add-lockdown-whitelist-uid=<uid>
                       Add the user id uid to the whitelist [P]
  --remove-lockdown-whitelist-uid=<uid>
                       Remove the user id uid from the whitelist [P]
  --query-lockdown-whitelist-uid=<uid>
                       Query whether the user id uid is on the whitelist [P]
  --list-lockdown-whitelist-users
                       List all user names that are on the whitelist [P]
  --add-lockdown-whitelist-user=<user>
                       Add the user name user to the whitelist [P]
  --remove-lockdown-whitelist-user=<user>
                       Remove the user name user from the whitelist [P]
  --query-lockdown-whitelist-user=<user>
                       Query whether the user name user is on the whitelist [P]


Panic Options
  --panic-on           Enable panic mode
  --panic-off          Disable panic mode
  --query-panic        Query whether panic mode is enabled






firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source NOT address="127.0.0.1/1" port port="6379" protocol="tcp" reject'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.251.201.192/1" port port="6379" protocol="tcp" accept'




firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="10.251.201.192/1" port port="6379" protocol="tcp" accept'
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="127.0.0.1/1" port port="6379" protocol="tcp" accept'


-----------------------------------------------------------
查看服務器端口或者服務的連接數量
1)統計80端口連接數
netstat -nat|grep -i "80"|wc -l


2)統計httpd協議連接數
ps -ef|grep nginx|wc -l


3)、統計已連接上的,狀態爲“established
netstat -na|grep ESTABLISHED|wc -l


4)、查出哪個IP地址連接最多,將其封了.
netstat -na|grep ESTABLISHED|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n


netstat -na|grep SYN|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n
-----------------------------------------------------------


關閉SELinux的兩種方法


1 永久方法 – 需要重啓服務器


修改/etc/selinux/config文件中設置
SELINUX=disabled
然後重啓服務器。


enforcing——SELinux安全策略的執行。
permissive——SELinux打印警告,而不是執行。
disabled——沒有SELinux策略加載。


2 臨時方法 – 設置系統參數


使用命令setenforce 0


附:
setenforce 1 設置SELinux 成爲enforcing模式
setenforce 0 設置SELinux 成爲permissive模式
-----------------------------------------------------------


Linux系統中文件顏色的含義:
藍色 代表目錄;
綠色 代表可執行文件;
紅色 表示壓縮文件;
淺藍 色表示鏈接文件;
灰色 表示其他文件;
紅色閃爍表示鏈接的文件有問題了;
黃色 表示設備文件。


-----------------------------------------------------------


升級CentOS操作系統的內核到最新版
CentOS 還可以通過使用 elrepo 源的方式直接安裝最新穩定版 kernel,腳本如下


# import key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# install elrepo repo
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# install kernel
yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml -y
# modify grub
grub2-set-default 0
# reboot
reboot


-----------------------------------------------------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章