smartos教程二:与 Linux 不同点总结

在SmartOS用户中最常见的问题之一就是,既然说SmartOS和Linux类似,那除了那些看不见的技术细节,在使用时到底有什么不同呢?如果已经熟练操作Linux,那SmartOS能快速上手么?答案是当然能,其实常用的不同之处并不多。这篇文章将回答Linux与SmartOS在操作上的不同之处。

SmartMachine和其他类Unix系统不同之处主要在于两类:

  • 命令类似,但在SmartOS中用不同的名字
  • 完成类似的任务,但在SmartOS中有不同的实现过程

这里列出一个命令列表,用来帮助Linux用户找到在SmartOS中与Linux对等的命令。

  • Linux 和 SmartOS 命令对比列表
  • 不同使用语境(Use Context)的例子
    • 检查进程和内存
    • 启动和停止服务

Linux and SmartOS 命令对比列表

任务 / 操作系统LinuxSmartOSSmartOS Virtual Instance (zone)
表中缩写代表的含义
table key
(rh) = Red Hat, Mandrake, SUSE,...
(deb) = Debian, Libranet,...
(fed) = Fedora
(gen) = Gentoo
(md) = Mandrake/Mandriva
(SUSE) = SUSE
Joyent SmartOS

开源版本可访问以下链接http://smartos.org
Joyent SmartOS zone
管理用户
managing users
useradd
usermod
userdel
adduser
chage
getent
useradd
userdel
usermod
getent
logins
groupadd
useradd
userdel
usermod
getent
logins
groupadd
列举硬件配置信息
list hardware configuration
arch
uname
dmesg (if you're lucky)
cat /var/log/dmesg
/proc/*
lshw
dmidecode
lspci
lspnp
lsscsi
lsusb
lsmod
(SUSE) hwinfo
/sys/devices/*
arch
prtconf [-v]
prtpicl [-v]
uname
psrinfo [-v]
isainfo [-v]
dmesg
iostat -En
cfgadm -l
/etc/path_to_inst
arch
uname
psrinfo [-v]
isainfo [-v]
dmesg
iostat -En
读取磁盘命名
read a disk label
fdisk -lfdisk
prtvtoc
命名磁盘
label a disk
cfdisk
fdisk
e2label
format
prtvtoc
fdisk
磁盘分区
partition a disk
parted (if you have it)
cfdisk
fdisk
pdisk (on a Mac)
(deb) mac-fdisk (on a Mac)_
(md) _diskdrake
format
fmthard
rmformat
内核文件
kernel
/boot/vmlinuz*
/boot/bootlx
(see /etc/lilo.conf or /boot/grub/menu.lst)
/kernel/genunix
/platform/`uname -m`/
kernel/unix
kernel modules are in /kernel, /usr/kernel, and /platform/`uname -m`/kernel
Kernel module files not visible within a zone
显示/配置内核参数
show/set kernel parameters
/proc/*
/proc/sys/*
sysctl
/etc/sysctl.conf
sysdef
getconf
cat /etc/system
ndd
mdb -k[w]
sysdef
getconf
ndd
显示已加载的内核模块
loaded kernel modules
lsmodmodinfomodinfo
加载内核模块
load module
modprobe
insmod
modload
add_drv
devfsadm
卸载内核模块
unload module
rmmod
modprobe -r
modunload
启动脚本
startup scripts
/etc/rc* (but may vary)
/etc/init.d/
SMF(5)
/etc/rc*
/etc/init.d/
svcadm
svcs
SMF(5)
/etc/rc*
/etc/init.d
svcadm
svcs
启动/停止/配置服务
start/ stop/ config services
(rh) _service
(rh) _chkconfig
(deb) _sysv-rc-conf
svcs
svcadm
svccfg
svcs
svcadm
svccfg
关机
shutdown (& power off if possible)
shutdown -Ph now
shutdown -y -g0 -i0
halt
poweroff
shutdown -y -g0 -i5
halt
shutdown -y -g0 -i5
halt
run levels
*=normal states
更多细节参考
www.phildev.net/runlevels.html
(set in /etc/inittab)
0: halt
s,S,1: vendor-dependent
1: single-user
2-5*: multiuser
6: reboot
0: firmware monitor
s,S: single-user
1: sys admin
2: multiuser
3*: share NFS
4*: user-defined
5: power-down if possible
6: reboot
s,S: single-user
1: sys admin
2: multiuser
3*: share NFS
4*: user-defined
5: power-down if possible
6: reboot
show runlevel/sbin/runlevelwho -rwho -r
时区信息
time zone info
/usr/share/zoneinfo/
/etc/localtime
/usr/share/lib/zoneinfo//usr/share/lib/zoneinfo
检查交换分区
check swap space
swapon -s
cat /proc/meminfo
cat /proc/swaps
free
swap -s[h]
swap -l[h]
Note: in a zone, swap is virtual
memory size
swap -s[h]
swap -l[h]
bind process to CPUtaskset (sched-utils)pbind
psrset
pbind
psrset
终止进程
killing processes
kill
killall
kill
pkill
killall <- tries to kill everything, DO NOT USE THIS
kill
pkill
killall <- tries to kill everything, DO NOT USE THIS
显示CPU信息
show CPU info
cat /proc/cpuinfo
lscpu
psrinfo -pvpsrinfo -pv
内存信息
memory
freememprtconf | head
zonememstat
prtconf | head
zonememstat
默认文件系统
"normal" filesystem
ext2
ext3
ReiserFS
zfszfs
开机自动挂载分区配置
file system
description
/etc/fstab/etc/vfstab/etc/vfstab
创建文件系统
create filesystem
mke2fs
mkreiserfs
mkdosfs
mkfs
zfs
zpool
zfs (if zone has delegated dataset)
文件系统调试和恢复
file system debugging and recovery
fsck
debugfs
e2undel
zdb
创建非空文件
create non-0-length empty file
dd if=/dev/zero of=filename
bs=1024k count=desired
mkfilemkfile
创建/挂载ISO镜像
create/mount ISO image
mkisofs
mount -o loop pathToIso
mountPoint
mkisofs;DEVICE=`lofiadm -a /absolute_pathname/image.iso` ; mount -F hsfs -o ro
$DEVICE
ACL配置
ACL management
getfacl
setfacl
getfacl
setfacl
getfacl
setfacl
NFS share definitions/etc/exports/etc/dfs/dfstab
dfshares
NFS share command/etc/init.d/nfs-server reload_(rh)__ _exportfs -ashare
shareall
NFS informationcat /proc/mountsshowmount
nfsstat
nfsstat
name resolution order/etc/nsswitch.conf
/etc/resolv.conf
/etc/nsswitch.conf
getent
/etc/nsswitch.conf
getent
显示网络接口信息
show network interface info
ifconfig
ethtool
dladm
ndd
ifconfig -a
netstat -in
dladm
ndd
ifconfig -a
netstat -in
更改IP地址
change IP
Joyent Public Cloud IP addresses are set in the Cloud Management Portal.
ifconfig
ping one packetping -c 1 hostnameping hostname packetsize 1ping hostname packetsize 1
监听网络
sniff network
etherfind
tcpdump
wireshark (formerly _ethereal)
etherape
snoopsnoop
tcpdump available from pkgin
route definitionsroute
(rh) /etc/sysconfig/network
(rh) /etc/sysconfig/static-routes
(deb) /etc/init.d/network
(deb) /etc/network
/etc/defaultrouter
/etc/notrouter
/etc/gateways
in.routed
netstat -r
route add
/etc/defaultrouter
/etc/notrouter
/etc/gateways
in.routed
netstat -r
route add
telnetd, ftpd banner/etc/issue.net (telnet)
(ftp varies; can use tcp wrappers)
Use nc insteadUse nc instead
配置日期/时间
set date/time
(from net: ntp or other)
ntpdate
rdate
netdate
ntpdate
rdate
ntpdate
rdate
auditingauditd
/var/log/faillog
audit
auditd
auditreduce
praudit
audit
auditd
auditreduce
praudit
用户密码保存位置
encrypted passwords in
/etc/shadow (may vary)/etc/shadow/etc/shadow
最小密码长度
min password length
/etc/pam.d/system-auth/etc/default/passwd/etc/default/passwd
允许/禁止root登陆
allow/deny root
logins
/etc/securetty/etc/default/login/etc/default/login
防火墙配置
firewall config
iptables
ipchains
ipfwadm
(rh) redhat-config-
securitylevel
/etc/ipf/ipf.conf/etc/ipf/ipf.conf
显示已安装的软件
show installed software
(rh) _rpm -a -i
(rh) _rpm -qa
(rh) yum list installed
(deb) dselect
(deb) aptitude
(deb) dpkg -l
(gen) _ls /var/db/pkg/*
(gen) _eix -I
pkgin list
pkgin avail <- list available installable software
安装软件
add software
(rh) _rpm -hiv
(rh) yum install pkg
(deb) dselect
(deb) _apt-get install _pkg
(deb) dpkg -i
pkgin install
precompiled binaries* of GPLware and freeware*www.linux.org
linux.tucows.com
sourceforge.net
rpmfind.net
(deb) ftp.debian.org
(deb) packages.debian.org
(gen) packages.gentoo.org
(gen) gentoo-portage.com;
(md) easyurpmi.zarb.org
www.sunfreeware.com
www.blastwave.org
http://pkgsrc.joyent.com/
pkgin
C编译器
C compiler
cc
gcc
gcc
[https://download.joyent.com/pub/build/SunStudio.tar.bz2]
gcc (may need to be installed via pkgin)
https://download.joyent.com/pub/build/SunStudio.tar.bz2
configure/show
runtime linking
ldconfig
ldd
readelf
lsmod
crle
ldd
elfdump
dump
pldd
modinfo
LD_PRELOAD
crle
ldd
elfdump
dump
readelf
pldd
modinfo
LD_PRELOAD
链接库路径
link library path
$LD_LIBRARY_PATH
/etc/ld.so.conf
$LD_LIBRARY_PATH$LD_LIBRARY_PATH
跟踪工具
tracing utility
strace
ltrace
dtrace
truss
sotruss
dtrace
truss
sotruss
define user defaults/etc/profile
/etc/security/
/etc/skel/
/etc/profile.d/*
/etc/default/login
/etc/profile
/etc/security/
/etc/default/login
/etc/profile
/etc/security/
csh global .login/etc/csh.login/etc/.login/etc/.login
default syslog and messages/var/log/syslog
/var/log/messages
/usr/adm/messages
/var/log/maillog
/var/adm/messages
/var/log/syslog
softpanorama.org/Logs/solaris_logs.shtml
/var/adm/messages
/var/log/syslog
系统错误报告工具
system error reporting tool
dmesg_(deb)_ reportbugfmadm
fmdump
prtdiag
fmadm
fmdump
性能检测
performance monitoring
vmstat
procinfo -D
top
htop
pstree
dtrace
prstat
sar
ostat
kstat
mpstat
netstat
nfsstat
vmstat
lockstat
plockstat
ptree
vfsstat
intrstat
dtrace
prstat
sar
ostat
kstat
mpstat
netstat
nfsstat
vmstat
plockstat
ptree
vfsstat
查看进程占用的文件和端口match process to file or portlsof
netstat -atup
fuser
pfiles
pfiles
fuser
lsof
zones/containerszoneadm
zonecfg
zlogin
zoneadm
zonename
虚拟工具
Virtualization
kvm/qemukvm/qemu (each instance in a kvm branded zone)
vmadm
imgadm
WikipediaLinuxSmartOS
Illumos
SmartOS
Illumos

smartos 和linux相同命令不同作用的例子

下面的例子是一些常用的命令,他们在linux与smartos中的作用不同

CommandWhat's different on a Smart Machine
dfOn most SmartOS image this is set up to use the GNU version. Use /usr/bin/df for the native version.
lsofSmartMachines use a different collection of tools to examine processes. See [Examining processes and memory|#procmem||||||||||||\||] later in this topic.
pingReturns whether a host responds or not.
Use ping -s to get a continuous response.
toptop is available in /opt/local/bin, but prstat -Z provides more zone aware (and more accurate) information than top.

Rosetta Stone for Unix 是一个有用的资源,可以帮你看看你经常使用的UNIX版本和其他的UNIX版本(包括Mac)有何不同,并如何对应。

检查进程和内存

在旧的SmartOS镜像中,这些命令提供了端口和相关资源的信息,使用root或sudo可运行它们。新的镜像使用的是 SmartMachine 工具包(Tools Package)

CommandDescriptionExample
pcpDisplays the ports used by a process, or the processes that use a port./root/bin/pcp -p 80 displays all the processes that use port 80.
/root/bin/pcp -P 28068 displays all the ports that process 28068 uses.
/root/bin/pcp -a displays port and process information for all ports.
jinfDisplays information about how your SmartMachine is using its resources./root/bin/jinf -c displays CPU usage information.
/root/bin/jinf -m displays memory usage information.
/root/bin/jinf -s displays swap usage information.

SmartOS 提供了一个工具套件来检查进程,可以在 proc 的 man page 中学习到更多内容。

ToolDescription
prstatThis tool displays the active processes like top does on Linux systems.
prstat -Z will provide you with a summary of your SmartMachine's status.
pgrepReturns a list of process IDs (PIDs) of processes that match a pattern or meet certain conditions.
pkillKills the processes that match a pattern or meet certain conditions.
pfilesReturns a list of all the open files that belong to a process.
pstackDisplays a stack trace of the specified process
ptreeDisplays a process tree for all processes or a given process
ls /procLists the process IDs of all running processes.

你可以将 pgrep 的结果和其他 proc 工具合并显示。比如,显示与 http 进程相关的所有文件,可以使用如下命令来替代 lsof:

$ sudo pfiles $(pgrep http)

若要限制 prstat 显示 http 进程,可以使用命令:

$ prstat $(pgrep -d , http)

注意:如果 prstat 显示改变了你的终端设置,可以使用 reset 命令返回到正常状态

对于 vmstat, mpstat 和 psrinfo 命令,主要显示物理机中处理器和内存的统计信息。这些输出一般来说对于SmartMachine的管理员才有用。

启动和停止服务

在其他系统中,你也许习惯使用命令在 /etc/init.d 来启动或停止服务。
SmartMachines 使用 Service Management Facility 来做到这些。

命令 svcs 和 svcadm 是你经常会使用到的。有些命令把 service identifier 叫做FMRI(Fault Management Resource Identifier)。
你可以使用 svcs 命令列举一个服务所有的 identifier 。

CommandDescription
svcsLists all the enabled services
svcs -aLists all of the services, even those that are disabled or off line
svcadm enable apacheEnable all of the processes with an apache FMRI
svcadm disable apacheDisable all of the processes with an apache FMRI
svcadm restart apacheRestart all of the processes with an apache FMRI

例如,如果你想更改 /etc/ssh/sshd_config 后重启SSH,可以这样做:

$ sudo svcadm restart ssh

向了解更多关于SMF的信息,可以打开这个网页

回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.