Skip to content

linux

plantuml常用汇总

linux 上中文文字层叠现象

ubuntu

sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy

centos

sudo yum install -y wqy-microhei-fonts
sudo yum install -y adobe-source-han-sans-cn-fonts

测试

   Fonts available: DejaVu Sans :你好DejaVu Sans Mono :你好DejaVu Serif :你好Dialog :你好DialogInput :你好Monospaced :你好Noto Sans CJK HK :你好Noto Sans CJK JP :你好Noto Sans CJK KR :你好Noto Sans CJK SC :你好Noto Sans CJK TC :你好Noto Sans Mono CJK HK :你好Noto Sans Mono CJK JP :你好Noto Sans Mono CJK KR :你好Noto Sans Mono CJK SC :你好Noto Sans Mono CJK TC :你好Noto Serif CJK HK :你好Noto Serif CJK JP :你好Noto Serif CJK KR :你好Noto Serif CJK SC :你好Noto Serif CJK TC :你好SansSerif :你好Serif :你好

字体

linux 字体安装

流程

1.将字体下载并拷贝到对应文件夹中,并进入字体文件夹

cp *.ttf /usr/share/fonts
cd /usr/share/fonts

2.字体安装器

sudo apt install ttf-mscorefonts-installer 
# (创建字体的fonts.scale文件,它用来控制字体旋转缩放)
sudo mkfontscale

# (创建字体的fonts.dir文件,它用来控制字体粗斜体产生)
sudo mkfontdir

3.建立字体缓存

sudo apt install fontconfig

# 建立字体缓存信息
sudo fc-cache -fv

# 查看已经安装的
fc-list

ohmyzsh 安装

参考

https://github.com/ohmyzsh/ohmyzsh

插件参考

https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
  • 第三方插件

1.zsh-autosuggestions 自动补全插件

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

2.高亮

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

3.autojump

sudo apt-get install autojump
  • 我的插件配置
plugins=(
        git
        z
        autojump
        zsh-autosuggestions
        zsh-syntax-highlighting
        sudo
)

主题参考

https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

第三方主题参考

powerlevel10k

https://github.com/romkatv/powerlevel10k

centos7 git 环境配置

安装最新git

