1. Solaris概述与环境规划
Oracle Solaris是由Oracle公司开发的UNIX操作系统,以其卓越的可扩展性、可靠性和安全性而闻名。Solaris广泛应用于企业级服务器环境,是数据库、中间件和关键业务应用的首选平台。更多学习教程www.fgedu.net.cn
1.1 Solaris版本说明
Solaris目前主要版本为Solaris 11.4,提供长期支持和定期更新。本教程以Solaris 11.4为例进行详细讲解。
# cat /etc/release
Oracle Solaris 11.4 X86
Copyright (c) 1983, 2024, Oracle and/or its affiliates. All rights reserved.
Assembled 15 March 2024
# 查看内核版本
# uname -a
SunOS fgedudb01 5.11 11.4.0.0.0.11.0 i86pc i386 i86pc
# 查看系统架构
# isainfo -kv
64-bit amd64 kernel modules
1.2 环境规划
本次安装环境规划如下:
IP地址:192.168.1.51
网关:192.168.1.1
DNS:192.168.1.1
磁盘分区:
rpool/ROOT/solaris 100GB (根文件系统)
rpool/VAR 50GB (var文件系统)
rpool/export 500GB (数据文件系统)
rpool/backup 300GB (备份文件系统)
swap 32GB (交换分区)
1.3 Solaris特点
1. ZFS文件系统:企业级文件系统,支持快照、压缩、去重
2. Zones容器:轻量级虚拟化技术,资源隔离
3. DTrace:动态追踪工具,性能分析
4. SMF:服务管理框架,服务依赖管理
5. IPS:镜像包系统,软件包管理
6. 网络虚拟化:Crossbow技术,网络性能优化
2. 硬件环境要求与检查
在安装Solaris之前,需要对服务器硬件环境进行全面检查。学习交流加群风哥微信: itpux-com
2.1 最低硬件要求
CPU:64位x86处理器
内存:2GB
磁盘:16GB
推荐配置(生产环境):
CPU:8核心以上
内存:32GB以上
磁盘:500GB以上
网络:千兆网卡
2.2 硬件检查命令
# psrinfo -v
Status of virtual processor 0 as of: April 4, 2024 10:00:00 AM CST
on-line since: April 4, 2024 08:00:00 AM CST.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.
Status of virtual processor 1 as of: April 4, 2024 10:00:00 AM CST
on-line since: April 4, 2024 08:00:00 AM CST.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.
# 检查CPU核心数
# psrinfo -p
32
# 检查内存信息
# prtconf | grep Memory
Memory size: 65536 Megabytes
# 查看内存使用情况
# echo “::memstat” | mdb -k
Page Summary Pages MB %Tot
——————— —————- —————-
Kernel 256000 1000 2%
ZFS File Data 512000 2000 3%
Anon 128000 500 1%
Exec and libs 64000 250 1%
Page cache 256000 1000 2%
Free (cachelist) 2048000 8000 12%
Free (freelist) 14336000 56000 79%
Total 17612800 68800
# 检查磁盘信息
# format
Searching for disks…done
AVAILABLE DISK SELECTIONS:
0. c0t0d0
/pci@0,0/pci8086,2829@1f,2/disk@0,0
1. c0t1d0
/pci@0,0/pci8086,2829@1f,2/disk@1,0
# 查看ZFS池状态
# zpool status
pool: rpool
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
c0t0d0s0 ONLINE 0 0 0
errors: No known data errors.
# 检查网络接口
# dladm show-phys
LINK MEDIA STATE SPEED DUPLEX DEVICE
net0 Ethernet up 1000 full e1000g0
# 查看网络接口配置
# ipadm show-addr
ADDROBJ TYPE STATE ADDR
lo0/v4 static ok 127.0.0.1/8
net0/v4 static ok 192.168.1.51/24
3. Solaris系统安装步骤
本节详细介绍Solaris 11.4的安装过程。学习交流加群风哥QQ113257174
3.1 下载Solaris镜像
# 需要Oracle账号登录后下载
# 文件名:sol-11_4-text-x86.iso
# 验证ISO文件完整性
# digest -a sha256 sol-11_4-text-x86.iso
abc123def456… sol-11_4-text-x86.iso
3.2 创建安装介质
# dd if=sol-11_4-text-x86.iso of=/dev/sdX bs=4M status=progress && sync
# 输出示例:
5242880000 bytes (5.0 GB, 4.7 GiB) copied, 600 s, 8.7 MB/s
1250+0 records in
1250+0 records out
3.3 图形化安装步骤
图形化安装步骤:
步骤1:启动安装程序 – 选择”Install Oracle Solaris” – 按Enter键
步骤2:选择键盘布局 – 选择默认布局
步骤3:选择语言 – 选择”English”或”中文”
步骤4:网络配置 – 配置IP地址、主机名、DNS
步骤5:时区设置 – 选择”Asia/Shanghai”
步骤6:用户设置 – 创建普通用户和设置root密码
步骤7:磁盘分区 – 选择”Use entire disk”或”Custom”
步骤8:安装类型 – 选择”Default Install”或”Custom Install”
步骤9:开始安装 – 等待安装完成
步骤10:重启系统 – 完成安装
3.4 使用AI自动化安装
# installadm create-service -n solaris11_4-x86 -s /export/iso/sol-11_4-text-x86.iso -d /export/auto_install/solaris11_4-x86
# 输出示例:
Setting up the install service.
Creating service from: /export/iso/sol-11_4-text-x86.iso
Service solaris11_4-x86 was created
Manifest defaulted to /export/auto_install/solaris11_4-x86/default.xml
# 创建AI清单文件
# vi /export/auto_install/solaris11_4-x86/manifest.xml
# 创建系统配置文件
# vi /export/auto_install/solaris11_4-x86/sc.xml
3.5 初始系统配置
Oracle Corporation SunOS 5.11 11.4.0.0.0.11.0 March 2024
fgedudb01 console login: root
Password:
# 更新系统软件包
# pkg update
# 输出示例:
Creating Plan (Solver setup): /
pkg update: No updates available for this image.
# 更新所有软件包
# pkg update -v ‘*’
# 输出示例:
Creating Plan (Solver setup): /
Packages to update: 25
Space to download: 500 MB
Space to install: 1 GB
Proceed? [y/N] y
Downloading packages…
Installing packages…
4. 网络配置与优化
网络配置是系统安装后的重要环节,Solaris提供了强大的网络功能。更多学习教程公众号风哥教程itpux_com
4.1 配置网络接口
# dladm show-link
LINK CLASS MTU STATE OVER
net0 phys 1500 up —
# 配置静态IP地址
# ipadm create-addr -T static -a 192.168.1.51/24 net0/v4
# 输出示例:
ipadm: Address object net0/v4 created successfully.
# 配置默认网关
# route -p add default 192.168.1.1
# 输出示例:
add net default: gateway 192.168.1.1
add persistent net default: gateway 192.168.1.1
# 配置DNS
# svccfg -s network/dns/client setprop config/nameserver = net_address: “(192.168.1.1 8.8.8.8)”
# svccfg -s network/dns/client setprop config/search = astring: “fgedu.net.cn”
# svcadm refresh network/dns/client
# svcadm enable network/dns/client
# 验证DNS配置
# cat /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8
search fgedu.net.cn
4.2 配置主机名
# hostname fgedudb01.fgedu.net.cn
# 永久配置
# svccfg -s system/identity:node setprop config/nodename = astring: “fgedudb01.fgedu.net.cn”
# svcadm refresh system/identity:node
# 配置hosts文件
# vi /etc/hosts
127.0.0.1 localhost
::1 localhost
192.168.1.51 fgedudb01.fgedu.net.cn fgedudb01 loghost
# 验证主机名
# hostname
fgedudb01.fgedu.net.cn
4.3 网络性能优化
# ndd /dev/tcp tcp_recv_hiwat
65536
# 增加TCP接收缓冲区
# ndd -set /dev/tcp tcp_recv_hiwat 262144
# 增加TCP发送缓冲区
# ndd -set /dev/tcp tcp_xmit_hiwat 262144
# 查看TCP队列长度
# ndd /dev/tcp tcp_conn_req_max_q
128
# 增加TCP队列长度
# ndd -set /dev/tcp tcp_conn_req_max_q 4096
# 永久配置
# vi /etc/rc3.d/S99ndd
#!/bin/sh
ndd -set /dev/tcp tcp_recv_hiwat 262144
ndd -set /dev/tcp tcp_xmit_hiwat 262144
ndd -set /dev/tcp tcp_conn_req_max_q 4096
ndd -set /dev/tcp tcp_conn_req_max_q0 4096
# 查看网络统计
# netstat -s -P tcp
TCP tcp tcpRtoAlgorithm 4 tcpRtoMin 400
tcpRtoMax 60000 tcpMaxConn -1
tcpActiveOpens 12345 tcpPassiveOpens 6789
tcpAttemptFails 12 tcpEstabResets 5
tcpCurrEstab 100 tcpOutSegs 1234567
tcpInSegs 8765432 tcpRetransSegs 123
tcpInErrs 0 tcpOutRsts 45
5. 内核参数配置
内核参数对系统性能和稳定性至关重要,Solaris提供了灵活的内核参数配置方式。from:www.itpux.com
5.1 配置内核参数
# vi /etc/system
# 添加以下内核参数
# 文件描述符限制
set rlim_fd_max=65535
set rlim_fd_cur=1024
# 共享内存参数
set shmsys:shminfo_shmmax=34359738368
set shmsys:shminfo_shmmni=4096
set shmsys:shminfo_shmseg=1024
# 信号量参数
set semsys:seminfo_semmni=1024
set semsys:seminfo_semmns=65536
set semsys:seminfo_semmnu=1024
set semsys:seminfo_semmsl=256
set semsys:seminfo_semopm=128
# 进程参数
set maxuprc=16384
set max_nprocs=32768
# 内存参数
set lotsfree=524288
set desfree=262144
set minfree=131072
# reboot
# 验证参数设置
# echo “::system” | mdb -k | grep shmmax
shminfo_shmmax = 0x800000000
# 查看文件描述符限制
# ulimit -n
65535
# 查看共享内存参数
# ipcs -ma
IPC status from
T ID KEY MODE OWNER GROUP CREATOR CGROUP NATSEGSZ SEGSZ CPID LPID ATIME DTIME CTIME
Shared Memory:
# 查看信号量参数
# ipcs -sa
IPC status from
T ID KEY MODE OWNER GROUP CREATOR CGROUP NSEMS OTIME CTIME
Semaphores:
5.2 配置用户资源限制
# projadd -U oracle -K “process.max-file-descriptor=(basic,65535,deny)” user.oracle
# projadd -U oracle -K “process.max-sem-ids=(basic,1024,deny)” user.oracle
# projadd -U oracle -K “process.max-shm-ids=(basic,1024,deny)” user.oracle
# projadd -U oracle -K “project.max-shm-memory=(privileged,32GB,deny)” user.oracle
# 查看项目配置
# projects -l user.oracle
user.oracle
projid : 100
comment: “”
users : oracle
groups : (none)
attribs: process.max-file-descriptor=(basic,65535,deny)
process.max-sem-ids=(basic,1024,deny)
process.max-shm-ids=(basic,1024,deny)
project.max-shm-memory=(privileged,34359738368,deny)
# 验证配置
# prctl -n process.max-file-descriptor -i project user.oracle
process.max-file-descriptor
65535 deny
5.3 配置大内存页
# pagesize -a
8192
2097152
# 查看大内存页使用情况
# echo “::memstat” | mdb -k | grep -i large
Large pages: 10240 pages 20480 MB
# 配置大内存页
# projadd -K “project.max-locked-memory=(privileged,32GB,deny)” user.oracle
# 启用大内存页
# ppgsz -o 2M oracle
# 查看进程内存页大小
# pmap -s
6. 存储配置与优化
存储配置直接影响系统性能,Solaris的ZFS文件系统提供了强大的存储管理功能。更多学习教程www.fgedu.net.cn
6.1 ZFS文件系统管理
# zpool status
pool: rpool
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
c0t0d0s0 ONLINE 0 0 0
errors: No known data errors.
# 查看ZFS文件系统
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool 50.0G 400G 96K /rpool
rpool/ROOT 49.5G 400G 96K legacy
rpool/ROOT/solaris 49.5G 400G 49.5G /
rpool/VAR 256M 400G 256M /var
rpool/export 128K 400G 96K /export
rpool/export/home 96K 400G 96K /export/home
# 创建新的ZFS文件系统
# zfs create -o mountpoint=/data rpool/data
# 设置ZFS属性
# zfs set compression=lz4 rpool/data
# zfs set atime=off rpool/data
# zfs set recordsize=128K rpool/data
# 验证设置
# zfs get compression,atime,recordsize rpool/data
NAME PROPERTY VALUE SOURCE
rpool/data compression lz4 local
rpool/data atime off local
rpool/data recordsize 128K local
6.2 创建ZFS镜像池
# zpool create datamirror mirror c0t1d0 c0t2d0
# 输出示例:
# zpool status datamirror
pool: datamirror
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
datamirror ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
c0t1d0 ONLINE 0 0 0
c0t2d0 ONLINE 0 0 0
errors: No known data errors.
# 创建RAIDZ池(类似RAID5)
# zpool create dataraidz raidz c0t1d0 c0t2d0 c0t3d0
# 创建RAIDZ2池(类似RAID6)
# zpool create dataraidz2 raidz2 c0t1d0 c0t2d0 c0t3d0 c0t4d0
# 添加缓存设备(L2ARC)
# zpool add rpool cache c0t5d0
# 添加日志设备(ZIL)
# zpool add rpool log c0t6d0
6.3 ZFS性能优化
# zpool iostat 1 5
capacity operations bandwidth
pool alloc free read write read write
———- —– —– —– —– —– —–
rpool 50.0G 400G 5 10 256K 512K
rpool 50.0G 400G 2 5 128K 256K
rpool 50.0G 400G 0 3 64K 192K
rpool 50.0G 400G 1 4 96K 224K
rpool 50.0G 400G 0 2 32K 128K
# 设置ZFS ARC缓存大小
# zfs set org.opensolaris.arc:arc_max=34359738368 rpool
# 查看ARC缓存使用情况
# echo “::arc” | mdb -k
ARC size (current): 12.5 % 2.5 GiB
Target size (adaptive): 25.0 % 5.0 GiB
Min size (hard limit): 6.2 % 1.2 GiB
Max size (high water): 100.0 % 20.0 GiB
# ZFS快照管理
# 创建快照
# zfs snapshot rpool/data@backup-20260404
# 查看快照
# zfs list -t snapshot
NAME USED AVAIL REFER MOUNTPOINT
rpool/data@backup-20260404 0B – 100G –
# 回滚快照
# zfs rollback rpool/data@backup-20260404
# 发送快照到远程
# zfs send rpool/data@backup-20260404 | ssh backup-server “zfs receive backuppool/data”
7. 安全配置与防火墙
安全配置是生产环境的重要环节,Solaris提供了多种安全机制。学习交流加群风哥微信: itpux-com
7.1 配置IPFilter防火墙
# svcadm enable network/ipfilter
# 创建IPFilter规则文件
# vi /etc/ipf/ipf.conf
# 添加以下规则
# 定义变量
ext_if=”net0″
tcp_services=”{ 22, 80, 443, 3306, 1521 }”
udp_services=”{ 53 }”
# 默认策略
block in all
pass out all keep state
# 允许SSH
pass in on $ext_if proto tcp from any to any port 22
# 允许Web服务
pass in on $ext_if proto tcp from any to any port { 80, 443 }
# 允许数据库服务
pass in on $ext_if proto tcp from 192.168.1.0/24 to any port { 3306, 1521 }
# 允许DNS
pass in on $ext_if proto udp from any to any port 53
# 允许ICMP
pass in on $ext_if proto icmp from any to any icmp-type echo
# 启动IPFilter
# svcadm restart network/ipfilter
# 检查IPFilter状态
# ipfstat -io
# 输出示例:
pass out quick from any to any keep state
block in quick from any to any
pass in quick proto tcp from any to any port = 22 keep state
pass in quick proto tcp from any to any port = 80 keep state
pass in quick proto tcp from any to any port = 443 keep state
7.2 配置SSH安全
# vi /etc/ssh/sshd_config
# 修改以下配置
Port 22
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
PermitEmptyPasswords no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers admin@192.168.1.0/24
# 重启SSH服务
# svcadm restart network/ssh
# 输出示例:
# svcs network/ssh
STATE STIME FMRI
online 10:00:00 svc:/network/ssh:default
# 验证SSH配置
# sshd -t
# 查看SSH服务状态
# svcs -x network/ssh
svc:/network/ssh:default (SSH server)
State: online since April 4, 2024 10:00:00 AM CST
See: sshd(8)
See: /var/svc/log/network-ssh:default.log
Impact: None.
7.3 配置RBAC和权限配置文件
# roleadd -d /export/home/dbadmin -m -P “Oracle Database” dbadmin
# 创建权限配置文件
# profiles -p “Oracle Database”
Oracle Database> set desc=”Oracle Database Administration”
Oracle Database> add cmd=/usr/bin/prctl
Oracle Database> add cmd=/usr/bin/privrun
Oracle Database> add cmd=/usr/bin/su
Oracle Database> commit
# 将权限配置文件分配给用户
# usermod -P “Oracle Database” oracle
# 查看用户权限配置文件
# profiles oracle
oracle:
Oracle Database
Basic Solaris User
All
# 查看用户授权
# auths oracle
solaris.device.cdrw,solaris.device.mount.removable,solaris.mail.mailq
8. 系统升级与迁移
系统升级和迁移是运维工作中的重要环节,Solaris提供了便捷的升级工具。更多学习教程公众号风哥教程itpux_com
8.1 系统版本升级
# pkg update
# 输出示例:
Creating Plan (Solver setup): /
Packages to update: 25
Space to download: 500 MB
Space to install: 1 GB
Proceed? [y/N] y
Downloading packages…
Installing packages…
# 更新到新版本
# pkg update –accept entire@latest
# 输出示例:
Creating Plan (Solver setup): /
Packages to update: 100
Space to download: 2 GB
Space to install: 5 GB
Proceed? [y/N] y
Downloading packages…
Installing packages…
A clone of rpool/ROOT/solaris exists and has been updated.
The updated clone is rpool/ROOT/solaris-1.
The boot environment rpool/ROOT/solaris-1 will be activated on next reboot.
# 查看引导环境
# beadm list
BE Active Mountpoint Space Policy Created
solaris NR / 50.0G static 2024-03-15 10:00
solaris-1 – – 55.0G static 2024-04-04 10:00
# 激活新引导环境
# beadm activate solaris-1
# 重启系统
# reboot
8.2 使用引导环境管理
# beadm create solaris-backup
# 输出示例:
beadm: successfully created solaris-backup
# 查看引导环境
# beadm list
BE Active Mountpoint Space Policy Created
solaris NR / 50.0G static 2024-03-15 10:00
solaris-1 – – 55.0G static 2024-04-04 10:00
solaris-backup – – 50.0G static 2024-04-04 11:00
# 挂载引导环境
# beadm mount solaris-backup /mnt
# 输出示例:
beadm: successfully mounted solaris-backup at /mnt
# 卸载引导环境
# beadm unmount solaris-backup
# 删除引导环境
# beadm destroy solaris-backup
8.3 系统迁移
# 在源系统创建快照
# zfs snapshot -r rpool@migrate-20260404
# 发送快照到目标系统
# zfs send -R rpool@migrate-20260404 | ssh target-server “zfs receive -F rpool”
# 输出示例:
full send of rpool@migrate-20260404 estimated size is 50.0G
total estimated size is 50.0G
TIME SENT SNAPSHOT
10:00:00 256K rpool@migrate-20260404
10:30:00 25.0G rpool@migrate-20260404
11:00:00 50.0G rpool@migrate-20260404
# 使用flarcreate创建归档
# flarcreate -n solaris-backup -c /backup/solaris-backup.flar
# 输出示例:
Full Flash
Checking integrity…
Integrity OK.
Running precreation scripts…
Precreation scripts done.
Determining the size of the archive…
The archive will be approximately 50.00GB.
Creating the archive…
Archive creation complete.
9. 生产环境实战案例
本节提供一个完整的生产环境配置案例,帮助读者更好地理解Solaris的实际应用。from:www.itpux.com
9.1 数据库服务器配置案例
主机名:fgedudb01.fgedu.net.cn
IP地址:192.168.1.51
内存:64GB
磁盘:500GB SSD(ZFS)
用途:Oracle数据库服务器
# 1. 配置内核参数
# vi /etc/system
set rlim_fd_max=65535
set rlim_fd_cur=1024
set shmsys:shminfo_shmmax=34359738368
set shmsys:shminfo_shmmni=4096
set semsys:seminfo_semmni=1024
set semsys:seminfo_semmns=65536
# 2. 配置项目资源限制
# projadd -U oracle -K “process.max-file-descriptor=(basic,65535,deny)” user.oracle
# projadd -U oracle -K “project.max-shm-memory=(privileged,32GB,deny)” user.oracle
# 3. 配置ZFS数据集
# zfs create -o mountpoint=/data/oracle -o recordsize=16K -o compression=lz4 -o atime=off rpool/oracle
# zfs create -o mountpoint=/data/oracle/data -o recordsize=8K rpool/oracle/data
# zfs create -o mountpoint=/data/oracle/redo -o recordsize=8K rpool/oracle/redo
# 4. 安装Oracle数据库
# pkg install oracle-database
# 输出示例:
Packages to install: 1
Space to download: 5 GB
Space to install: 10 GB
Proceed? [y/N] y
Downloading packages…
Installing packages…
# 5. 配置IPFilter防火墙
# vi /etc/ipf/ipf.conf
pass in on net0 proto tcp from 192.168.1.0/24 to any port 1521
# 重启IPFilter
# svcadm restart network/ipfilter
9.2 Web服务器配置案例
主机名:fgeduweb01.fgedu.net.cn
IP地址:192.168.1.52
内存:16GB
磁盘:200GB SSD
用途:Web服务器
# 1. 安装Web服务器
# pkg install web/server/apache-24
# 输出示例:
Packages to install: 1
Space to download: 50 MB
Space to install: 100 MB
Proceed? [y/N] y
Downloading packages…
Installing packages…
# 2. 配置Apache
# vi /etc/apache2/2.4/httpd.conf
# 修改以下配置
ServerName fgeduweb01.fgedu.net.cn:80
Listen 80
DocumentRoot “/var/apache2/2.4/htdocs”
# 3. 启动Apache服务
# svcadm enable network/http:apache24
# 输出示例:
# svcs network/http:apache24
STATE STIME FMRI
online 10:00:00 svc:/network/http:apache24:default
# 4. 配置IPFilter防火墙
# vi /etc/ipf/ipf.conf
pass in on net0 proto tcp from any to any port { 80, 443 }
# 重启IPFilter
# svcadm restart network/ipfilter
9.3 系统监控配置
# prstat -s cpu -n 5
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
12345 oracle 10G 8G cpu0 10 0 0:10:00 5.0% oracle/50
12346 root 100M 50M sleep 10 0 0:00:10 1.0% java/20
12347 root 50M 25M sleep 10 0 0:00:05 0.5% httpd/10
# 使用DTrace分析性能
# dtrace -n ‘syscall:::entry { @num[execname] = count(); } tick-5s { printa(@num); clear(@num); }’
dtrace: description ‘syscall:::entry ‘ matched 476 probes
oracle 12345
java 5678
httpd 1234
# 查看ZFS性能
# zpool iostat -v rpool 1
capacity operations bandwidth
pool alloc free read write read write
———- —– —– —– —– —– —–
rpool 50.0G 400G 5 10 256K 512K
c0t0d0 50.0G 400G 5 10 256K 512K
# 查看系统日志
# tail -f /var/adm/messages
Apr 4 10:00:00 fgedudb01 sshd[12345]: [ID 800047 auth.info] Accepted publickey for admin from 192.168.1.100 port 54321 ssh2
Apr 4 10:05:00 fgedudb01 sendmail[12346]: [ID 702911 mail.info] x34A000A001234: to=admin@fgedu.net.cn, delay=00:00:05, xdelay=00:00:02, mailer=esmtp, pri=123456, relay=mail.fgedu.net.cn. [192.168.1.200], dsn=2.0.0, stat=Sent
9.4 系统备份配置
# zfs create -o mountpoint=/backup rpool/backup
# 创建ZFS快照备份脚本
# vi /backup/zfs_backup.sh
#!/bin/sh
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_POOL=”rpool”
# 创建快照
zfs snapshot -r ${BACKUP_POOL}@backup_${DATE}
# 发送快照到备份服务器
zfs send -R ${BACKUP_POOL}@backup_${DATE} | ssh backup-server “zfs receive -u backuppool/fgedudb01”
# 清理7天前的快照
zfs list -t snapshot -o name | grep ${BACKUP_POOL}@backup_ | head -n -7 | xargs -n 1 zfs destroy
echo “Backup completed at $(date)”
# 设置脚本权限
# chmod +x /backup/zfs_backup.sh
# 配置定时任务
# crontab -e
0 2 * * * /backup/zfs_backup.sh >> /var/log/backup.log 2>&1
# 验证定时任务
# crontab -l
0 2 * * * /backup/zfs_backup.sh >> /var/log/backup.log 2>&1
# 手动执行备份测试
# /backup/zfs_backup.sh
# 输出示例:
full send of rpool@backup_20260404_020000 estimated size is 50.0G
total estimated size is 50.0G
TIME SENT SNAPSHOT
02:00:00 256K rpool@backup_20260404_020000
02:30:00 25.0G rpool@backup_20260404_020000
03:00:00 50.0G rpool@backup_20260404_020000
Backup completed at Fri Apr 4 03:00:00 CST 2026
# 验证备份快照
# zfs list -t snapshot | head -5
NAME USED AVAIL REFER MOUNTPOINT
rpool@backup_20260404_020000 0B – 100G –
rpool/ROOT@backup_20260404_020000 0B – 49.5G –
rpool/data@backup_20260404_020000 0B – 200G –
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
