linux 常见配置

图片无法加载请跳转CSDN:Linux常见配置-CSDN博客

一、配置固定IP, 主机名映射

1、修改主机名

1
hostnamectl set-hostname xxx

2、Centos配置固定IP
使用vim编辑/etc/sysconfig/network-scripts/ifcfg-ens33文件,填入下图信息

1
vim /etc/sysconfig/network-scripts/ifcfg-ens33

添加完成后重启网卡

1
2
3
4
# 重启网卡
systemctl stop network
systemctl start network
systemctl restart network

3、主机名映射
Windows在C:\Windows\System32\drivers\etc\hosts 、Linux 在/etc/hosts 添加如下信息 (需要管理员权限,配置为自己的即可)

1
2
3
192.168.88.131 node1
192.168.88.132 node2
192.168.88.133 node3

二、配置环境变量

1、将要配置的环境变量写入相应文件

1
2
~/.bashrc		# 用户环境变量配置文件
/etc/profile # 全局环境变量配置文件

2、执行文件

1
2
source ~/.bashrc
source /etc/profile

source 命令用于在当前 shell 会话中读取和执行指定文件的内容

全局环境变量也可以在/etc/profile.d/xxx.sh中写入 (在profile.d下创建任意.sh文件写入),最后也只需执行/etc/profile即可生效

因为/etc/profile内有执行profile.d文件夹下所有.sh文件的代码

三、vim配置

编辑用户目录下.vimrc即可 (没有可以自行创建)

1
~/.vimrc

以下是一些设置,如需要直接写在~/.vimrc即可

基本设置

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
" 启用语法高亮
syntax on
" 显示行号
set number
" 高亮当前行
set cursorline
" 设置制表符宽度为 4 个空格
set tabstop=4
set shiftwidth=4
set expandtab
" 启用智能缩进
set smartindent
" 启用自动缩进
set autoindent
" 显示匹配的括号
set showmatch
" 启用行号相对显示
set relativenumber
" 搜索时忽略大小写
set ignorecase
" 搜索时根据输入大小写智能匹配
set smartcase
" 增量搜索
set incsearch
" 搜索高亮
set hlsearch
" 在命令行显示正在输入的命令
set showcmd
" 显示光标位置
set ruler
" 启用鼠标支持
set mouse=a
" 设置终端标题
set title
" 启用自动换行
set wrap
" 禁用兼容模式以启用 Vim 的所有功能
set nocompatible
" 设置剪切板使用系统剪切板
set clipboard=unnamedplus

可视化和美化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
" 设置颜色方案
colorscheme desert
" 设置背景颜色为暗色
set background=dark
" 显示状态栏
set laststatus=2
" 启用命令行补全
set wildmenu
" 设置滚动偏移,使光标上下移动时始终保持一定的上下缓冲区
set scrolloff=8
" 设置文件编码
set encoding=utf-8
" 突出显示当前列
set colorcolumn=80
1
2
底行模式搜索 :/xxxxx
取消高亮 :noh

四、ssh配置

免密连接

1
2
ssh-keygen -t rsa	# 生成密钥
ssh-copy-id xxx # 将公钥拷贝到xxx

详细配置请查看: ssh安装,配置以及免密连接

五、未完待续


linux 常见配置
https://leaf-domain.gitee.io/2024/08/04/linux02/
作者
叶域
发布于
2024年8月4日
许可协议