如果使用 EPEL 存储库中的 dnf 安装 Git 仍然无法得到最新版本的 Git,您可以考虑从源代码编译安装 Git。以下是在 CentOS 7 上编译安装最新版本 Git 的步骤:

  1. 打开终端并使用 root 用户登录系统。

  2. 安装必需的编译工具和依赖项:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker -y
  1. 前往 Git 官网的下载页面(https://git-scm.com/downloads) 并找到最新版本的 Git。复制该版本的下载链接。

  2. 在终端中使用以下命令下载 Git 的源代码压缩包(请将命令中的 URL 替换为第 3 步中复制的下载链接):

curl -LO https://github.com/git/git/archive/refs/tags/v2.40.1.tar.gz
  1. 使用以下命令解压缩源代码压缩包:
tar xzf *.gz
  1. 进入解压后的 Git 源代码目录:
cd git-*
  1. 使用以下命令编译和安装 Git:
make prefix=/usr/local/git all
make prefix=/usr/local/git install
  1. 将 Git 添加到 PATH 环境变量中:
echo 'export PATH=$PATH:/usr/local/git/bin' >> ~/.bashrc
source ~/.bashrc
  1. 使用以下命令验证 Git 是否已成功安装:
git --version

如果 Git 版本号显示为最新版本,则表示 Git 已经成功安装在 CentOS 7 上。请注意,由于 CentOS 7 默认使用较旧的软件版本,因此您可能需要升级其他依赖项来满足 Git 的要求。如果在编译过程中遇到任何问题,请检查错误消息并尝试解决它们。

git

git 环境

windows git 上有分支名称,一下加入可让 linux 也支持分支名称

vim ~/.bashrc

  • 方案1:
function git-branch-name {
  git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
  local branch=`git-branch-name`
  if [ $branch ]; then printf " [%s] " $branch; fi
}

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(git-branch-prompt)\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(git-branch-prompt)\$ '
fi
  • 方案2:

git env

显示分支名称

parse_git_branch() {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

PS1="\[\033[36m\]\u@\h\[\033[m\]:\[\033[32m\]\w\[\033[m\]\$(parse_git_branch)\$ "

配色

配置文件

vim /home/[username]/.gitconfig

[color]
    status = auto
    diff = auto
    ui = true
    interactive = auto
    branch = auto

修改后立马生效

命令设置

git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.ui true
git config --global color.interactive auto

1 远程操作

1.1 获取远程仓库地址信息

git remote -v

1.2 本地新建项目情况

本地建立仓库,远程后建立,拉取时会失败,使用以下命令强制拉取

git pull <远程仓库地址> -allow-unrelated-histories 

1.3 更新当前分支远程仓库分支地址

git branch --set-upstream-to=origin/<远程分支名称>

1.4 删除远程仓库

git push origin --delete origin/<远程分支名称>

1.5 远程分支回滚

  1. 要回滚的版本号
git reset --hard <commit> 
  1. 提交回退
// 方式1
git push origin HEAD --force   
// 方式2
git push --force

1.6 回滚作为一个更改项,避免已提交到远程分支后同步造成冲突

git revert <commit>     // 回退作为一个动作保留
git push                // 这样作为一个同步提交不会造成服务器的冲突了

1.7 更新远程仓库地址

git remote set-url origin 【url】

或者

git remote remove origin
git remote add origin【url】

1.8 克隆单个分支

git clone -b <branch> <remote_repo>

2 本地操作

2.1 拉取其他仓库所有分支作自己分支

fetch <仓库路径>

2.2 当前分支获取其他分支某个提交的改动

git cherry-pick <版本号> # 也可以是分支名称

3 打标签

3.1 显示标签
$ git tag
3.2 创建标签
$ git tag -a v1.0 -m "xxx"
3.3 显示标签所有前缀标签

```\ $ git tag -l "v1.0*"

#### 3.4 显示对应标签所有信息
$ git show v1.0
#### 3.5 删除标签
$ git tag -d v1.0
## git submodule

### 添加子模块

```sh
git submodule add <submodule> <path>

拉取整个项目

git submodule update --init --recursive

删除子模块

git submodule deinit <path>
git rm <path>

如果已经update 了,还要删除 .git里面module的对应内容

更换子模块

先删除再添加

  1. git submodule deinit -f {submodule_name}
  2. 删除 .gitsubmodule 中对应条目
  3. rm -rf .git/modules/{submodule_name}
  4. 如果 .git/config 中有对应信息需删除
  5. 添加新的子模块

更新子模块路径

git 1.8.5 之后新增, 建议先删除再新增子模块

git mv {oldPath} {newPath}
# 如果要更换submodule 名称与 path 一致
mv .git/modules/{oldPath} .git/modules/{newPath}

nvs环境配置

nvs 详细安装可以去 github:

https://github.com/jasongin/nvs

windows

gitbase 如果找不到 nvs

如果使用 git base 环境, 在 ~/.bash_profile 加入以下命令

export NVS_HOME=$LOCALAPPDATA/nvs
. $NVS_HOME/nvs.sh

linux

wsl 解决与windows中 nvs 冲突

如果为wsl环境, 如果windows中无nvs环境可跳过此步骤

vim ~/.bashrc

在文件末尾加入,排出windows nvs 环境变量, 具体路径参考自己 windows 的 nvs 环境

export PATH=$(echo $PATH | sed -e 's;:/mnt/c/Users/<user>/AppData/Local/nvs/default;;' -e 's;:/mnt/c/Users/<user>/AppData/Local/nvs/;;')

公共配置

解决全局模块在切换版本后需要重装问题

mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global

推荐直接使用 pnpm 替代

pnpm config set prefix ~/.npm-global

配置到环境变量到 ~/.bashrc, windows类似在系统配置中添加

export PATH=~/.npm-global/bin:$PATH

配置镜像地址

查看 remote

nvs remote

配置镜像地址

nvs remote node https://npmmirror.com/mirrors/node/

挂载

挂载新硬盘

1.查看硬盘

root@ubuntu:~# fdisk -lu
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3c78b7a1

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 16777215 16775168   8G 83 Linux
/dev/sda2       16779262 20969471  4190210   2G  5 Extended
/dev/sda5       16779264 20969471  4190208   2G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.


Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2.创建分区

root@ubuntu:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xdf96fde2.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):

Created a new partition 1 of type 'Linux' and of size 50 GiB.

Command (m for help): p
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xdf96fde2

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

3.格式化分区

root@ubuntu:~# mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: 完成
Creating filesystem with 13106944 4k blocks and 3276800 inodes
Filesystem UUID: c0887faa-eed2-4f38-9f18-6e3059261202
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

4.挂载和查看分区表

root@ubuntu:~# mount /dev/sdb1 /data
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  5.5M  389M   2% /run
/dev/sda1       7.8G  1.2G  6.2G  16% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           395M     0  395M   0% /run/user/0
/dev/sdb1        50G   52M   47G   1% /data

5.永久挂载

# 执行前一定要进行备份,以免误操作
echo '/dev/sdb1       /data   ext4    defaults        0       0' >> /etc/fstab

映射硬盘

eg: 将 docker lib 目录映射到 /data/lib/docker

echo '/data/lib/docker /var/lib/docker none defaults,bind 0 0'>>/etc/fstab

fstab 立即生效

mount -a

linux信息

查看系统版本

# 打印系统信息
$ uname -a
Linux LAPTOP-2181LTT2 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# 获取发行版信息
$ cat /etc/issue
Ubuntu 18.04.6 LTS \n \l

$ cat /etc/issue.net 
Ubuntu 18.04.6 LTS

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

# 根据上面 ID_LIKE 来获取version
$ cat /etc/debian_version
9.3

# 也可直接通过system 获取(如果有)
$ cat /etc/system-release
9.3

# 获取内核版本
$ cat /proc/version 
Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020

# dmesg 命令
$ dmesg | grep "Linux"
[    0.000000] Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020
[    3.522133] ACPI: Added _OSI(Linux-Dell-Video)
[    3.527064] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    3.531431] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)

