All modern operating systems are able to run many programs at the same time. For example, a typical Linux server might include a Web server, an email server, and probably a database service. Each of these programs runs as a separate process. What do you do if one of your services stops working? Here are some handy command-line tools for managing processes.
Each process uses time on a system's CPU, as well as other system resources such as memory and disk space. If a program goes wrong, it can start to use too much CPU time or memory and so deny other programs the resources they need to run.
Knowing how to manage rogue processes is an essential part of Linux system management. To help, turn to command-line tools such as ps, top, service, kill, and killall.
ps
ps shows the current processes running on the machine. ps has many options, but one of the most useful invocations is ps aux, which shows every process on the system.
A normal Linux server may have 100 processes running after boot up, so the output from the ps command can be quite long. Here are the first few lines from my CentOS 5 test machine:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 10308 668 ? S 15:03 0:00 init [5]
root 2 0.0 0.0 0 0 ? S 15:03 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN 15:03 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S 15:03 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S
Here is a brief explanation of each of the columns:
USER is the name of the user that owns the processes.
Each process has a unique process ID (or PID for short).
%CPU shows the CPU utilization of the process. It is the CPU time used divided by the time the process has been running expressed as a percentage.
%MEM is the amount of the physical memory the process is using.
VSZ show the virtual memory size of the process in kilobytes.
RSS is similar to VSZ, but rather than virtual memory size, RSS shows how much non-swapped, physical memory the process is using in kilobytes.
TTY is the controlling terminal.
STAT is the status of the process, where S means the process is sleeping and can be woken at any time, N means the process has a low priority, and < means the process has a high priority. Other letters to watch for are l which means the process is multi-threaded and R which means the processes is running.
START shows when the process was started.
TIME is the accumulated CPU time. This includes time spent running the processes and time spent in the kernel on behalf of that process.
For a complete explanation see the ps man page.
Finding a specific process in such a long list can be a problem. To help, you can use the grep command to look for matches in the text. For example, to look for the sendmail process, use the command:
ps aux | grep sendmail
root 2401 0.0 0.4 66444 2064 ? Ss 15:04 0:00 sendmail: accepting connections
smmsp 2409 0.0 0.3 53040 1752 ? Ss 15:04 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
gary 3807 0.0 0.1 60224 700 pts/2 R+ 15:17 0:00 grep sendmail
When you run it, the grep command itself will be shown (in this case PID 3807) as it matches the string we are looking for, namely sendmail. But of course it isn't part of the sendmail service.
top
While ps shows only a snapshot of the system process, the top program provides a dynamic real-time view of a system. It displays a system summary (with CPU usage, memory usage, and other statistics) as well as a list of running processes that changes dynamically as the system is in use. It lists the processes using the most CPU first.
The first few lines of top look something like this:
top - 15:18:00 up 54 min, 0 users, load average: 0.00, 0.10, 0.11
Tasks: 115 total, 2 running, 113 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.7%us, 0.0%sy, 0.0%ni, 99.0%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 467888k total, 458476k used, 9412k free, 15264k buffers
Swap: 3204884k total, 0k used, 3204884k free, 222108k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
554 root 15 0 229m 9940 4548 S 0.7 2.1 0:10.29 Xorg
1 root 15 0 10308 668 552 S 0.0 0.1 0:00.11 init
2 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0
The bottom part of the output is similar to the output from the ps command. In the top part, the Swap: line is useful for checking how much swap space is being used. For more information see the top man page.
service
The easiest way to start and stop services such as sendmail or the Apache Web server from the command line is to use the service command. Each service provide a script for easily starting and stopping the service.
To discover the status of a service, type service sendmail status. This should output something similar to:
sendmail (pid 4660 4652) is running...
If you want to shutdown a running sendmail, you can type service sendmail stop. To start it again, use service sendmail start. To stop and restart sendmail, use service sendmail restart.
If you can't stop a running or rogue service using the service command then you may need to resort to the kill and killall commands.
kill and killall
The kill command attempts to shut down a running process. In Linux, a process is stopped when the operating system sends it a signal telling it to shut down. The default signal for kill is TERM (signal 15), meaning software terminate. If it receives the signal, the process should shut down in an orderly way. If the process has become rogue, chances are that it won't respond to being told politely to shut down. In that case you have to send the KILL signal (signal 9 for short). So to kill off a running process (e.g. process 1234) we would use kill -9 1234.
The killall command kills running processes by name rather than by PID. This bring two immediate advantages. First, to kill a process we don't need to look for the PID using the ps command. Second, if there are multiple processes with the same name (as is the case with the Apache Web server) then all the processes will be killed in one fell swoop. As with kill, killall takes a signal parameter, and -9 is used to terminate the processes. So to kill off all the Apache processes you would use killall -9 httpd.
Restarting an unresponsive Web server
Let's look at an example of how to use these commands to solve a real-life problem. If you find that your Web server has stopped responding and needs to be restarted, first try the service command. The start/stop script for your Web server should be able to get it running again. For Apache on CentOS 5 we would type:
service httpd restart
If that fails, next try the killall command to eliminate the old instance of the Web server:
killall -9 httpd
Run ps to check that all the Apache services died:
ps aux | grep httpd
If there are any strays, kill them off individually with the kill command. Finally, restart the Web server with:
service httpd start
A friend of mine recently had problem with the fetchmail process. Fetchmail is a program that fetches mail from external mail servers and pulls them down onto the local server. One morning he discovered that his system was running slowly. A quick use of the top command revealed that the fetchmail process was using 99% of the system memory. He noted the fetchmail process's PID, then killed the process and restarted it using the service command. The memory was freed and the system sprang back to life.
Conclusion
You should monitor your system to ensure that none of your processes have gone haywire. One simple method is to permanently run a terminal window with the top command. A quick glance every so often will assure you that all is OK. If something does start to go bad, Linux provides useful tools to stop and restart processes. Only rarely will a full system reboot be needed.
read more | digg story
2007年6月16日星期六
Controlling your Linux system processes
2007年6月15日星期五
HOWTO: Installing And Working With eyeOS Under Linux (Ubuntu/Debian)
Great HOWTO explaining how to install the eyeOS 1.0 Web Operating System into a Linux system (It's for Debian, I tested it under Ubuntu). Just 4 steps and you can be working on eyeOS from any computer on the net. eyeOS is a web Operating System with a ports system like apt-get and 19 base applications to work on the browser, Open Source.
read more | digg story
2007年6月11日星期一
How to disable tap-clicking with your touchpad in Linux in a easy way
Lots of people have a love/hate relationship with their touch pad on their laptops. It’s great for speeding around your screen and doing lots of cool things with nary a mouse in site. It’s horrible when you accidentaly double-click that Quake 3 icon while your boss is strolling into the room.
Here’s a quick and easy guide to disabling tap-clicking and scrolling on your touchpad. With this little hack you’ll still have a mouse replacement, but will avoid Quake 3 inspired embarrassment.
First, you’ll need to edit your xorg.conf file. This is the file that controls your display, and oddly all of your input devices as well like your keyboard, mouse and…. touchpad. Open up a CLI (Applications-> Accessories-> Terminal) and let’s get down to business.
gksu gedit /etc/X11/xorg.conf
Now you’ve got your xorg.conf file open in an editor, let’s add one line too it. Look for this section in your xorg.conf file:
Section “InputDevice”
Identifier “Synaptics Touchpad”
Driver “synaptics”
Option “SendCoreEvents” “true”
Option “Device” “/dev/psaux”
Option “Protocol” “auto-dev”
Option “HorizScrollDelta” “0″
EndSection
Yours may have all of this stuff or it may have very little of it. The key points you want to look for are the Section and EndSection bits. Everything has to go between these two, and what we’re going to add is not exception.
See the Options above? We’re going to add an option. So cut and paste the following in there just above the EndSection portion:
Option “TouchpadOff” 2
Now save your file and exit Gedit. The next time you restart your laptop (or restart your X session) you’re touchpad will be click-less.
But perhaps this way is so complicated and sometimes it doesn't work! Then you should try this way:
For KDE:
1. Open KDE Control Center
2. Select Peripherals > Touch Pad
3. Select “Tapping” tab and uncheck “Enable Tapping”
4. Click “Apply”
Done
For Gnome:
sudo apt-get install gsynaptics
And go to System > Preferences > Touchpad
Done
2007年5月27日星期日
Make your firefox more beautiful in ubuntu!
One thing that has always bothered me about Ubuntu's firefox is that the buttons, radio buttons, drop down menus, text fields, and checkboxes (known as widgets) are very cruddy looking. Fortunately I found a simple way to fix this. What we have below is a replacement set of images and CSS code for the widgets which will make them much nicer on the eyes (see bottom of the post for screenshots).
The original widgets are done by Osmo Salomaa
By default this script works with the default firefox directory: /usr/lib/firefox. To work with a different directory (such as /usr/local/firefox32 if you are using Kilz's firefox32 package) you can specify a new installation/removal (option 3). Make sure you enter the correct path to your firefox directory. You can also change the installation/removal directory with the "-p=" or "--path=" command line options when you initiate the script (run ./install --help or read the README for more information).
Once you have the correct path (or you are just using the default /usr/lib/firefox path), you can install by using option 1 in the main menu. To run the installer immediately and bypass the menu use the "-i" or "--install" command line options when executing the script. Use the "-h" or "--help" command line options to get more information (./install -h).
To remove the widgets (make sure you have the correct path first just like with installing), just select option 2 from the main menu. If you wish to bypass the menu and go straight to removal, envoke the "-r" or "--remove" option.
You can also use the "-p=" option in conjunction with the "-r" or "-i" command line options if you like.
Example) ./install --path=/usr/local/Iceweasel32 -i
This would install the widgets to the /usr/local/Iceweasel32 directory.
I should also mention, I have included a backup forms.css file incase you mess anything up. This file is from a default 64-bit Firefox 2.0 installation. The forms.css file an be found in Firefox's "res" directory. You won't need my backup unless you accidently delete your's or the script malfunctions (in which case please contact me).
Read the README for more information. Screenshots are below, enjoy!
Buttons
Check Boxes
Radio Buttons
Drop Down Menus
Text Fields
Before
After
Download script:http://www.mediafire.com/?8xs20zmmrhv
Read more
2007年5月3日星期四
Ultimate Ubuntu performance tweaking guide
Lets start first with the kernel:
apt-get install build-essential libncurses-dev kernel-package
cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.tar.bz2
This will download the latest sources available, in my case linux-2.6.20.tar.bz2
cd /usr/src
tar -xjf linux-2.6.20.tar.bz2
cd linux-2.6.20
Now lets apply the Con Kolivas patches, these are patches designed to improve system responsiveness with specific emphasis on the desktop, but suitable to any workload.
wget www.kernel.org/pub/linux/kernel/people/ck/patches/2.6/2.6.20/2.6.20-ck1/patch-2.6.20-ck1.bz2
bzcat patch-2.6.20-ck1.bz2 |patch -p1
Copy the current kernel config and configuring the kernel
cp /boot/config-`uname -r` .config
make menuconfig
In “General Setup” activate:
- Support for paging of anonymous memory (swap)
- Support for prefetching swapped memory
In “Processor type and features“:
- Processor family Choose the model of your processor.
- set Preemption Model to Voluntary Kernel Preemption (Desktop)
- High Memory Support
- off - if you have less than 1 GB of RAM
- 1GB Low Memory Support - if you have 1GB of RAM
- 4GB - if you have more than 1GB of RAM
- set Timer frequency to 1000 Hz
In “Kernel hacking” uncheck “Kernel debugging“.
Now exit and save the configuration.
Making the new kernel package:
make-kpkg -initrd –revision=LinuxMonitor1 kernel_image kernel_headers modules_image
Installing the new kernel
cd ..
dpkg -i *.deb
HDParm
sudo gedit /etc/hdparm.conf
at the bottom add:
/dev/hda {
dma = on
io32_support = 1
}
/dev/cdroms/cdrom0 {
dma = on
interrupt_unmask = on
io32_support = 0
}
Concurrent Booting
Concurrent booting allows Ubuntu to take advantage of dual-core processors, as well as processors that hyperthread or multithread
or what ever the different companies call it now.
sudo gedit /etc/init.d/rc
Look through the file and you will find CONCURRENCY=none.
You must change it to: CONCURRENCY=shell
Prelink
Disclaimer: Prelinking might break your system! Only consider for use if you can risk the chance that your install might mess up. Most of all make sure that it gets to run the whole thing through the first time you prelink. Stopping in the middle can lead to system failure. Prelinking is a powerful device and needs to be used with care.
Prelink is no longer necessary in Feisty. Feisty uses a new linking mechanism called DT_GNU_HASH which dramatically speeds up the linking process without the need for continuously running this prelink program. Again, prelink is NOT useful starting from Feisty
How to enable prelink
1. Activate Ubuntu universe sources
2. Put this command into terminal to install Prelink:
sudo apt-get install prelink
3. Now put this command into the terminal:
sudo gedit /etc/default/prelink
4. Change where it says “PRELINKING=unknown” from unknown to “yes”
5. Adjust the other options if you know what the heck you’re doing. If it looks foreign to you, the defaults work well.
6. To start the first prelink (the longest one!), put this in terminal:
sudo /etc/cron.daily/prelink
Automatic Prelinking After Program Are Installed
One problem with prelinking in that when you install new programs those programs are not prelinked. So to avoid this problem when installing programs with apt-get or synaptic, use the directions below.
1. Put this in terminal:
sudo gedit /etc/apt/apt.conf
2. When the file opens in Gedit, put this line at the end of the file and save (even if the file has no content before you add the line):
DPkg::Post-Invoke {”echo Running prelink, please wait…;/etc/cron.daily/prelink”;}
General Notes About Prelinking
In the future, prelink performs a quick prelink (a less-than-1-minute procedure on most systems) daily, usually at midnight. Every 14 days, or whatever you changed it to be, a full prelink will run.
If you just did a major apt-get upgrade that changed systemwide libraries (i.e. libc6, glibc, major gnome/X libs, etc etc etc) and experience cryptic errors about libs, rerun step 6.
To undo prelink, change step 4 from yes to no, then rerun step 6.
Prelinking will make the binaries it prelinks change, so it’s not appropriate if you have tripwire or another checksum-based IDS system, or if you do incremental or differential backups to save on space.
Services
*Note you might not have all these services on your box.
To enable/disable services go to System -> Administration -> Services
1. acpi-support - leave it on.
2. acpid - The acpi daemon. These two are for power management, quite important for laptop and desktop computers, so leave them on.
3. alsa - If you use alsa sound subsystem, yes leave it on. But if you have the service below, its safe to be off. The default is off when alsa-utils is on.
4. alsa-utils - On my system, this service supercedes the alsa, so I turn off the alsa and turn this on at S level.
5. anacron - A cron subsystem that executes any cron jobs not being executed when the time is on. Most likely you’ve probably turned your computer off when a certain cron job time is ready. For example, updatedb is scheduled at 2am everyday, but at that moment, you computer is off, then if anacron service is on, it will try to catch up that updatedb cron.
6. apmd - If you computer is not that old which can’t even support acpi, then you may try to turn this off.
7. atd - like cron, a job scheduler. I turned it off.
8. binfmt-support - Kernel supports other format of binary files. I left it on.
9. bluez-utiles - I turned it off. I don’t have any bluetooth devices.
10. bootlogd - Leave it on.
11. cron - Leave it on.
12. cupsys - subsystem to manager your printer. I don’t have one so I turned it off, but if you do, just leave it on.
13. dbus - Message bus system. Very important, leave it on.
14. dns-clean - Mainly for cleaning up the dns info when using dial-up connection. I don’t use dial up, so I turn it off.
15. evms - Enterprise Volumn Management system. I turned it off.
16. fetchmail - A mail receving daemon. I turned it off.
17. gdm - The gnome desktop manager. I turned it off anyway since I get use to boot to console first. This is up to you if you want to boot directly to GUI.
18. gdomap - You can turn it off.
19. gpm - Mouse support for console. If you feel you’d better have a mouse on console, go turn it on.
20. halt - Don’t change it.
21. hdparm - tuning harddisk script, should be on.
22. hibernate - If your system support hibernate, leave it on. Otherwise, its useless for you.
23. hotkey-setup - This daemon setup some hotkey mappings for Laptop. Manufacturers supported are: HP, Acer, ASUS, Sony, Dell, and IBM. If you have a laptop in those brands, you can leave it on, otherwise, this might not have any benefits for you.
24. hotplug and hotplug-net - activating hotplug subsystems takes time. I’d consider to turn them off.
25. hplip - HP printing and Image subsystem. I turned it off.
26. ifrename - network interface rename script. Sounds pretty neat but I turned it off. Mainly for managing multiple network interfaces names. Since I have a wireless card and an ethernet card, they all assigned eth0 and ath0 from kernel, so its not really useful for me.
27. ifupdown and ifupdown-clean - Leave it on. They are network interfaces activation scripts for the boot time.
28. inetd or inetd.real - take a look your /etc/inetd.conf file and comment out any services that you don’t need.
29. klogd - Leave it on.
30. laptop-mode - A service to tweak the battery utilization when using laptops. You can leave it on.
31. linux-restricted-modules-common - You need to see if you really have any restricted modules loaded on your system. I’d leave it on.
32. lvm - I don’t use it so I turned it off. Leave it on if you *DO* have lvm.
33. makedev - Leave it on.
34. mdamd - Raid management tool. I don’t use it so I turned it off.
35. mdamd-raid - Raid tool. If you don’t have Raid devices, turn it off.
36. module-init-tools - Load extra modules from /etc/modules file. You can investigate your /etc/modules file and see if there is any modules that you don’t need. Normally, this is turned on.
37. mountvirtfs - mount virtual filesystems. Leave it on.
38. networking - bring up network interfaces and config dns info during boot time by scaning /etc/network/interfaces file. Leave it on.
39. ntpdate - Sync time with the ubuntu time server. Leave it on if you want.
40. nvidia-kernel - I compiled the nvidia driver by myself, so its useless for me now. If you use the ubuntu nvidia driver from the restrict modules, just leave it on. 41. pcmcia - pcmcia device - useless if you are using desktop which doesn’t have pcmcia card. So in that case, turn it off please.
42. portmap - daemon for managing services like nis, nfs, etc. If your laptop or desktop is a pure client, then turn it off.
43. powernowd - client to manage cpufreq. Mainly for laptops that support CPU speed stepping technology. Normally, you should leave it on if you are configuring a laptop, but for desktop, it might be useless.
44. ppp and ppp-dns - Useless to me. I don’t have dial-up.
45. readahead - It seems readahead is a kind of “preloader”. It loads at startup some libs on memory, so that some programs will start faster. But it increases startup time for about 3-4 seconds. So, you can keep it… or not. I tested and I just didn’t feel difference loading programs. So I decided to turn it off. If you have a reason to keep it on, please do so.
46. reboot - Don’t change it.
47. resolvconf - Automatically configuring DNS info according to your network status. I left it on.
48. rmnologin - Remove nologin if it finds it. It wouldn’t happen on my laptop, so I got rid of it.
49. rsync - rsync daemon. I don’t use it on my laptop, so turned it off.
50. sendsigs - send signals during reboot or shutdown. Leave it as it is.
51. single - Active single user mode. Leave it as it is.
52. ssh - ssh daemon. I need this so I turned it on.
53. stop-bootlogd - stop bootlogd from 2,3,4,5 runlevel. Leave it as it is.
54. sudo - check sudo stauts. I don’t see any good to run it everytime on a laptop or desktop client, so I turned it off.
55. sysklogd - Leave it as it is.
56. udev and udev-mab - Userspace dev filesystem. Good stuff, I left them on.
57. umountfs - Leave it as it is.
58. urandom - Random number generator. Might not useful but I left it on.
59. usplash - Well, if you really want to see the nice boot up screen, leave it as it is.
60. vbesave - video card BIOS configuration tool. Its able to save your video card status. I left it on.
61. xorg-common - setup X server ICE socket. Leave it as it is.
62. adjtimex - This is a kernel hw clock time adjusting too. Normally, you shouldn’t see this on your boot up list. In very rare case if you do see its on your boot up process, then there might be a reason why it is on, so better leave it that way. In my case, it is off.
63. dirmngr - A certification lists management tool. Work with gnupg. You will have to see if you need it or not. In my case, I turned it off.
64. hwtools - A tool to optimize irqs. Not sure what’s the benefits of turning it on. In my case, I turned it off.
65. libpam-devperm - A daemon to fix device files permissions after a system crash. Sounds pretty good, so I left it on.
66. lm-sensors - If you matherboard has builtin some sensor chips, it might be helpful to see hw status via userspace. I ran it and it said “No sensors found”, so I turned it off.
67. screen-cleanup - A script to cleanup the boot up screen. Well, turn on or off is up to you. In my case, I left it on.
68. xinetd - A inetd super daemon to manage other damons. In my system, the xinetd is managing chargen, daytime, echo and time (find them from /etc/xinetd.d dir), I care none of them, so I turned it off. If you do have some important services configured under xinetd, then leave it on.
linux学习笔记(6)开机流程简介
开机流程简介
1、載入 BIOS 的硬體資訊,並取得第一個開機裝置的代號;
2、讀取第一個開機裝置的 MBR 的 boot Loader (亦即是 lilo, grub, spfdisk 等等) 的開機資訊;
3、載入 Kernel 作業系統核心資訊, Kernel 開始解壓縮,並且嘗試驅動所有硬體裝置;
4、Kernel 執行 init 程式並取得 run-level 資訊;
5、init 執行 /etc/rc.d/rc.sysinit 檔案;
6、啟動核心的外掛模組 (/etc/modprobe.conf);
7、init 執行 run-level 的各個批次檔( Scripts );
8、init 執行 /etc/rc.d/rc.local 檔案;
9、執行 /bin/login 程式,並等待使用者登入;
10、登入之後開始以 Shell 控管主機。
在/etc/rc.d/rc3.d內,以S开头的为开机启动,以K开头的为关闭,接着的数字代表执行顺序
GRUB vga设定
彩度\解析度 640x480 800x600 1024x768 1280x1024 bit
256 769 771 773 775 8 bit
32768 784 787 790 793 15 bit
65536 785 788 791 794 16 bit
16.8M 786 789 792 795 32 bit
./configure 检查系统信息 ./configure --help | more 帮助信息
make clean 清除之前留下的文件
make 编译
make install 安装
rpm -q ----->查询是否安装 rpm -ql ------>查询该套件所有的目录
rpm -qi ----->查询套件的说明资料 rpm -qc[d] ----->设定档与说明档
rpm -ivh ---->安装 rpm -V -------->查看套件有否更动过
rpm -e ------>删除 rpm -Uvh ------->升级安装
--nodeps ----->强行安装 --test ----->测试安装
转http://blog.chinaunix.net/u/30619/showart.php?id=249558
linux学习笔记(5)帐户管理
帐号管理
/etc/passwd 系统帐号信息
/etc/shadow 帐号密码信息 经MD5 32位加密
在密码栏前面加『 * 』『 ! 』禁止使用某帐号
/etc/group 系统群组信息
/etc/gshadow
newgrp 改变登陆组
useradd & adduser 建立新用户 ---------> useradd -m test 自动建立用户的登入目录
useradd -m -g pgroup test --------->指定所属级
/etc/default/useradd 相关设定
/etc/login.defs UID/GID 有關的設定
passwd 更改密码 -----------> passwd test
usermod 修改用户帐号
userdel 删除帐号 ----------->userdel -r test
chsh 更换登陆系统时使用的SHELL [-l]显示可用的SHELL;[-s]修改自己的SHELL
chfn 改变finger指令显示的信息
finger 查找并显示用户信息
id 显示用户的ID -----------> id test
groupadd 添加组
groupmod 与usermod类似
groupdel 删除组
su test 更改用户 su - 进入root,且使用root的环境变量
sudo 以其他身份来执行指令
visudo 编辑/etc/sudoers 加入一行『 test ALL=(ALL) ALL 』
%wheel ALL = (ALL) ALL 系统里所有wheel群组的用户都可用sudo
%wheel ALL = (ALL) NOPASSWD: ALL wheel群组所有用户都不用密码NOPASSWD
User_Alias ADMPW = vbird, dmtsai, vbird1, vbird3 加入ADMPW组
ADMPW ALL = NOPASSWD: !/usr/bin/passwd, /usr/bin/passwd [A-Za-z]*, \
!/usr/bin/passwd root 可以更改使用者密码,但不能更改root密码 (在指令前面加入 ! 代表不可)
PAM (Pluggable Authentication Modules, 嵌入式模組)
who & w 看谁在线
last 最近登陆主机的信息
lastlog 最近登入的時間 读取 /var/log/lastlog
talk 与其他用户交谈
write 发送信息 write test [ctrl]+d 发送
mesg 设置终端机的写入权限 mesg n 禁止接收 mesg y
wall 向所有用户发送信息 wall this is q test
mail 写mail
/etc/default/useradd 家目录默认设置
quota 显示磁盘已使用的空间与限制 quota -guvs ----->秀出目前 root 自己的 quota 限制值
quota -vu 查询
quotacheck 检查磁盘的使用空间与限制 quotacheck -avug ----->將所有的在 /etc/mtab 內,含有 quota 支援的 partition 進行掃瞄
[-m] 强制扫描
quota一定要是独立的分区,要有quota.user和quota.group两件文件,在/etc/fstab添加一句:
/dev/hda3 /home ext3 defaults,usrquota,grpquota 1 2
chmod 600 quota* 设置完成,重启生效
edquota 编辑用户或群组的quota [u]用户,[g]群组,[p]复制,[t]设置宽限期限
edquota -a yang edquota -p yang -u young ----->复制
quotaon 开启磁盘空间限制 quotaon -auvg -------->啟動所有的具有 quota 的 filesystem
quotaoff 关闭磁盘空间限制 quotaoff -a -------->關閉了 quota 的限制
repquota -av 查閱系統內所有的具有 quota 的 filesystem 的限值狀態
Quota 從開始準備 filesystem 的支援到整個設定結束的主要的步驟大概是:
1、設定 partition 的 filesystem 支援 quota 參數:
由於 quota 必須要讓 partition 上面的 filesystem 支援才行,一般來說, 支援度最好的是 ext2/ext3 ,
其他的 filesystem 類型鳥哥我是沒有試過啦! 啟動 filesystem 支援 quota 最簡單就是編輯 /etc/fstab ,
使得準備要開放的 quota 磁碟可以支援 quota 囉;
2、建立 quota 記錄檔:
剛剛前面講過,整個 quota 進行磁碟限制值記錄的檔案是 aquota.user/aquota.group,
要建立這兩個檔案就必須要先利用 quotacheck 掃瞄才行喔!
3、編輯 quota 限制值資料:
再來就是使用 edquota 來編輯每個使用者或群組的可使用空間囉;
4、重新掃瞄與啟動 quota :
設定好 quota 之後,建議可以再進行一次 quotacheck ,然後再以 quotaon 來啟動吧!
linux学习笔记(4)shell初步知识
认识SHELL
alias 显示当前所有的命令别名 alias lm="ls -al" 命令别名 unalias lm 取消命令别名
type 类似which
exprot 设置或显示环境变量
exprot PATH="$PATH":/sbin 添加/sbin入PATH路径
echo $PATH 显示PATH路径
bash 进入子程序
name=yang 设定变量
unset name 取消变量
echo $name 显示变量的内容
myname="$name its me" & myname='$name its me' 单引号时$name失去变量内容
ciw=/etc/sysconfig/network-scripts/ 设置路径
env 列出所有环境变量
echo $RANDOM 显示随意产生的数
set 设置SHELL
PS1='[\u@\h \w \A #\#]\$ ' 提示字元的設定
[root@linux ~]# read [-pt] variable -----------读取键盘输入的变量
參數:
-p :後面可以接提示字元!
-t :後面可以接等待的『秒數!』
declare 声明 shell 变量
ulimit -a 显示所有限制资料
ls /tmp/yang && echo "exist" || echo "not exist"
意思是說,當 ls /tmp/yang 執行後,若正確,就執行echo "exist" ,若有問題,就執行echo "not exist"
echo $PATH | cut -d ':' -f 5 以:为分隔符,读取第5段内容
export | cut -c 10-20 读取第10到20个字节的内容
last | grep 'root' 搜索有root的一行,加[-v]反向搜索
cat /etc/passwd | sort 排序显示
cat /etc/passwd | wc 显示『行、字数、字节数』
正规表示法
[root@test root]# grep [-acinv] '搜尋字串' filename
參數說明:
-a :將 binary 檔案以 text 檔案的方式搜尋資料
-c :計算找到 '搜尋字串' 的次數
-i :忽略大小寫的不同,所以大小寫視為相同
-n :順便輸出行號
-v :反向選擇,亦即顯示出沒有 '搜尋字串' 內容的那一行!
grep -n 'the' 123.txt 搜索the字符 -----------搜尋特定字串
grep -n 't[ea]st' 123.txt 搜索test或taste两个字符---------利用 [] 來搜尋集合字元
grep -n '[^g]oo' 123.txt 搜索前面不为g的oo-----------向選擇 [^]
grep -n '[0-9]' 123.txt 搜索有0-9的数字
grep -n '^the' 123.txt 搜索以the为行首-----------行首搜索^
grep -n '^[^a-zA-Z]' 123.txt 搜索不以英文字母开头
grep -n '[a-z]$' 123.txt 搜索以a-z结尾的行---------- 行尾搜索$
grep -n 'g..d' 123.txt 搜索开头g结尾d字符----------任意一個字元 .
grep -n 'ooo*' 123.txt 搜索至少有两个oo的字符---------重複字元 *
sed 文本流编辑器 利用脚本命令来处理文本文件
awd 模式扫描和处理语言
nl 123.txt | sed '2,5d' 删除第二到第五行的内容
diff 比较文件的差异
cmp 比较两个文件是否有差异
patch 修补文件
pr 要打印的文件格式化
linux学习笔记(3)vi的一般用法
vi一般用法
一般模式 编辑模式 指令模式
h 左 a,i,r,o,A,I,R,O :w 保存
j 下 进入编辑模式 :w! 强制保存
k 上 dd 删除光标当前行 :q! 不保存离开
l 右 ndd 删除n行 :wq! 保存后离开
0 移动到行首 yy 复制当前行 :e! 还原原始档
$ 移动到行尾 nyy 复制n行 :w filename 另存为
H 屏幕最上 p,P 粘贴 :set nu 设置行号
M 屏幕中央 u 撤消 :set nonu 取消行号
L 屏幕最下 [Ctrl]+r 重做上一个动作 ZZ 保存离开
G 档案最后一行 [ctrl]+z 暂停退出 :set nohlsearch 永久地关闭高亮显示
/work 向下搜索 :sp 同时打开两个文档
?work 向上搜索 [Ctrl]+w 两个文档设换
gg 移动到档案第一行 :nohlsearch 暂时关闭高亮显示
linux学习笔记(2)常用命令
uname -a 查看内核版本
ls -al 显示所有文件的属性
pwd 显示当前路径
cd - 返回上一次目录 cd ~ 返回主目录
date s 设置时间、日期
cal 显示日历 cal 2006
bc 计算器具
man & info 帮助手册
locale 显示当前字体 locale -a 所有可用字体 /etc/sysconfig/i18n设置文件
LANG=en 使用英文字体
sync 将数据同步写入硬盘
shutdonw -h now & half & poweroff 关机
reboot 重启
startx & init 5 进入图形介面
/work & ?work 向上、下查找文档内容
chgrp 改变档案群组 chgrp testing install.log
chown 改变所属人 chown root:root install.log
chmod 改变属性 chmod 777 install.log read=4 write=2 execute=1
cp 复制 cp filename
rm 删除文件 rm -rf filename 强制删除文件
rmdir 删除文件夹
mv 移动 mv 123.txt 222.txt 重命名
mkdir 创建文件夹
touch 创建文件 更新当前时间
cat 由第一行开始显示 cat |more 分页
nl 在内容前加行号
more & less 一面一面翻动
head -n filename 显示第N行内容
tail -n filename 显示后N行内容
od 显示非纯文档
df -h 显示分区空间
du 显示目录或文件的大小
fdisk 分区设置 fdisk -l /dev/hda 显示硬盘分区状态
mkfs 建立各种文件系统 mkfs -t ext3 /dev/ram15
fsck 检查和修复LINUX档案
ln 硬链接 ln -s 软件链接
whereis 查找命令
locate 查找
find 查找 find / -name "***.***"
which 查看工具
whoami 显示当前用户
gcc -v 查看GCC版本
chattr +i filename 禁止删除 chattr -i filename 取消禁止
lsattr 显示隐藏档属性
updatedb 更新资料库
mke2fs 格式化 mkfs -t ext3
dd if=/etc/passwd of=/tmp/passwd.bak 备份
mount 列出系统所有的分区
mount -t iso9660 /dev/cdrom /mnt/cdrom 挂载光盘
mount -t vfat /dev/fd0 /mnt/floppy 挂载软盘
mount -t vfat -o iocharset=utf8,umask=000 /dev/hda2 /mnt/hda2 挂载fat32分区
mount -t ntfs -o nls=utf8,umask=000 /dev/hda3 /mnt/hda3 挂载ntfs分区
Linux-NTFS Project: http://linux-ntfs.sourceforge.net/
umount /mnt/hda3 缷载
ifconfig 显示或设置网络设备
service network restart 重启网卡
ifdown eth0 关闭网卡
ifup eth0 开启网卡
clear 清屏
history 历史记录 !55 执行第55个指令
stty 设置终端 stty -a
fdisk /mbr 删除GRUB
at 僅進行一次的工作排程
crontab 循環執行的例行性命令 [e]编辑,[l]显示,[r]删除任务
& 后台运行程序 tar -zxvf 123.tar.gz & --------->后台运行
jobs 观看后台暂停的程序 jobs -l
fg 将后台程序调到前台 fg n ------>n是数字,可以指定进行那个程序
bg 让工作在后台运行
kill 结束进程 kill -9 PID [9]强制结束,[15]正常结束,[l]列出可用的kill信号
ps aux 查看后台程序
top 查看后台程序 top -d 2 每两秒更新一次 top -d 2 -p10604 观看某个PID
top -b -n 2 > /tmp/top.txt ----->將 top 的資訊進行 2 次,然後將結果輸出到 /tmp/top.txt
pstree 以树状图显示程序 [A]以 ASCII 來連接, [u]列出PID, [p]列出帐号
killall 要刪除某個服務 killall -9 httpd
free 显示内存状态 free -m -------->以M为单位显示
uptime 显示目前系统开机时间
netstat 显示网络状态 netstat -tulnp------>找出目前系統上已在監聽的網路連線及其 PID
dmesg 显示开机信息 demsg | more
nice 设置优先权 nice -n -5 vi & ----->用 root 給一個 nice 植為 -5 ,用於執行 vi
renice 调整已存在优先权
runlevel 显示目前的runlevel
depmod 分析可载入模块的相依性
lsmod 显示已载入系统的模块
modinfo 显示kernel模块的信息
insmod 载入模块
modprobe 自动处理可载入模块
rmmod 删除模块
chkconfig 检查,设置系统的各种服务 chkconfig --list ----->列出各项服务状态
ntsysv 设置系统的各种服务
cpio 备份文件
压缩命令:
*.Z compress 程式壓縮的檔案;
*.bz2 bzip2 程式壓縮的檔案;
*.gz gzip 程式壓縮的檔案;
*.tar tar 程式打包的資料,並沒有壓縮過;
*.tar.gz tar 程式打包的檔案,其中並且經過 gzip 的壓縮
compress filename 压缩文件 加[-d]解压 uncompress
gzip filename 压缩 加[-d]解压 zcat 123.gz 查看压缩文件内容
bzip2 -z filename 压缩 加[-d]解压 bzcat filename.bz2 查看压缩文件内容
tar -cvf /home/123.tar /etc 打包,不压缩
tar -xvf 123.tar 解开包
tar -zxvf /home/123.tar.gz 以gzip解压
tar -jxvf /home/123.tar.bz2 以bzip2解压
tar -ztvf /tmp/etc.tar.gz 查看tar内容
cpio -covB > [file|device] 份份
cpio -icduv < [file|device] 还原
linux学习笔记(1)linux目录结构
/ 根目录
/bin 常用的命令 binary file 的目錄
/boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内
/boot/grub/menu.lst GRUB设置
/boot/vmlinuz 内核
/boot/initrd 核心解壓縮所需 RAM Disk
/dev 系统周边设备
/etc 系统相关设定文件
/etc/DIR_COLORS 设定颜色
/etc/HOSTNAME 设定用户的节点名
/etc/NETWORKING 只有YES标明网络存在
/etc/host.conf 文件说明用户的系统如何查询节点名
/etc/hosts 设定用户自已的IP与名字的对应表
/etc/hosts.allow 设置允许使用inetd的机器使用
/etc/hosts.deny 设置不允许使用inetd的机器使用
/etc/hosts.equiv 设置远端机不用密码
/etc/inetd.conf 设定系统网络守护进程inetd的配置
/etc/gateways 设定路由器
/etc/protocols 设定系统支持的协议
/etc/named.boot 设定本机为名字服务器的配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0 设置IP
/etc/resolv.conf 设置DNS
/etc/X11 X Window的配置文件,xorg.conf 或 XF86Config 這兩個 X Server 的設定檔
/etc/fstab 记录开机要mount的文件系统
/etc/inittab 设定系统启动时init进程将把系统设置成什么样的runlevel
/etc/issue 记录用户登录前显示的信息
/etc/group 设定用户的组名与相关信息
/etc/passwd 帐号信息
/etc/shadow 密码信息
/etc/sudoers 可以sudo命令的配置文件
/etc/securetty 设定哪些终端可以让root登录
/etc/login.defs 所有用户登录时的缺省配置
/etc/exports 设定NFS系统用的
/etc/init.d/ 所有服務的預設啟動 script 都是放在這裡的,例如要啟動或者關閉
/etc/xinetd.d/ 這就是所謂的 super daemon 管理的各項服務的設定檔目錄
/etc/modprobe.conf 内核模块额外参数设定
/etc/syslog.conf 日志设置文件
/home 使用者家目录
/lib 系统会使用到的函数库
/lib/modules kernel 的相关模块
/var/lib/rpm rpm套件安装处
/lost+found 系統不正常產生錯誤時,會將一些遺失的片段放置於此目錄下
/mnt 外设的挂载点
/media 与/mnt类似
/opt 主机额外安装的软件
/proc 虚拟目录,是内存的映射
/proc/version 内核版本
/proc/sys/kernel 系统内核功能
/root 系统管理员的家目录
/sbin 系统管理员才能执行的指令
/srv 一些服務啟動之後,這些服務所需要取用的資料目錄
/tmp 一般使用者或者是正在執行的程序暫時放置檔案的地方
/usr 最大的目录,存许应用程序和文件
/usr/X11R6: X-Window目录
/usr/src: Linux源代码
/usr/include:系统头文件
/usr/openwin 存放SUN的OpenWin
/usr/man 在线使用手册
/usr/bin 使用者可執行的 binary file 的目錄
/usr/local/bin 使用者可執行的 binary file 的目錄
/usr/lib 系统会使用到的函数库
/usr/local/lib 系统会使用到的函数库
/usr/sbin 系统管理员才能执行的指令
/usr/local/sbin 系统管理员才能执行的指令
/var 日志文件
/var/log/secure 記錄登入系統存取資料的檔案,例如 pop3, ssh, telnet, ftp 等都會記錄在此檔案中
/var/log/wtmp 記錄登入者的訊息資料, last
/var/log/messages 幾乎系統發生的錯誤訊息
/var/log/boot.log 記錄開機或者是一些服務啟動的時候,所顯示的啟動或關閉訊息
/var/log/maillog 紀錄郵件存取或往來( sendmail 與 pop3 )的使用者記錄
/var/log/cron 記錄 crontab 這個例行性服務的內容
/var/log/httpd, /var/log/news, /var/log/mysqld.log, /var/log/samba, /var/log/procmail.log:
分別是幾個不同的網路服務的記錄檔
