我的 Linux 初始化

为了方便每次都设置 Linux 系统的个性化内容。这次整理了一下,以后就来 copy 就行了,嘿嘿。

VirtualBox 安装

2024-11-09 23:52:19 重新记录:虚拟机安装
https://www.virtualbox.org/wiki/Downloads

在这里插入图片描述

下载完,默认安装 C盘(选择其他盘 有权限问题,默认安装C盘就行了)

更改 虚拟机的位置
在这里插入图片描述

1
2
3
4
5
6
7
8
9
10
11
12
13
准备好 centos7  ios 文件。
1、新建名称 "vm01"
2、 4核 8G(8192 MB) 50GB(预分配)
3、网络:只勾选 网卡1,启用连接,仅主机
4、储存:控制器 添加 iso 镜像

5、启动安装,选择 第一个
6、语言选择 中文简体
7、点击一下 分区,什么都不要操作,直接点击完成
8、安装(root 密码 123456)
9、重启

系统重启后,网络设置(如下)

VirtualBox 网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat > /etc/sysconfig/network-scripts/ifcfg-enp0s3 << EOF
DEVICE=enp0s3
ONBOOT=yes

GATEWAY=192.168.1.254
NETMASK=255.255.255.0
IPADDR=192.168.1.1
DNS1=8.8.8.8
EOF

# 重启网卡
systemctl restart network

# 测试是否可以连通外网
ping www.baidu.com

在这里插入图片描述

yum

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
# 更新 yum 源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y update

# ifconfig netstat
yum -y install net-tools
# ping
yum -y install iputils
# telnet
yum -y install telnet
# ip
yum -y install iproute
# 压缩/解压 zip
yum -y install zip unzip
# Coreutils 软件包包括一整套基本的 shell 工具。
# 是GNU提供了一整套比较基本的工具软件包,是这些工具的集合。
# 其本身是需要依赖shell程序的。
yum -y install coreutils
# wget
yum -y install wget
# curl
yum -y install curl
# scp
# 远程的东西 -> 本地 scp -r 用户名@主机名:远程路径 本地路径
# 本地的东西 -> 远程 scp -r 本地路径 用户名@主机名:远程路径
yum -y install openssh-clients
# vim
yum -y install vim
# man 中文 命令使用 例如:"man ls"
yum -y install man-pages-zh-CN
# 命令补全
yum -y install bash-completion
# sz-rz
yum -y install lrzsz

内存

1
2
3
4
5
6
7
8
# 查看交换内存
swapon -s

# 查看交换内存(第二行 swap)
free -h

# 禁用交换内存
sudo swapoff -a

语言

1
2
echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
source /etc/profile.d/lang.sh

时区

Linux的时间分为 System Clock(系统时间)和 Real Time Clock(硬件时间,简称RTC)。
系统时间:指系统内核中的时间。
硬件时间:指主板上的时间。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查看时间
date
hwclock

# 同步上海时间
rm -rf /etc/localtime ; ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 同步阿里服务器时间
yum -y install ntp ntpdate
ntpdate ntp1.aliyun.com

# 软硬时间同步
/sbin/hwclock --systohc

# 再次查看
date
hwclock

diy.sh

1
2
3
4
5
6
7
8
9
10
11
vim /etc/profile.d/diy.sh

# 16个 - 减号
PS1=----------------

# 文件显示时间格式 yyyy-MM-dd HH:mm:ss
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'

# history 大小(10w,默认1k)
export HISTFILESIZE=100000
export HISTSIZE=100000

vim

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

cat > ~/.vimrc << 'EOF'
set nu " 显示行号
set autoindent " 自动缩排(回车后,会自动与上一行对齐)

" 注释 这个文件的注释符合是英文双引号 ",而不是井号 #
EOF

防火墙

1
2
3
4
5
6
# 停止,并永久禁用
systemctl stop firewalld && systemctl disable firewalld

# 安装再停止
yum -y install iptables-services
systemctl stop iptables && systemctl disable iptables

selinux

1
2
3
4
5
6
7
# Redhat使用了SELinux来增强安全,关闭的办法为:
# 永久有效
# 修改 /etc/selinux/config 文件中的 SELINUX=enforcing ===> SELINUX=disabled,然后重启。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

## 临时生效
setenforce 0

docker

  1. docker 安装 => Docker小总结
  2. 设置 2375端口 => IDEA 整合 Docker:打包 SpringBoot 应用,直接构建镜像,启动容器

blog

参考:博客部署到自己的服务器上