Linux 笔记

SSH

putty

1
2
# 快捷方式目标后添加,-pw前面要有空格
-pw 123456@@ root@192.168.1.100

ssh

1
2
3
4
5
6
7
8
# 生成 ssh 公钥
ssh-keygen -t rsa -C "laijingwei1993@163.com"

# 上传公钥至服务器
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.100

# ssh 连接服务器
ssh root@192.168.1.100

yum

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# yum 中国镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# nodejs 最新版本源
curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -

## Run `sudo yum install -y nodejs` to install Node.js 10.x and npm.
yum install -y nodejs

## You may also need development tools to build native addons:
yum install -y gcc-c++ make

## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install -y yarn

yum install -y git
yum install -y tree
tree -L 1

OneinStack

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 安装命令
wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1

# Nginx目录
cd /data/wwwroot

# OneinStack安装目录
cd /root/oneinstack

# Nginx 虚拟主机配置
cd /usr/local/nginx/conf/vhost

# Nginx SSL证书 
cd /usr/local/nginx/conf/ssl

Rust tools

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
yum install -y rust cargo

# bat
cargo install bat
ln -s /root/.cargo/bin/bat /bin/bat

# fd
cargo install fd-find
ln -s /root/.cargo/bin/fd /bin/fd

# lsd
cargo install lsd
ln -s /root/.cargo/bin/lsd /bin/lsd

Cent OS 常用命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 查看系统版本
cat /etc/redhat-release
uname -a

# 树形显示目录
tree -L 1 -C

# 查看内存排行
top
# 按 shift + M

# 从 '/' 开始进入根文件系统搜索文件和目录
find / -name file1

# YUM 软件包升级器
yum install ..
yum update ..
yum remove ..
yum search ..

tar

1
2
3
4
5
6
# 压缩
tar -czvf test.tar.gz test/

# 解压
tar -xzvf test.tar.gz
unzip test.zip -d test/

mount

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 查看硬盘列表
fdisk -l

# 格式化硬盘
mkfs.xfs /dev/sdb

mkdir /home/nas
mount /dev/sdb /home/nas

# 查看分区列表
df -lh

# 开机自动挂载
vim /etc/fstab

/dev/sdb  /home/nas  xfs  defaults  0 0

# 查看当前目录文件夹大小
du -hd 1

VMWare Tools

CentOS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 点击安装 VMWare Tools
# 进入 CentOS 挂载 /dev/cdrom
mkdir /mnt/cdrom && mount /dev/cdrom /mnt/cdrom
cp /mnt/cdrom/VMwareTools-10.3.2-9925305.tar.gz .. /mnt

# 解压
cd /mnt/tar xzvf VMwareTools-10.3.2-9925305.tar.gz

# 运行安装脚本,一直回车
cd vmware-tools-distrib && ./vmware-install.pl

# 卸载光盘
umount /dev/cdrom

# 共享文件夹目录
cd /mnt/hgfs/share

# Windows 共享虚拟机目录
C:\Users\Public\Documents\Shared Virtual Machines

静态 IP

ifcfg-ens33 为网卡名称

1
vim /etc/sysconfig/network-scripts/ifcfg-ens33
1
2
3
4
5
6
7
8
# 修改
BOOTPROTO="static"

# 底部增加
IPADDR=192.168.75.130
NETMASK=255.255.255.0
GATEWAY=192.168.75.2
DNSI=119.29.29.29

阿里云中国镜像 unable to resolve host address

1
vim /etc/resolv.conf
1
2
nameserver 8.8.8.8
nameserver 8.8.4.4

Manjaro

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 内存至少分配 2G 处理器数量 2
# 分区 50G / + 26G /home + 4G linuxswap

# 更换为为中科大arch软件源
sudo vim /etc/pacman.conf

# 最底部添加
[archlinuxcn]
SigLevel = Optional TrustedOnly
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

# 更新软件源
sudo pacman -Syy && sudo pacman -S archlinuxcn-keyring

CURL

Usage: curl [options…]

1
2
3
4
5
6
# RESTful API

curl -X GET http://localhost:1337/test
curl -X POST http://localhost:1337/test -d "name=hello" -d "password=123456"
curl -X PATCH http://localhost:1337/test/5cb8338cf4b67d3718ae62f9 -d "name=hello" -d "password=123456"
curl -X DELETE http://localhost:1337/test?id=5cb8338cf4b67d3718ae62f9

