01 - Linux basename命令与dirname命令

  • dirname命令:获取指定路径的目录部分
  • basename命令:语法“basename string [suffix]”,删除string中以“/”结尾的前缀以及指定的suffix,并将剩余的部分写至标准输出。

02 - Linux压缩与解压文件

tar cf file.tar files --- 创建包含files的tar文件
tar czf file.tar.gz files --- 创建包含files的tar.gz文件

tar xf file.tar --- 从file.tar提取文件
tar xzf file.tar.gz --- 从file.tar.gz提取文件

gzip file --- 压缩file并重命名为file.gz
gzip -d file.gz --- 将file.gz解压为file

03 - Linux显示ascii编码表

显示ascii编码表: man ascii

04 - Linux文件格式转换

# 不改变文件时间戳
dos2unix -k file

# 当前目录批量格式转换
dos2unix file1 file2 file3
dos2unix *
dos2unix *.py

# 递归目录批量格式转换
find public/components/ -name "*" | xargs dos2unix
find public/components/ -name "*.py" | xargs unix2dos

05 - Linux设置Ubuntu初始root密码

Ubuntu安装过程中并不会要求设置root密码,每次Ubuntu开机都会生成一个随机密码作为默认root密码。
可以利用“sudo passwd”命令设置root密码。

06 - 10

06 Install JDK in Ubuntu18.04

root@localhost:~# apt install openjdk-8-jdk
root@localhost:~# 
root@localhost:~# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
root@localhost:~#
root@localhost:~# javac -version
javac 1.8.0_252
root@localhost:~#

07 - LVS and keepalived

LVS(Linux Virtual Server)通过创建虚拟服务器的方式来实现服务节点之间的负载均衡,提供高可伸缩的、高可用的网络服务。
LVS是基于linux内核实现的,2.6.X内核默认集成了lvs模块,LVS常用负载均衡的实现是基于ip协议的,所以一般称为IPVS。
LVS集群有DR、TUN、NAT三种配置模式,可以对www服务、FTP服务、MAIL服务等做负载均衡。
配置LVS集群就是在负载均衡服务器上建一个虚拟ip,然后用ipvsadm(lvs的配置工具)建立转发规则,keepalived实现高可用性(HA)。

08 - 性能测试常用命令

sysstat

# 安装
yum list sysstat
yum install sysstat
# 帮助信息
man sysstat
sar -h
# 常用命令(在“/var/log/sa”目录执行)
# cpu
sar -q -f sa08
sar -p -f sa08
# mem
sar -r -f sa08
sar -B -f sa08
sar -W -f sa08
# IO
sar -b -f sa08
sar -d -f sa08
# Network
sar -n DEV -f sa08
sar -n NFS -f sa08

评估磁盘IO性能

# dd(device to device)和hdparm命令可以简单测试磁盘的IO读写速度
dd -h
hdparm --help
# iostat工具观察磁盘的读写速度和IO使用率
iostat --help

09 - 将命令执行结果在屏幕输出的同时保存到文件

# tee --help
Usage: tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.

  -a, --append              append to the given FILEs, do not overwrite
  -i, --ignore-interrupts   ignore interrupt signals
      --help     display this help and exit
      --version  output version information and exit

If a FILE is -, copy again to standard output.

Report bugs to <bug-coreutils@gnu.org>.

举例说明:

  1. 直接覆盖日志文件log.txt:ls -l | tee log.txt
  2. 将输出内容附加到日志文件 log.txt:ls -l | tee -a log.txt

需要注意的是:此时log.txt文件中只包含有ls –l命令的标准输出信息(stdout),没有标准错误信息(stderr)。

10 - Linux文件和目录的颜色代表的含义

约定的默认颜色:

  • 白色:表示普通文件
  • 蓝色:表示目录
  • 绿色:表示可执行文件
  • 红色:表示压缩文件
  • 浅蓝色:链接文件
  • 红色闪烁:表示链接的文件有问题
  • 黄色:表示设备文件
  • 灰色:表示其他文件

11 - 15

11 - Linux CentOS中升级FireFox

yum erase firefox  # 先卸载
yum install firefox  # 再安装

12 - 创建用户并添加到Sudo组

创建用户并添加到Sudo组, 能够使用户在本地不用密码就能执行sudo命令.
以在CentOS7中添加gerrit用户为例:

[Anliven@mt101 ~]$ sudo adduser gerrit
[Anliven@mt101 ~]$ sudo passwd gerrit
Changing password for user gerrit.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[Anliven@mt101 ~]$ su - gerrit
Password: 
[gerrit@mt101 ~]$ 
[gerrit@mt101 ~]$ exit
logout
[Anliven@mt101 ~]$ 
[Anliven@mt101 ~]$ sudo visudo
[Anliven@mt101 ~]$ sudo cat /etc/sudoers |grep gerrit
gerrit    ALL=(ALL)    NOPASSWD: ALL
[Anliven@mt101 ~]$ 

13 - CentOS7修改主机名

临时生效(重启失效)

[root@localhost ~]# hostname node101
[root@localhost ~]# hostname
node101
[root@localhost ~]# exec bash
[root@node101 ~]# hostname
node101
[root@node101 ~]# 

永久生效

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# 
[root@localhost ~]# hostnamectl set-hostname node102
[root@localhost ~]# exec bash
[root@node102 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 node102
192.168.16.102   localhost localhost.localdomain localhost4 localhost4.localdomain4 node102
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 node102
[root@node102 ~]# 
[root@node102 ~]# hostname
node102
[root@node102 ~]# 

14 Python in Ubuntu18.04

anliven@localhost:~$ python -V
Python 2.7.17
anliven@localhost:~$ python3 -V
Python 3.6.9
anliven@localhost:~$
anliven@localhost:~$ sudo apt install python3-pip
anliven@localhost:~$ sudo apt install python-pip
anliven@localhost:~$
anliven@localhost:~$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
anliven@localhost:~$
anliven@localhost:~$ pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
anliven@localhost:~$

相关文章:

  • 2021-10-26
  • 2021-06-05
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2022-02-04
  • 2022-12-23
  • 2021-10-22
  • 2021-08-30
相关资源
相似解决方案