# 其他 Yum/Dnf
$ yum info nano
$ yum repolist
$ dnf info nano
$ apt-cache policy nano
nano:
  Installed: 2.9.3-2
  Candidate: 2.9.3-2
  Version table:
 *** 2.9.3-2 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status

nginx配置

nginx 配置单机器多域名

1.conf.d/default.conf 默认域名,若没命中,进入此处

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html/default;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

1.conf.d/www.my.com.conf www.my.com 和 my.com 进入会命中

server {
    listen       80;
    listen  [::]:80;
    server_name  www.my.com my.com;

    location / {
        root   /usr/share/nginx/html/my;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

常用功能

文件服务器

server {
    listen 80;  # 监听 HTTP 请求的端口,可以根据需要更改
    server_name files.localhost;  # 你的服务器名称或 IP 地址

    location / {
        alias /files/;  # 指定文件存储目录
        autoindex on;  # 启用自动列出目录内容
        autoindex_exact_size off;  # 显示文件大小的近似值
        charset utf-8;
    }
}

basic auth

  • htpasswd文件生成
printf "test:$(openssl passwd -crypt 123456)\n" >> /usr/local/nginx-1.5.1/conf/basicauth
  • 使用
server{
    listen 80;
    server_name  auth.localhost;

    location / {
        root   html;
        auth_basic "Please enter your username and password";
        auth_basic_user_file ../conf/basicauth; 
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

samba服务器搭建

1 配置

在配置文件/etc/samba/smb.conf中

#共享文件设置参数
[share]      #自定义共享名称,共享路径对应显示的实际名称,常用项
comment =  This is share software         #共享描述,做一个说明
path  =  /home/testfile    #共享目录路径
browseable  =  yes/no      #设置共享是否可浏览,如果no就表示隐藏,需要通过IP+共享名称进行访问
writable  =  yes/no        #设置共享是否具有可写权限
read only  =  yes/no     #设置共享是否具有只读权限
admin users  =  root     #设置共享的管理员,如果security =share 时,引项无效,多用户中间使用逗                            号隔开,例如admin users = root,user1,user2
# 设置允许访问共享的用户,例如valid users = user1,user2,@group1,@group2(多用户或组使用逗号隔
# 开,@group表示group用户组)
valid users  =  username 
invalid users  =  username    #设置不允许访问共享的用户

# 设置在共享具有写入权限的用户,例如例如write list  = user1,user2,@group1,@group2(多用户或组使
# 用逗号隔开,@group表示group用户组)
write list  =  username     
public  =  yes/no       #设置共享是否允许guest账户访问

guest  ok  =  yes/no    #功能同public 一样
create mask = 0700       #创建的文件权限为700
directory mode = 0700    #创建的文件目录为 700
force user = ubuntu      #客户端默认创建所属用户,设置后防止windows访问成为nobody, 常用项

2 添加用户

smbpasswd -a ubuntu  // 将ubuntu添加到samba用户组

3 重启服务

配置操作后需重启服务

ubuntu

sudo /etc/init.d/smbd restart

centos

常见问题

windows无法访问问题

graph TD
    A["cmd:gpedit.msc"]
    --> B["管理模板"]
    B --> C["网络"]
    C --> D["lanman工作站"]
    D --> E["启用不安全的来宾登陆:已启用"]

centos 服务器 windows无访问权限

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

setenforce 1 设置SELinux 成为enforcing模式

setenforce 0 设置SELinux 成为permissive模式  

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

  /usr/bin/setstatus -v  

?? 不关闭防火墙方法

setsebool -P samba_enable_home_dirs on
setsebool -P samba_domain_controller on
#/usr/sbin/setsebool -P allow_smbd_anon_write=1 
#chcon -t public_content_rw_t <共享文件路径>