wget

wget [参数列表] [目标软件、网页的网址]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-V,–version 显示软件版本号然后退出; 
-h,–help显示软件帮助信息; 
-e,–execute=COMMAND 执行一个 “.wgetrc”命令 

-o,–output-file=FILE 将软件输出信息保存到文件; 
-a,–append-output=FILE将软件输出信息追加到文件; 
-d,–debug显示输出信息; 
-q,–quiet 不显示输出信息; 
-i,–input-file=FILE 从文件中取得URL; 

-t,–tries=NUMBER 是否下载次数(0表示无穷次) 
-O –output-document=FILE下载文件保存为别的文件名 
-nc, –no-clobber 不要覆盖已经存在的文件 
-N,–timestamping只下载比本地新的文件 
-T,–timeout=SECONDS 设置超时时间 
-Y,–proxy=on/off 关闭代理 

-nd,–no-directories 不建立目录 
-x,–force-directories 强制建立目录 

–http-user=USER设置HTTP用户 
–http-passwd=PASS设置HTTP密码 
–proxy-user=USER设置代理用户 
–proxy-passwd=PASS设置代理密码 

-r,–recursive 下载整个网站、目录(小心使用) 
-l,–level=NUMBER 下载层次 

-A,–accept=LIST 可以接受的文件类型 
-R,–reject=LIST拒绝接受的文件类型 
-D,–domains=LIST可以接受的域名 
–exclude-domains=LIST拒绝的域名 
-L,–relative 下载关联链接 
–follow-ftp 只下载FTP链接 
-H,–span-hosts 可以下载外面的主机 
-I,–include-directories=LIST允许的目录 
-X,–exclude-directories=LIST 拒绝的目录 
  • 使用wget下载单个文件
1
wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip 
  • 使用wget -O下载并以不同的文件名保存
1
wget -O wordpress.zip http://www.centos.bz/download.php?id=1080
  • 使用wget -c断点续传
1
wget -c http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
  • 使用wget -b后台下载
1
wget -b http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
  • 使用wget -i下载多个文件 首先,保存一份下载链接文件
1
2
3
4
5
cat > filelist.txt
url1
url2
url3
url4
  • 接着使用这个文件和参数-i下载

wget -i filelist.txt

  • 使用wget FTP下载 你可以使用wget来完成ftp链接的下载。 使用wget匿名ftp下载
1
wget ftp-url

使用wget用户名和密码认证的ftp下载

1
wget –ftp-user=USERNAME –ftp-password=PASSWORD url

Nginx

Nginx 配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 宝塔 nginx 配置文件
/etc/nginx/nginx.conf

# 宝塔 nginx 站点配置文件
/www/server/panel/vhost/nginx

# 重启服务
service nginx restart
systemctl restart nginx
nginx -t
nginx -s reload

Nginx 反向代理

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 跨域设置
  location /
  {
      proxy_pass http://120.25.80.86:19751;
      proxy_pass_header Set-Cookie;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_redirect off;
  }

  # 静态资源
  location ~ .*\.(js|css|jpg|png)$
  {
      proxy_pass http://120.25.80.86:19751;
  }

公共DNS

1
2
3
4
5
6
7
# 阿里云
223.5.5.5
223.6.6.6

# Google
8.8.8.8
8.8.4.4

服务器常见端口

端口进程
21ftp
22ssh
23telnet
80http
443https
1433ms-sql-s
2000hotel
3306mysql
3389mstsc
5900vnc
6379redis
8080webcache
8888bt-panel
27017mongo

Samba

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 查询是否已经安装了Samba
rpm -qi samba

# 安装Samba
yum install -y samba

# 查看已经安装好的Samba的信息
rpm -qi samba

# 新建分享目录
mkdir /home/nas && chmod -R 777 /home/nas

# 备份配置文件
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# 修改配置文件
vim /etc/samba/smb.conf

# [homes]、[printers]、[print$]都注释掉只保留[global],load printers = no
[nas]
comment = nas
path = /nas
public = yes
writable = yes
browseable = yes
available = yes
valid users = root

# 添加账户
smbpasswd -a root

# 关闭防火墙
systemctl stop firewalld
setenforce 0

# 防火墙放行端口
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp

# 启动命令
systemctl enable smb
systemctl start smb
systemctl restart smb
systemctl status smb
systemctl stop smb

