Linux常用

2021-06-29  本文已影响0人  美美的苹果核

Linux第一分钟

  1. w 显示目前登入系统的用户信息
  2. history 显示历史指令
  3. top 查看系统状态
  4. df -h 查看磁盘空间
  5. netstat 查看网络状态

常用服务

  1. ssh 远程服务
  2. java 运行环境
  3. nginx http服务
  4. git 代码库
  5. lrzsz 上传下载

常用命令

环境变量

字符串操作

解压文件

tar -x 解压 -c 压缩 -v 显示过程 -f 要操作的文件,必需且放最后一位

压缩文件

文件操作

功能 命令
复制文件 cp –r test newtest
覆盖文件 cp –rf newtest test
删除文件 rm -rf weixin-h5/

后台启动

远程复制

查看端口

系统服务

下载工具

功能 命令
下载文件 wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
重命名下载 wget -O wordpress.zip http://www.centos.bz/download.php?id=1080
断点续传 wget -c http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
后台下载 wget -b http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
批量下载 wget -i download.txt

上传下载

模拟请求curl

-- 通过指定OAuth2授权方式获取接口权限码
curl -d "grant_type=client_credentials&client_id=demo_client&client_secret=4HMCPHY76" http://xxx.com/uaa/oauth/token

-- 通过OAuth2授权码请求接口
curl "http://xxx.com/api/v1/role/tag" -d "{id:1}" -H "content-type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsImtpZCI6ImxlZ2FjeS10b2t"

修改时间

grep 文本过滤器

sed

# 根据时间过滤日志
sed -n '/2021-04-25 16:30:*/,/2021-04-25 16:40:*/p' info.log

ssh 配置

服务端配置

  1. 检查/etc/ssh/sshd_config以下配置
    #允许密钥认证1.x
    RSAAuthentication yes
    #允许密钥认证2.x
  PubkeyAuthentication yes
  #默认公钥存放的位置
  AuthorizedKeysFile .ssh/authorized_keys
  1. 合并公钥内容到authorized_keys,免密登录
    cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

客户端配置

  1. 生成密钥对,添加公钥到服务端
  2. 客户端选择私钥登录

OpenSSL

创建CA和申请证书(https)

1. 生成rsa私钥,des3算法,2048位强度
openssl genrsa -des3 -out server.key 2048

2. 去掉私钥密码
openssl rsa -in server.key -out server.key

3. 生成证书申请文件
openssl req -new -key server.key -out server.csr

4. 生成ca证书,有效期3650天 
openssl req -new -x509 -key server.key -out ca.crt -days 3650

5. 生成服务器证书,有效期3650天
openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey server.key -CAcreateserial -out server.crt

OpenSSH

安装软件

nginx

  1. /etc/yum.repos.d 目录创建 nginx.repo 文件,内容如下
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
  1. 执行安装命令
sudo yum install nginx
  1. 设置开机启动,其实就是在 /etc/systemd/system/multi-user.target.wants 目录创建软链接
# 开机启动
systemctl enable nginx
# 停止开机启动
systemctl disable nginx

MariaDB

  1. /etc/yum.repos.d 目录创建 MariaDB.repo 文件,内容如下,其他步骤同nginx安装
[mariadb]
name = MariaDB
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.5/centos7-amd64
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
  1. 执行安装命令
yum install MariaDB-server MariaDB-client
  1. 启动服务
systemctl start mysql
上一篇 下一篇

猜你喜欢

热点阅读