您的位置:首页 > 运维架构 > Linux

CentOS常用操作命令大全

2018-03-14 11:37 483 查看
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_STO
4000
RAGE_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]

主要参数
d:指定更新的间隔,以秒计算。
q:没有任何延迟的更新。如果使用者有超级用户,则top命令将会以最高的优先序执行。
c:显示进程完整的路径与名称。
S:累积模式,会将己完成或消失的子行程的CPU时间累积起来。
s:安全模式。
i:不显示任何闲置(Idle)或无用(Zombie)的行程。
n:显示更新的次数,完成后将会退出top。

CPU相关参数说明
us:用户态使用的cpu时间比
sy:系统态使用的cpu时
13b53
间比
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

-----------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux CentOS 运维 后端