确保setlinux关闭,可以用 setenforce 0 命令执行。 默认的,SELinux禁止网络上对Samba服务器上的共享目录进行写操作,即使你在smb.conf中允许了这项操作

如果要彻底禁用SELinux 需要在/etc/sysconfig/selinux中设置参数permissive ,或者在/etc/grub.conf中添加这个参数

访问Samba共享的文件很慢很慢的问题

查看当前的主机名

1
2
[root@ls100 ~]# hostname
ls100

查看 hosts

1
2
3
4
5
6
[root@ls100 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1	ls100
192.168.1.100   ls775.com
192.168.1.100	a805.com

增加 127.0.0.1 ls100,其中 ls100 为当前主机名

防火墙

1
2
3
4
5
6
7
8
# 防火墙放行端口
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp

# 关闭防火墙
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld

lrsz

Xshell 上传文件到 Linux 和下载文件到 Windows

1
2
3
4
5
6
7
8
yum install -y lrzsz

# Windows 传文件 到 Linux
rz

# Linux 传文件到 Windows
# 文件夹需要 tar -czvf 打包
sz [file]

Termux

Github

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 连接远程仓库,获取软件包信息
$ apt update

# 更新本地已经安装的软件包
$ apt upgrade

# 安装 sl 软件包
$ apt install sl

# 运行
$ sl

# 访问本机存储
$ termux-setup-storage

# 安装软件包
$ pkg install [package name]

# 卸载软件包
$ pkg uninstall [package name]

# 列出所有软件包
$ pkg list-all

# 安装常用软件
$ pkg install nodejs
$ pkg install git

chmod

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
mv /home/nas/docute-notebook /www/wwwroot
mv /home/nas/go/img/* /www/wwwroot/hugo-blog/static/assets/

# 权限
chmod -R 755 docute-notebook

# 用户
chown -R www docute-notebook

# 用户组
chgrp -R www docute-notebook

# 查看所有用户
cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4 }'|more

# 删除用户
userdel -r git2

宝塔 Webhook

Gogs + 宝塔 Webhook

git pull sh 脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
echo ""

#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"

#判断宝塔WebHook参数是否存在
if [ ! -n "$1" ];
then 
  echo "param参数错误"
  echo "End"
  exit
fi

#git项目路径
gitPath="/home/nas/www/$1"
echo "Web站点路径:$gitPath"

#判断项目路径是否存在
if [ -d "$gitPath" ]; then
  cd $gitPath
  git pull origin master
  echo "End"
  exit
else
  echo "该项目路径不存在"
  echo "End"
  exit
fi

hugo sh 脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
echo ""

#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"

#判断宝塔WebHook参数是否存在
if [ ! -n "$1" ];
then 
  echo "param参数错误"
  echo "End"
  exit
fi

#git项目路径
gitPath="/home/nas/www/$1"
echo "Web站点路径:$gitPath"

#判断项目路径是否存在
if [ -d "$gitPath" ]; then
  cd $gitPath
  git pull origin master
  hugo
  echo "End"
  exit
else
  echo "该项目路径不存在"
  echo "End"
  exit
fi

生成钩子

1
2
http://192.168.1.100:8888/hook?access_key=iDO5X0LNRhMNn68v7e7StZGVCjigTxqQ1Lebkz7fBLZmLULS&param=sdsf-guide
http://203.195.167.93:8888/hook?access_key=La3YazpurYzOR1WoYxEps5jFrRYwf1tmnPK960xTmd9yK5B9&param=a0201.cloud.laijw.com

新增钩子后记得重启宝塔面板

腾讯图床防盗链

1
http://img01.store.sogou.com/net/a/04/link?appid=100520029&url=
1
<meta name="referrer" content="no-referrer"/>

centos ruby 安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# ruby 安装
tar -zxvf ruby-2.5.7.tar.gz && cd ruby-2.5.7
./configure
make && make install
ruby -v

# gem 安装
tar -zxvf rubygems-3.0.6.tgz && cd rubygems-3.0.6
ruby setup.rb
gem -v

gem sources -l
gem sources --remove https://rubygems.org/
gem sources -a http://mirrors.aliyun.com/rubygems/
gem sources -u

gem install jekyll
gem install rails

bundle config mirror.https://rubygems.org https://gems.ruby-china.com/