ubuntu下安装配置Postfix邮件系统
1. Introduction(介绍)
Postfix is a Mail Transfer Agent (MTA) which is the default MTA for Ubuntu. It is in Ubuntu’s main repository, which means that it receives security updates. This guide explains how to install and configure postfix and set it up as an SMTP server using a secure connection.
Postfix是一个邮件传输客户端(MTA),它也是ubuntu中默认的邮件传输客户端.它是Ubuntu的main软件库中的一个软件.这意味着它拥有安全更新.这份指南告诉你如何安装及配置postfix并将其设置成一个使用安全连接的SMTP服务器.
2. Installation(安装)
In order to install Postfix with SMTP-AUTH and TLS do the following steps:
安装带SMTP-AUTHT和TLSR的Postfix使用如下的命令:
apt-get install postfix libsasl2 sasl2-bin libsasl2-modules libdb3-util procmail
3. Configuration(配置)
Run:
运行:
dpkg-reconfigure postfix
Insert the following details when asked (replacing server1.example.com with your domain name if you have one):
当要求提供相关信息时输入如下的信息(如果你拥有一个域名的话,将server1.example.com替换成你自己的域名):
* Internet Site
* NONE
* server1.example.com
* server1.example.com, localhost.example.com, localhost
* No
* 127.0.0.0/8
* Yes
* 0
* +
* all
Then run the following commands:
运行下列命令:
### Configure Postfix to do SMTP AUTH using SASL (saslauthd)
postconf -e ’smtpd_sasl_local_domain =’
postconf -e ’smtpd_sasl_auth_enable = yes’
postconf -e ’smtpd_sasl_security_options = noanonymous’
postconf -e ‘broken_sasl_auth_clients = yes’
postconf -e ’smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination’
postconf -e ‘inet_interfaces = all’
echo ‘pwcheck_method: saslauthd’ >> /etc/postfix/sasl/smtpd.conf
echo ‘mech_list: plain login’ >> /etc/postfix/sasl/smtpd.conf
### Generate certificates to be used for TLS encryption and/or certificate Authentication
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
### Configure Postfix to do TLS encryption for both incoming and outgoing mail
postconf -e ’smtpd_tls_auth_only = no’
postconf -e ’smtp_use_tls = yes’
postconf -e ’smtpd_use_tls = yes’
postconf -e ’smtp_tls_note_starttls_offer = yes’
postconf -e ’smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key’
postconf -e ’smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt’
postconf -e ’smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem’
postconf -e ’smtpd_tls_loglevel = 1′
postconf -e ’smtpd_tls_received_header = yes’
postconf -e ’smtpd_tls_session_cache_timeout = 3600s’
postconf -e ‘tls_random_source = dev:/dev/urandom’
postconf -e ‘myhostname = server1.example.com’
The file /etc/postfix/main.cf should now look like this: /etc/postfix/main.cf
这个文件应当是如下的内容:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA’s job.
append_dot_mydomain = no
# Uncomment the next line to generate “delayed mail” warnings
#delay_warning_time = 4h
myhostname = server1.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = server1.example.com, localhost.example.com, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a “$EXTENSION”
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject _unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
Restart the postfix daemon like this:
重启postfix守护进程:
/etc/init.d/postfix restart
4. Authentication(验证)
Authentication will be done by saslauthd.
使用saslauthd来执行验证
We have to change a few things to make it work properly. Because Postfix runs chrooted in /var/spool/postfix we have change a couple paths to live in the false root. (ie. /var/run/saslauthd becomes /var/spool/postfix/var/run/saslauthd):
我们应当修改一些内容来令saslauthd正常工作.因为Postfix需要将根目录更改为/var/spool/postfix ,我们应当将那些使用不正确根目录的目录更改为正确的.(例如:将/var/run/saslauthd 修改为/var/spool/postfix/var/run/saslauthd):
First we edit /etc/default/saslauthd in order to activate saslauthd. Remove # in front of START=yes and add the PWDIR, PARAMS, and PIDFILE lines:
首先,我们需要编辑/etc/default/saslauthd 以激活 saslauthd . 请将 START=yes 之前的 # 号去掉并添加 PWDIR, PARAMS 和 PIDFILE 行:
# This needs to be uncommented before saslauthd will be run automatically
START=yes
PWDIR=”/var/spool/postfix/var/run/saslauthd”
PARAMS=”-m ${PWDIR}”
PIDFILE=”${PWDIR}/saslauthd.pid”
# You must specify the authentication mechanisms you wish to use.
# This defaults to “pam” for PAM support, but may also include
# “shadow” or “sasldb”, like this:
# MECHANISMS=”pam shadow”
MECHANISMS=”pam”
Note: If you prefer, you can use “shadow” instead of “pam”. This will use MD5 hashed password transfer and is perfectly secure. The username and password needed to authenticate will be those of the users on the system you are using on the server.
注 : 如果你喜欢的话,你可以使用”shadow”来替换”pam” .这将使用MD5生成的哈希值来传输以得到更高的安全性. 需要验证的用户名及密码将是那些你服务器上的系统上的.
Next, we update the dpkg “state” of /var/spool/portfix/var/run/saslauthd. The saslauthd init script uses this setting to create the missing directory with the appropriate permissions and ownership:
下一步: 我们更新 dpkg 中 /var/spool/portfix/var/run/saslauthd 的状态. saslauthd 的启动脚本需要一个特定的用户权限来建立一个新的目录.
dpkg-statoverride –force –update –add root sasl 755 /var/spool/postfix/var/run/saslauthd
Finally, start saslauthd:
最后,启动saslauthd:
/etc/init.d/saslauthd start
5. Testing(测试)
To see if SMTP-AUTH and TLS work properly now run the following command:
要查看SMTP-AUTH 及TLS能否正常工作请使用如下命令:
telnet localhost 25
After you have established the connection to your postfix mail server type
在您建立了与您的postfix邮件服务器类型的连接之后
ehlo localhost
If you see the lines
如果你看到如下行
250-STARTTLS
250-AUTH
among others, everything is working.
在其它内容之上,表明一切正常.
Type quit to return to the system’s shell.
输入 quit 以返回系统.
6、安装Postfix
从下面的URL下载Postfix 2.2.8的源代码:http://www.postfix.org
从下面的URL下载Postfix 2.2.8的VDA补丁程序:http://web.onda.com.br/nadal/
chkconfig –level 2345 sendmail off
增加Postfix运行所需要的用户和组,并建立“/home/mail”目录作为存储邮件的地方:
groupadd postfix
groupadd postdrop
useradd postfix -g postfix -c “Postfix user” -d /nonexistent -s /sbin/nologin
mkdir /home/mail
chown postfix:postfix /home/mail
安装Postfix:
gzip -d postfix-2.2.8-vda.patch.gz
tar zvxf postfix-2.2.8.tar.gz
cd postfix-2.2.8
patch -p1 >/etc/postfix/aliases
/usr/bin/newaliases
注:因为Postfix不允许直接发邮件给root用户,所以你需要为root用户建立一个别名。
建立smtpd用户认证的配置文件:
vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list: plain login
authdaemond_path:/var/spool/authdaemon/socket
使用postconf -n简化main.cf,这样的好处是main.cf比较短小,不容易造成同一个配置出现两次的问题:
cd /etc/postfix
postconf -n > main2.cf
mv main.cf main.cf.old
mv main2.cf main.cf
修改Postfix的配置文件,#号之后是说明文字:
vi /etc/postfix/main.cf
myhostname = mail.example.com # mail.example.com是安装Postfix软件的主机名
mydomain = example.com # example.com是安装Postfix软件的主机名中的域名部分
myorigin = $mydomain
mydestination =
alias_maps = hash:/etc/aliases
home_mailbox = Maildir/ # 使用Maildir作为邮件的存储格式
# Add following line in file’s finality
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_base = /home/mail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 102400000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 502
virtual_uid_maps = static:502
virtual_gid_maps = static:502
virtual_transport = virtual
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user’s maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes
virtual_trash_count=yes
virtual_trash_name=.Trash
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname,
reject_rbl_client opm.blitzed.org,
reject_rbl_client list.dsbl.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client sbl-xbl.spamhaus.org
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
注:①“virtual_gid_maps”和“virtual_uid_maps”是postfix用户的gid和uid, “virtual_minimum_uid”应当≤“virtual_uid_maps”,“virtual_mailbox_limit”是每个邮箱的大小。
②opm.blitzed.org、list.dsbl.org、bl.spamcop.net、sbl-xbl.spamhaus.org是经常使用的几个反垃圾邮件列表,如果你使用上面的设置可能无法收到sina、sohu、163等几个国内主要ISP的邮件。你也可以使用中国反垃圾邮件联盟的反垃圾邮件列表,这样你就能收到国内几个主要ISP的邮件,同时一些垃圾邮件也可能光临你的邮件服务器^_^。
③Postfix使用MySQL存储用户信息的配置文件已经包含在extman的发行包中,等安装extman的时候copy到/etc/postfix目录下即可。
设置Postfix开机自动运行,在/etc/rc.local中增加“/usr/sbin/postfix start&”。
注:①系统已经打开了Postfix的TLS支持,如果你需要这项功能可以参考Postfix发行包中的TLS_README文档进行配置。
②你可以使用一个叫pflogsumm.pl的perl脚本对postfix的日志进行分析,详细的情况见:http://jimsun.linxnet.com/postfix_contrib.html。
7. Installing courier IMAP and POP3
sudo apt-get install courier-pop
sudo apt-get install courier-imap
自已架站就要 DIY 一些比較底層的東西,像是 firewall, dns, mail server… 等等有的沒的。啊!現在想想公司有 MIS 可以依賴真好 (被寵壞啦~)。好,回正題吧。先聲名一下,本文不是架一台 mail server,然後提供用戶 pop3, smtp 等那種偉大的服務。我的需求很簡單,只是讓網站能寄信出去而已,像是寄寄認證信,通知信之類的小事。
OS: Ubuntu
Ubuntu 真是個好用的 Linux distro,以前我是用 redhat 的,但是 fedora 對我的 notebook 支援不好,所以改成最多人使用的 Ubuntu。久而久之就迷上啦!所以 server 也開始改用 Ubuntu。Ubuntu 吸引我的優點是 (1) 不會裝無謂的 service — 從 security 這角度來看是比較好。像 fedora 就 “很好心”,一口氣幫你全裝了,但你不見得用的到,你也不見得都懂那些 service 在幹嘛,留著洞放在那就是徒增無謂的風險。(2) apt-get 比 fedora 的 yum 好用太多了,快速、問題又少 ![]()
Mail Agent: postfix
對我這個 mail 白吃,只能裝人家包好的來用:
sudo apt-get install mutt
上面這個指令自動安裝一個 command-line 的 mail client mutt。mutt 這個程式可以用 command line 指令直接寄帶有 attachment 的 email,功能強大,很適合來做 scripting,推薦大家使用!好了,注意看安裝過程,安裝 mutt 時,apt-get 會順便將 postfix mail agent 也一併安裝了。感覺真爽!緊接著會進入 postfix 的設定畫面:
* General Type of Configuration: 選Internet Site
* Mail name? 設為 mysite.com.tw
* Other dest. to accept mail for? 設為 空白
* Force sync. updates on mail queue? 設 Yes
上面僅列出幾個比較特別要設的,其他的設定都用預設值即可。設完之後 postfix 便會啟動,並且只限本機才能寄 email。(這樣才能避免別人將你的站當垃圾信轉寄站)
安裝完後,查看 /etc/postfix/main.cf 底下應該是長這樣:
myhostname = mysite.com.tw
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination =
relayhost =
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
myorigin = /etc/mailname
inet_protocols = all
如果想要再次修改 postfix 的設定,可以用下面這個指令:
sudo dpkg-reconfigure –priority=low postfix
OK,寄一封信測試一下 postfix 是否正常運作吧:
echo “test content” | mutt -s “test subject” myname@example.com.tw
寄出後,到 /var/log/mail.log 看一下 log 訊息,只要沒看到 refuse talk, reject 之類的字眼,對方的 server 大概已接受了你的來信。OK,現在到你的信箱去(myname@example.com.tw) 應該會收到剛才那一封測試信才是。而且大概會被分類到垃圾信箱…
設定 dns 反查
為了避免寄出去的信被當做垃圾信,首先要設定 dns 反查,讓你的 ip 可以反查回 domain name。這樣別人的 mail server 才比較能相信你的站寄的信件。
#下指令:
nslookup 220.xxx.xxx.xxx
#如果是 hinet ,結果大概是:
Server: 168.95.192.1
Address: 168.95.192.1#53
xxx.xxx.xxx.220.in-addr.arpa name = xxxxxxxxxxxx
最後面的 name= xxxxxxx 如果不是出現你的 domain name,表示還沒設反查。那麼請洽 ISP 幫你設定。我是用 hinet adsl 固定制的,大概說一下流程:首先要到 申請 hinet 領域反解填線上申請表。按照範例填妥後送出,再將畫面上的申請表列印並加蓋個人私章 (個人申請用私章),再 fax 給該單位即可。沒意外的話,下個工作天就會收到已完工的 email。然後 dns 的反查大約需要 12~24 小時才會生效。屆時再用 nslookup 檢查一下即可。
設定 Sender Policy Framework (SPF)
設定 dns 反查只是解決被誤判垃圾信的第一步,接下來還要設定 SPF,一種對付垃圾信的技術,詳細說明請看 Wikipedia SPF。我自個兒呢… 有看沒有懂…. 所幸有高人相助啊!!
首先到你的註冊 domain name 的網站,通常裡面都有 DNS zone file 的設定。請加入下面這一行 spf 相關的設定:
mysite.com.tw. 86400 IN TXT v=spf1 a ip4:220.xxx.xxx.xxx -all
前面是你的 mail 的 full domain name,記得要用 . 結尾。86400 是設定 TTL (Time To Live) 的秒數。86400秒意指這個設定一天內都不需重讀。這個值我亂設的… 也許可以設更長?按理說固定 ip 應該不會常換才是?
好了,設完之後,大概也是等個幾小時才會生效。想確認可以到 邪惡的地方做個測試,只要輸入 doman name 即可。(測完後要記得洗手啊!!)
OK,就設到這邊。gmail 和 yahoo 大致上不會把站寄出去的信當 spam 了,除非你發信的內容太像 spam… 不過 hotmail 還是不大行,也不知還差了啥?這就要請教各位高手了…
ps. 感謝 koji兄 和 tempo兄 指導與協助!
ps2. 如果你是像我一樣,只求本機可以寄信出去,那麼 firewall 不用開 port 25 (smtp)
ps3. 我想先買 Wii 耶。
前 言
在CentOS中,默认的邮件服务器(SMTP方面)是sendmail,但sendmail有若干的缺点,比如,配置复杂、安全漏洞曾被多次发现 –并且依然存在隐患、邮件发送速度慢等等,这里就不再一一叙述。而另一个被广泛应用于邮件服务方面的“Postfix”的缺点就少得多,或者说它就是针对于sendmail的缺点,而被设计的。对应sendmail的短处,它在各方面也比较成熟。所以,无特殊要求,这里不推荐用sendmail来构建邮件服务器。本站介绍的邮件服务器配置方法,也将基于Postfix。
添加MX记录(这里假设使用动态域名)
由于MX记录添加后,可能生效要等待一段时间(通常为数分钟或数十分钟,也可能马上生效),所以在安装配置前,我们首先为动态域名添加MX记录。添加方法也会因域名ISP的不同而不同,但大致信息如下:
mx mail.centospub.com. 10
a mail 服务器的IP地址
mail为别名,10为优先度。这个别名指向服务器的IP地址。(如有疑问或需要帮忙请到 技术论坛 发贴。)
确认MX记录的添加是否生效的方法:
[root@sample ~]# host -t mx centospub.com
centospub.com mail is handled by 10 mail.centospub.com. ← 确认MX记录生效
安装Postfix
然后,安装Postfix。
[root@sample ~]# yum -y install postfix ← 在线安装Postfix
Setting up Install Process
Setting up repositories
dag 100% |=========================| 1.1 kB 00:00
update 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 28 kB 00:04
update : ################################################## 84/84
Added 84 new packages, deleted 1499 old in 3.44 seconds
primary.xml.gz 100% |=========================| 157 B 00:00
Added 0 new packages, deleted 1499 old in 1.97 seconds
primary.xml.gz 100% |=========================| 26 kB 00:00
extras : ################################################## 102/102
Added 102 new packages, deleted 1499 old in 2.73 seconds
Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only
Finished
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for postfix to pack into transaction set.
postfix-2.2.10-1.RHEL4.2. 100% |=========================| 40 kB 00:00
—> Package postfix.i386 2:2.2.10-1.RHEL4.2 set to be updated
–> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
postfix i386 2:2.2.10-1.RHEL4.2 base 3.0 M
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 3.0 M
Downloading Packages:
(1/1): postfix-2.2.10-1.R 100% |=========================| 3.0 MB 00:05
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: postfix ######################### [1/1]
Installed: postfix.i386 2:2.2.10-1.RHEL4.2
Complete!
配置Postfix及相关组件
[1] 对Postfix进行配置。
[root@sample ~]# vi /etc/postfix/main.cf ← 编辑Postfix的配置文件
#myhostname = host.domain.tld ← 找到此行,将等号后面的部分改写为主机名
↓
myhostname = sample.centospub.com ← 变为此状态,设置系统的主机名
#mydomain = domain.tld ← 找到此行,将等号后面的部分改写为域名
↓
mydomain = centospub.com ← 变为此状态,设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)
#myorigin = $mydomain ← 找到此行,将行首的#去掉
↓
myorigin = $mydomain ← 变为此状态,将发信地址“@”后面的部分设置为域名(非系统主机名)
inet_interfaces = localhost ← 找到此行,将“localhost”改为“all”
↓
inet_interfaces = all ← 变为此状态,接受来自所有网络的请求
mydestination = $myhostname, localhost.$mydomain, localhost ← 找到此行,在行为添加“$mydomain”
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 变为此状态,指定发给本地邮件的域名
#relay_domains = $mydestination ← 找到此行,将行首的#去掉
↓
relay_domains = $mydestination ← 变为此状态,定义允许转发的域名
#mynetworks = 168.100.189.0/28, 127.0.0.0/8 ← 找到此行,依照自己的内网情况修改
↓
mynetworks = 168.100.189.0/28, 127.0.0.0/8 ← 变为此状态,指定内网和本地的IP地址范围
#home_mailbox = Maildir/ ← 找到这一行,去掉行首的#
↓
home_mailbox = Maildir/ ← 变为此状态,指定用户邮箱目录
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server’s greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) ← 找到这一行,接此行添加如下行:
smtpd_banner = $myhostname ESMTP unknow ← 添加这一行,不显示SMTP服务器的相关信息
在配置文件的文尾,添加如下行:
smtpd_sasl_auth_enable = yes ← 服务器使用SMTP认证
smtpd_sasl_local_domain = $myhostname ← 指定SMTP认证的本地域名(主机名)
smtpd_sasl_security_options = noanonymous ← 不允许匿名的方式认证
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 15728640 ← 规定邮件最大尺寸为15MB
[2] 配置SMTP认证的相关选项
为了提高安全性,我们不将系统用户的密码作为相应用户SMTP认证的密码,而将在后面为用户建立SMTP认证专用的密码。
[root@sample ~]# vi /usr/lib/sasl2/smtpd.conf ← 编辑SMTP认证的配置文件
pwcheck_method: saslauthd ← 找到此行,将“saslauthd”改为“auxprop”
↓
pwcheck_method: auxprop ← 不使用系统用户密码作为用户的SMTP认证密码
[root@sample ~]# vi /etc/sysconfig/saslauthd
MECH=shadow ← 找到这一行,在前面加#
↓
#MECH=shadow ← 不使用shadow机制
FLAGS= ← 找到此行,在等号后面添加“sasldb”
↓
FLAGS=sasldb ← 定义认证方式为sasldb2
[3] 建立用户的邮箱目录
首先建立用户模板下的邮箱目录,以便于建立新用户时,相应用户的邮箱目录自动被建立。
[root@sample ~]# mkdir /etc/skel/Maildir ← 在用户模板下建立用户邮箱目录
[root@sample ~]# chmod 700 /etc/skel/Maildir ← 设置用户邮箱目录属性为700
然后再为已经存在的用户建立相应邮箱目录。
[root@sample ~]# mkdir /home/centospub/Maildir ← 为用户(这里以centospub用户为例)建立邮箱目录
[root@sample ~]# chmod 700 /home/centospub/Maildir ← 设置该用户邮箱目录属性为700
[root@sample ~]# chown centospub. /home/centospub/Maildir ← 设置该用户邮箱目录为该用户所有
[4] 为用户设置SMTP认证密码
[root@sample ~]# saslpasswd2 -u sample.centospub.com -c centospub ← 为centospub用户设置SMTP认证密码
Password: ← 在这里输入密码(不会显示)
Again (for verification): ← 再次输入密码
[5] 改变SALS的属性及归属
[root@sample ~]# chgrp postfix /etc/sasldb2 ← 将数据库归属改为postfix,
[root@sample ~]# chmod 640 /etc/sasldb2 ← 将数据库属性改为640
[6] 关闭sendmail服务及设置默认MTA
因为在用Postfix作为SMTP服务器的前提下,我们不准备再用sendmail,所以将sendmail服务关掉,以确保安全及节省系统资源。
[root@sample ~]# /etc/rc.d/init.d/sendmail stop ← 关闭sendmail服务
Shutting down sendmail: [ OK ]
Shutting down sm-client: [ OK ]
[root@sample ~]# chkconfig sendmail off ← 关闭sendmail自启动
[root@sample ~]# chkconfig –list sendmail ← 确认sendmail自启动已被关闭(都为off就OK)
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
然后再将默认的MTA设置为Postfix。
[root@sample ~]# alternatives –config mta ← 设置默认MTA
There are 2 programs which provide ‘mta’.
Selection Command
———————————————–
*+ 1 /usr/sbin/sendmail.sendmail ← 当前状态:sendmail为默认MTA
2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2 ← 在这里输入2,使Postfix成为默认MTA
启动相应服务
最后,启动SMTP认证及Postfix服务,并设置相应服务为自启动。
[root@sample ~]# chkconfig saslauthd on ← 将SMTP-Auth设置为自启动
[root@sample ~]# chkconfig –list saslauthd ← 确认SMTP-Auth服务状态
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
[root@sample ~]# /etc/rc.d/init.d/saslauthd start ← 启动SMTP-Auth
Starting saslauthd: [ OK ]
[root@sample ~]# chkconfig postfix on ← 将Postfix设置为自启动
[root@sample ~]# chkconfig –list postfix ← 确认Postfix服务状态
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2~5为on的状态就OK
[root@sample ~]# /etc/rc.d/init.d/postfix start ← 启动Postfix
Starting postfix: [ OK ]
至此,就完成了SMTP服务器方面的配置,但目前只具从备客户端通过服务器发送邮件的功能。做为完整的邮件服务器,还需具备从客户端通过POP/IMAP协议接受邮件到本地的功能。POP/IMAP服务器的构建请参见下一节 。
apt-get 使用指南
apt-get使用source.list文件进行软件包管理。如果您想了解关于如何编辑和更新source.list中的条目的信息,请参阅SourcesList
引言
“起初GNU/Linux系统中只有.tar.gz。用户必须自己编译他们想使用的每一个程序。在Debian出现之後,人们认为有必要在系统中添加一种机制用来管理安装在计算机上的软件包。人们将这套系统称为dpkg。至此着名的‘package’首次在GNU/Linux上出现。不久之後红帽子也开始着手建立自己的包管理系统 ‘rpm’。
“GNU/Linux的创造者们很快又陷入了新的窘境。他们希望通过一种快捷、实用而且高效的方式来安装软件包。这些软件包可以自动处理相互之间的依赖关系,并且在升级过程中维护他们的配置文件。Debian又一次充当了开路先锋的角色。她首创了APT(Advanced Packaging Tool)。这一工具後来被Conectiva 移植到红帽子系统中用于对rpm包的管理。在其他一些发行版中我们也能看到她的身影。”
* — 摘自 Debian APT HOWTO
“同时,apt是一个很完整和先进的软件包管理程序,使用它可以让你,又简单,又准确的找到你要的的软件包, 并且安装或卸载都很简洁。 它还可以让你的所有软件都更新到最新状态,而且也可以用来对ubuntu进行升级。”
“apt是需要用命令来操作的软件,不过现在也出现了很多有图形的软件,比如Synaptic, Kynaptic 和 Adept。”
命令
下面将要介绍的所有命令都需要sudo!使用时请将“packagename”和“string”替换成您想要安装或者查找的程序。
* apt-get update——在修改/etc/apt/sources.list或者/etc/apt/preferences之後运行该命令。此外您需要定期运行这一命令以确保您的软件包列表是最新的。
* apt-get install packagename——安装一个新软件包(参见下文的aptitude)
* apt-get remove packagename——卸载一个已安装的软件包(保留配置文件)
* apt-get –purge remove packagename——卸载一个已安装的软件包(删除配置文件)
* dpkg –force-all –purge packagename 有些软件很难卸载,而且还阻止了别的软件的应用,就可以用这个,不过有点冒险。
* apt-get autoclean apt会把已装或已卸的软件都备份在硬盘上,所以如果需要空间的话,可以让这个命令来删除你已经删掉的软件
* apt-get clean 这个命令会把安装的软件的备份也删除,不过这样不会影响软件的使用的。
* apt-get upgrade——更新所有已安装的软件包
* apt-get dist-upgrade——将系统升级到新版本
* apt-cache search string——在软件包列表中搜索字符串
* dpkg -l package-name-pattern——列出所有与模式相匹配的软件包。如果您不知道软件包的全名,您可以使用“*package-name-pattern*”。
* aptitude——详细查看已安装或可用的软件包。与apt-get类似,aptitude可以通过命令行方式调用,但仅限于某些命令——最常见的有安装和卸载命令。由于aptitude比apt-get了解更多信息,可以说它更适合用来进行安装和卸载。
* apt-cache showpkg pkgs——显示软件包信息。
* apt-cache dumpavail——打印可用软件包列表。
* apt-cache show pkgs——显示软件包记录,类似于dpkg –print-avail。
* apt-cache pkgnames——打印软件包列表中所有软件包的名称。
* dpkg -S file——这个文件属于哪个已安装软件包。
* dpkg -L package——列出软件包中的所有文件。
* apt-file search filename——查找包含特定文件的软件包(不一定是已安装的),这些文件的文件名中含有指定的字符串。apt-file是一个独立的软件包。您必须先使用apt-get install来安装它,然後运行apt-file update。如果apt-file search filename输出的内容太多,您可以尝试使用apt-file search filename | grep -w filename(只显示指定字符串作为完整的单词出现在其中的那些文件名)或者类似方法,例如:apt-file search filename | grep /bin/(只显示位于诸如/bin或/usr/bin这些文件夹中的文件,如果您要查找的是某个特定的执行文件的话,这样做是有帮助的)。
* apt-get autoclean——定期运行这个命令来清除那些已经卸载的软件包的.deb文件。通过这种方式,您可以释放大量的磁盘空间。如果您的需求十分迫切,可以使用apt-get clean以释放更多空间。这个命令会将已安装软件包裹的.deb文件一并删除。大多数情况下您不会再用到这些.debs文件,因此如果您为磁盘空间不足而感到焦头烂额,这个办法也许值得一试。
典型应用
我是个赛车发烧友,想装个赛车类游戏玩玩。有哪些赛车类游戏可供选择呢?
apt-cache search racing game
出来了一大堆结果。看看有没有更多关于torcs这个游戏的信息。
apt-cache show torcs
看上去不错。这个游戏是不是已经安装了?最新版本是多少?它属于哪一类软件,universe还是main?
apt-cache policy torcs
好吧,现在我要来安装它!
apt-get install torcs
在控制台下我应该调用什么命令来运行这个游戏呢?在这个例子中,直接用torcs就行了,但并不是每次都这么简单。我们可一通过查找哪些文件被安装到了 “/usr/bin”文件夹下来确定二进制文件名。对于游戏软件,这些二进制文件将被安装到“/usr/games”下面。对于系统管理工具相应的文件夹是“/usr/sbin”。
dpkg -L torcs|grep /usr/games/
这个命令的前面一部分显示软件包“torcs”安装的所有文件(您自己试试看)。通过命令的第二部分,我们告诉系统只显示前一部分的输出结果中含有“/usr/games”的那些行。
这个游戏很酷哦。说不定还有其他赛道可玩的?
apt-cache search torcs
我的磁盘空间不够用了。我得把apt的缓存空间清空才行。
apt-get clean
哦不,老妈叫我把机器上的所有游戏都删掉。但是我想把配置文件保留下来,这样待会我只要重装一下就可以继续玩了。
apt-get remove torcs
如果我想连配置文件一块删除:
apt-get remove –purge torcs
额外的软件包
deborphan和debfoster工具可以找出已经安装在系统上的不会被用到的软件包。
提高命令行方式下的工作效率
您可以通过定义别名(alias)来提高这些命令的输入速度。例如,您可以在您的*~/.bashrc*文件中添加下列内容
alias acs=’apt-cache search’
alias agu=’sudo apt-get update’
alias agg=’sudo apt-get upgrade’
alias agd=’sudo apt-get dist-upgrade’
alias agi=’sudo apt-get install’
alias agr=’sudo apt-get remove’
或者使用前面介绍的aptitude命令,如“alias agi=’sudo aptitude install’”。
为apt-get设置http代理
可以通过三种方法为apt-get设置http代理
方法一
这是一种临时的手段,如果您仅仅是暂时需要通过http代理使用apt-get,您可以使用这种方式。
在使用apt-get之前,在终端中输入以下命令(根据您的实际情况替换yourproxyaddress和proxyport)。
export http_proxy=http://yourproxyaddress:proxyport
方法二
这种方法要用到/etc/apt/文件夹下的apt.conf文件。如果您希望apt-get(而不是其他应用程序)一直使用http代理,您可以使用这种方式。
注意: 某些情况下,系统安装过程中没有建立apt配置文件。下面的操作将视情况修改现有的配置文件或者新建配置文件。
sudo gedit /etc/apt/apt.conf
在您的apt.conf文件中加入下面这行(根据你的实际情况替换yourproxyaddress和proxyport)。
Acquire::http::Proxy “http://yourproxyaddress:proxyport”;
保存apt.conf文件。
方法三
这种方法会在您的主目录下的.bashrc文件中添加两行。如果您希望apt-get和其他应用程序如wget等都使用http代理,您可以使用这种方式。
gedit ~/.bashrc
在您的.bashrc文件末尾添加如下内容(根据你的实际情况替换yourproxyaddress和proxyport)。
http_proxy=http://yourproxyaddress:proxyport
export http_proxy
保存文件。关闭当前终端,然後打开另一个终端。
使用apt-get update或者任何您想用的网络工具测试代理。我使用firestarter查看活动的网络连接。
如果您为了纠正错误而再次修改了配置文件,记得关闭终端并重新打开,否自新的设置不会生效。
ubuntu linux 一些转换工具
* wvWare: Converts to HTML and LaTeX. It’s used by a small army of
helper scripts able to preview Word documents and convert them to
various other formats, like PostScript, PDF, DVI, etc.
* wvRTF: Converts to Microsoft’s Rich Text Format.
* wvSummary: Displays the summary information stream of all OLE2 files,
i.e. Excel, PowerPoint, Visio, Access, etc.
* wvVersion: Outputs the version of the Word format a document is stored
in.
Note that conversion to DVI, PostScript, or PDF requires the tetex-extra
package; PDF conversion also requires Ghostscript. Having ELinks, Links,
or Lynx will greatly improve the plain text output. ImageMagick may help
with the quality of images. If you wish to preview Word documents from
the comfort of your mail reader, install a PostScript viewer like gv.
convert html to word
converts word processor files to HTML
Docvert is a web application which takes word processor files
(typically .doc) and converts them to OpenDocument and clean HTML.
The resulting OpenDocument is then optionally converted to HTML or
any XML. This is done with XML Pipelines, an approach that supports
XSLT, breaking up content over headings or sections, and saving those
results to multiple files (e.g., chapter1.html, chapter2.html, etc.).
The result is returned in a .zip file.
A command-line program which uses the web application is also included.
This package only supports OpenDocument. To convert other formats,
install docvert-openoffice.org.
Canonical 不为 docvert 提供更新。某些更新可能由 Ubuntu 社区提供。
HTML to PostScript converter
This program converts HTML directly to PostScript. The HTML code can be
retrieved from one or more URLs or local files, specified as parameters on the
command line. A comprehensive level of HTML is supported, including inline
images, CSS 1.0, and some features of HTML 4.0.
converts jpg images to ascii
Small utility that converts JPG images to ASCII using libjpeg.
jp2a is very flexible. It can use ANSI colors and html in output.
Screenshot: http://www.eriberto.pro.br/debian/screenshots/jp2a.jpg
Converts documents from LaTeX to RTF format
Attempts to convert as much formatting information as possible from
LaTeX to Microsoft’s Rich Text Format (RTF). While RTF has limited
support for mathematical markup, it is widely supported as a “least
common denominator” word processing format.
html2wiki
Text-to-HTML conversion tool
Markdown is a text-to-HTML conversion tool for web writers. It
allows you to write using an easy-to-read, easy-to-write plain text
format, then convert it to structurally valid XHTML (or HTML).
Mail to HTML converter
MHonArc is a Perl mail-to-HTML converter. MHonArc provides HTML mail
archiving with index, mail thread linking, etc; plus other capabilities
including support for MIME and powerful user customization features
bioinformatic functions for Octave
This package provides functions to do work in bioinformatics in
Octave, a numerical computation software. It contains functions to
convert amino acid characters into integers (aa2int), convert between
amino acid representations (aminolookup), cleave peptides (cleave),
convert integers into amino acid characters (int2aa) and reverse a
nucleotide sequence (seqreverse).
This Octave add-on package is part of the Octave-Forge project.
convert pfb into more compressible format and back
The package contains the two small tools pfb2t1c and t1c2pfb. pfb file
(PostScript Type1) can be converted into t1c and back without losing
information. The t1c files have the same size but are more compressible.
This feature is very useful when packaging PostScript Type1 fonts
ps module for PHP 5
ps is an extension similar to the pdf extension but for creating
PostScript files. Its api is modelled after the pdf extension.
It has some advanced features like taking kerning into account
and support for hyphenation. PostScript files can converted to
pdf files with ghostscript retaining hyperlinks and bookmarks.
Scientific plotting library (utilities)
This package contains the following utilities associated with PLplot,
a scientific plotting library:
* pltek – review a Tektronix vector file
* plm2gif – converts PLplot metafiles to GIF files
* plpr – converts PLplot metafile to something the printer will understand
PDF utilitites (based on libpoppler)
This package contains pdftops (PDF to PostScript converter), pdfinfo
(PDF document information extractor), pdfimages (PDF image extractor),
pdftohtml (PDF to HTML converter), pdftotext (PDF to text converter),
and pdffonts (PDF font analyzer).
convert PostScript to EPS (Encapsulated PostScript) files
ps2eps is a tool to produce Encapsulated PostScript Files (EPS/EPSF)
from usual one-paged Postscript documents. It calculates correct
Bounding Boxes for those EPS files and filters some special
postscript command sequences that can produce erroneous results on
printers. EPS files are needed for including (scalable) graphics
into TeX (or even Word) documents. Other programs like ps2epsi do
not calculate the bounding box always correctly (because the values are
put on the PostScript stack which may get corrupted by bad PostScript
code) or rounded it off so that clipping the EPS cut off some parts of
the image. Therefore ps2eps uses a resolution of 144 dpi to get the
correct bounding box.
Convert html and text documents to palm DOC format
Pyrite Publisher can convert a variety of input formats into several
different variations on the palm doc format.
This version includes support for a gui interface; see
/usr/share/doc/pyrite-publisher/README.GUI for details.
[Biology] Conversion between sequence formats
Reads and writes nucleic/protein sequences in various
formats. Data files may have multiple sequences.
Readseq is particularly useful as it automatically detects many
sequence formats, and converts between them.
converter between OpenOffice.org document formats
This package provides a commandline utility which can convert from
any document format that OpenOffice can import to any document format
it can export. It uses OpenOffice’s UNO bindings for non-interactive
conversion of documents.
Supported document formats include Open Document format, MS Word, MS
Office Open/MS OOXML, PDF, HTML, XHTML, RTF, Docbook, and more.
RTF to other formats converter
UnRTF is a moderately complicated converter from RTF to other
formats, including HTML, LaTeX, text, and PostScript. Converting
to HTML, it supports tables, fonts, colors, embedded images,
hyperlinks, paragraph alignment among other things. All other
conversions are “alpha”–just begun.
OpenOffice.org Writer/Calc to LaTeX/XHTML converter
Writer2LaTeX is a utility written in java. It converts OpenOffice.org
documents – in particular documents containing formulas – into other
formats. It is actually a collection of four converters, i.e.:
1) Writer2LaTeX converts documents into LaTeX 2e format for high quality
typesetting.
2) Writer2BibTeX extracts bibliographic data from a document and stores it in
BibTeX format (works together with Writer2LaTeX).
3) Writer2xhtml converts documents into XHTML 1.0 or XHTML 1.1+MathML 2.0 with
CSS2.
4) Calc2xhtml is a companion to Writer2xhtml that converts OOo Calc documents
to XHTML 1.0 with CSS2 to display your spreadsheets on the web.
HTML to PostScript converter (Tcl/Tk GUI frontend)
This program converts HTML directly to PostScript. The HTML code can be
retrieved from one or more URLs or local files, specified as parameters on the
command line. A comprehensive level of HTML is supported, including inline
images, CSS 1.0, and some features of HTML 4.0.
A program for converting Microsoft Excel Files .xls
The xlhtml program will take an Excel 95, or 97 file as input and
convert it to highly optimized html. The output is via standard out
so it can be re-directed to files or piped to filters or used as a
gateway on the internet.
Chinese HZ/GB/BIG5/UNI/UTF7/UTF8 encodings auto-converter
AutoConvert is an intelligent Chinese Encoding converter. It uses
builtin functions to judge the type of the input file’s Chinese
Encoding (such as GB/Big5/HZ), then converts the input file to any
type of Chinese Encoding you want. You can use autoconvert to handle
incoming mail, automatically converting messages to the Chinese
Encoding you want.
It can alse handle Unicode/UTF7/UTF8 now.
Author: Yu Guanghui
linux 常用软件搜索
linux 常用软件搜索
http://bingle.pku.edu.cn 北大天网ftp搜索,教育网和国内用户查找软件应首先访问,软件特别丰富
http://www.linuxforum.net/ 有很多国外软件的官方镜像,应首先访问
http://rpmfind.net
http://freshmeat.net
http://sourceforge.net
注:很多软件主站是在sourceforge上的,形如http://phpmyadmin.sourceforge.net的地址,可以通过 http://sourceforge.net/projects/phpmyadmin这样的地址访问,如不能上也可用http镜象直接下载软件如 http://telia.dl.sourceforge.net/phpmyadmin/
http://www.gnu.org GNU的大本营,gcc,bash之类的软件源码可以到这里得到 linux 文档和FAQs
http://www.tldp.org 强烈推荐! The linux document project: linux HOWTO and guides
http://www.linux.org.tw/CLDP/ 强烈推荐! TLDP中文版,繁体
http://www.linuxgazette.com/ linux在线杂志
http://linux.tcpip.com.cn/download/ linux中文版文档和软件下载
http://cosoft.org.cn/html/documents/ 很多中文版手册
gnuplot
对于在Linux下工作的人,如果你经常要画一些二维图和简单的三维图的话,那么,gnuplot 无疑是一个非常好的选择,不仅图形漂亮,而且操作简单。当然如果需要质量更高的三维图,请用其他的一些专业绘图软件。建议大家学会使用gnuplot。这个小软件通常都是Redhat Linux自带的,但自带的版本是3.7的,建议将其升级到4.0,新版本具有很多新功能。最新版本可以到 http://www.gnuplot.info下载。
一些最基本的操作请大家看说明书。这里总结一下我在使用过程中遇到的一些问题以及解决的办法,目的是让那些以前不会的或不熟练的能快速入门,会画自己想要的图,因为原来的说明书很长,较难有针对性地很快找到自己想要的信息。这里简单的总结不可能面面俱到,所以大家不要抱怨我写的不全,更全面的了解还是请看说明书,网上的资料也多的是。其实这也是我们从网上一点一点搜集和摸索出来的。我相信看完后,应该平时最常见的问题基本上都能在这里找到答案。如果大家在使用过程中摸索到了我没有写到的技巧和体会,或有其它建议,请大家提告诉我,以不断完善这篇总结,谢谢!
一、 基础篇:
在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出。
1、plot命令
gnuplot> plot sin(x) with line linetype 3 linewidth 2 或
gnuplot> plot sin(x) w l lt 3 lw 2 %用线画,线的类型(包括颜色与虚线的类型)是3,线的宽度是2,对函数sin(x)作图
gnuplot> plot sin(x) with point pointtype 3 pointsize 2 或
gnuplot> plot sin(x) w p pt 3 ps 2 %用点画,点的类型(包括颜色与点的类型)是3,点的大小是2
gnuplot> plot sin(x) title ‘f(x)’ w lp lt 3 lw 2 pt 3 ps 2 %同时用点和线画,这里title ‘f(x)’表示图例上标’f(x)’,如果不用则用默认选项
gnuplot> plot sin(x) %此时所有选项均用默认值。如果缺某一项则将用默认值
gnuplot> plot ‘a.dat’ u 2:3 w l lt 3 lw 2 %利用数据文件a.dat中的第二和第三列作图
顺便提一下,如这里最前面的两个例子所示,在gnuplot中,如果某两个词,按字母先后顺序,前面某几个字母相同,后面的不同,那么只要写到第一个不同的字母就可以了。如with,由于没有其它以w开头的词,因此可以用 w 代替,line也可以用 l 代替。
2、同时画多条曲线
gnuplot> plot sin(x) title ‘sin(x)’ w l lt 1 lw 2, cos(x) title ‘cos(x)’ w l lt 2 lw 2 %两条曲线是用逗号隔开的。画多条曲线时,各曲线间均用逗号隔开就可以了。
以上例子中是对函数作图,如果对数据文件作图,将函数名称换为数据文件名即可,但要用单引号引起来。
3、关于图例的位置
默认位置在右上方。
gnuplot> set key left %放在左边,有left 和right两个选项
gnuplot> set key bottom %放在下边,只有这一个选项;默认在上边
gnuplot> set key outside %放在外边,但只能在右面的外边
以上三个选项可以进行组合。如:
gnuplot> set key left bottom %表示左下边
还可以直接用坐标精确表示图例的位置,如
gnuplot> set key 0.5,0.6 %将图例放在0.5,0.6的位置处
4、关于坐标轴
gnuplot> set xlabel ‘x’ %x轴标为‘x’
gnuplot> set ylabel ‘y’ %y轴标为’y’
gnuplot> set ylabel ‘DOS’ tc lt 3 %其中的tc lt 3表示’DOS’的颜色用第三种颜色。
gnuplot> set xtics 1.0 %x轴的主刻度的宽度为1.0,同样可以为y轴定义ytics
gnuplot> set mxtics 3 %x轴上每个主刻度中画3个分刻度,同样可以为y轴定义mytics
gnuplot> set border 3 lt 3 lw 2 %设为第三种边界,颜色类型为3,线宽为2
同样可以为上边的x轴(称为x2)和右边y(称为y2)轴进行设置,即x2tics,mx2tics,y2tics,my2tics。
gnuplot> set xtics nomirror
gnuplot> unset x2tics %以上两条命令去掉上边x2轴的刻度
gnuplot> set ytics nomirror
gnuplot> unset y2tics %以上两条命令去掉右边y轴的刻度
5、在图中插入文字
gnuplot> set label ‘sin(x)’ at 0.5,0.5 %在坐标(0.5,0.5)处加入字符串’sin(x)’。
在输出为.ps或.eps文件时,如果在set term 的语句中加入了enhanced选现,则可以插入上下标、希腊字母和特殊符号。上下标的插入和latex中的方法是一样的。
6、在图中添加直线和箭头
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 %从(0.0,0.0)到(0.6,0.8)画一个箭头
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 lt 3 lw 2 %这个箭头颜色类型为3,线宽类型为2
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 nohead lt 3 lw 2 %利用nohead可以去掉箭头的头部,这就是添加直线的方法。
注意,在gnuplot中,对于插入多个的label和arrow等等,系统会默认按先后顺序分别对各个label或arrow进行编号,从1开始。如果以后要去掉某个label或arrow,那么只要用unset命令将相应的去掉即可。如:
gnuplot> unset arrow 2
将去掉第二个箭头。
7、图的大小和位置
gnuplot>set size 0.5,0.5 %长宽均为默认宽度的一半,建议用这个取值,尤其是画成ps或eps图形的时候
gnuplot>set origin 0.0,0.5 %设定图的最左下角的那一点在图形面板中的位置。这里图将出现在左上角。
8、画三维图
gnuplot>splot ‘文件名’ u 2:4:5 %以第二和第四列作为x和y坐标,第五列为z坐标。
二、提高篇:
1、如何在同一张图里同时画多个图
gnuplot>set multiplot %设置为多图模式
gnuplot>set origin 0.0,0.0 %设置第一个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第一个图的大小
gnuplot>plot “a1.dat”
gnuplot>set origin 0.0,0.5 %设置第二个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第二个图的大小
gnuplot>plot “a2.dat”
gnuplot>set origin 0.0,0.0 %设置第三个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第三个图的大小
gnuplot>plot “a3.dat”
gnuplot>set origin 0.0,0.0 %设置第四个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第四个图的大小
gnuplot>plot “a4.dat”
当然,如果后一个图中的某个量的设置和前一个的相同,那么后一个中的这个量的设置可以省略。例如上面对第二、第三和第四个图的大小的设置。前一个图中对某个量的设置也会在后一个图中起作用。如果要取消在后面图中的作用,必须用如下命令,如取消label,用
gnuplot>unset label
2、作二维图时,如何使两边坐标轴的单位长度等长
gnuplot> set size square %使图形是方的
gnuplot> set size 0.5,0.5 %使图形是你要的大小
gnuplot> set xrange[-a:a]
gnuplot> set yrange[-a:a] %两坐标轴刻度范围一样
gnuplot> plot ‘a.dat’
3、如何在同一张图里利用左右两边的y轴分别画图
gnuplot> set xtics nomirror %去掉上面坐标轴x2的刻度
gnuplot> set ytics nomirror %去掉右边坐标轴y2的刻度
gnuplot> set x2tics %让上面坐标轴x2刻度自动产生
gnuplot> set y2tics %让右边坐标轴y2的刻度自动产生
gnuplot> plot sin(x),cos(x) axes x1y2 %cos(x)用x1y2坐标,axes x1y2表示用x1y2坐标轴
gnuplot> plot sin(x),cos(x) axes x2y2 %cos(x)用x2y2坐标,axes x2y2表示用x2y2坐标轴
gnuplot> set x2range[-20:20] %设定x2坐标的范围
gnuplot> replot
gnuplot> set xrange[-5:5] %设定x坐标的范围
gnuplot> replot
gnuplot> set xlabel ‘x’
gnuplot> set x2label ‘t’
gnuplot> set ylabel ‘y’
gnuplot> set y2label ’s’
gnuplot> replot
gnuplot> set title ‘The figure’
gnuplot> replot
gnuplot> set x2label ‘t’ textcolor lt 3 %textcolor lt 3或tc lt 3设置坐标轴名称的颜色
4、如何插入希腊字母和特殊符号
一般只能在ps和eps图中,且必须指定enhanced选项。在X11终端(即显示器)中无法显示。
gnuplot> set terminal postscript enhanced
然后希腊字母就可以通过{/Symbol a}输入。例如
gnuplot> set label ‘{/Symbol a}’
各种希腊字母与特殊符号的输入方法请见安装包中gnuplot-4.0.0/docs/psdoc目录下的ps_guide.ps文件。
另外还可参见:
http://t16web.lanl.gov/Kawano/gnuplot/label-e.html#4.3
5、gnuplot中如何插入Angstrom(埃)这个符号(A上面一个小圆圈)
脚本中在插入前先加入
gnuplot>set encoding iso_8859_1
这个命令,然后就可以通过“{305}”加入了。如横坐标要标上“k(1/Å)”:
gnuplot>set xlabel ‘k(1/{305})
如果是multiplot模式,则这个命令必须放在
gnuplot>set multiplot
的前面。
如果后面还要插入别的转义字符,那么还要在插入字符后加入如下命令:
set encoding default
安装包中gnuplot-4.0.0/docs/psdoc/ps_guide.ps文件中的表中的‘E’代表那一列的所有符号都用这个方法输入。
6、gnuplot画等高线图
gnuplot>splot ‘文件名.dat’ u 1:2:3 w l %做三维图
gnuplot>set dgrid3d 100,100 %设置三维图表面的网格的数目
gnuplot>replot
gnuplot>set contour %设置画等高线
gnuplot>set cntrparam levels incremental -0.2,0.01,0.2 %设置等高线的疏密和范围,数据从 -0.2到0.2中间每隔0.01画一条线
gnuplot>unset surface 去掉上面的三维图形
最后用鼠标拽动图形,选择合理的角度即可。或者直接设置(0,0)的视角也可以:
gnuplot>set view 0,0
gnuplot>replot
这里注意,画三维图的数据文件必须是分块的,也就是x每变换一个值,y在其变化范围内变化一周,这样作为一块,然后再取一个x值,y再变化一周,作为下一数据块,等等。块与块之间用一空行格开。
7、输出为ps或eps图时,以下几个选项值得特别注意
gnuplot>set term postscript eps enh solid color
其中eps选项表示输出为eps格式,去掉则表示用默认的ps格式;enh选项表示图中可以插入上下标、希腊字母及其它特殊符号,如果去掉则不能插入;solid选项表示图中所有的曲线都用实线,去掉则将用不同的虚线;color选项表示在图中全部曲线用彩色,去掉则将用黑白。
8、如何画漂亮的pm3d图
gnuplot> set pm3d %设置pm3d模式
gnuplot> set isosamples 50,50 %设置网格点
gnuplot> splot x**2+y**2 %画三维图
gnuplot> splot x**2+y**2 w pm3d %画成pm3d模式,注意比较变化
gnuplot> set view 0,0 %设置视角,(0,0)将投影到底面上去
gnuplot> splot x**2+y**2 w pm3d %重画,注意看变化
gnuplot> unset ztics %把z轴上的数字给去掉
gnuplot> set isosamples 200,200 %使网格变细
gnuplot> replot %重画,注意看变化,主要是过渡更光滑
9、利用脚本文件避免重复输入
有时候对某个数据文件做好一张图后,下次可能还要利用这个数据文件作图,但某个或某些设置要作些细微变化。这时候,可以把第一次作图时的命令全部写到一个文件里,如a.plt,下次只要将相应的设置做修改后,用下面的命令就会自动运行文件所有的命令而最后得到你要的图:
gnuplot>load ‘a.plt’
作为一个例子,假设文件名为a.plt,里面的内容为:
set pm3d
set view 0,0
unset ztics
set isosamples 200,200
splot x**2+y**2 w pm3d
set term post color
set output ‘a.ps’
replot
那么启动gnuplot后,只要运行如下命令就可以了:
gnuplot>load ‘a.plt’
如果我们要得到的仅仅是.ps或.eps图,那也可以在linux命令提示符下直接运行如下命令:
[zxh@theory zxh]$gnuplot a.plt
10、在gnuplot模式下运行linux命令
在gnuplot提示符下也可以运行linux命令,但必须在相应的命令前面加上 ! 号。例如,假设很多参量都已经设置好了,但需要对某个数据文件a.dat进行修改后再画图,则可以用如下方式
gnuplot>!vi a.dat
通过这种方式,所有的linux命令都可以在gnuplot环境里运行。
另外,也可以在gnuplot的提示符后输入shell,暂时性退出gnuplot,进入linux环境,做完要做的事情后,运行exit命令,又回到gnuplot环境下。
gnuplot>shell
[zxh@theory zxh]$vi a.f
[zxh@theory zxh]$f77 a.f
[zxh@theory zxh]$a.out (假设生成a.dat数据文件)
[zxh@theory zxh]$exit
gnuplot>plot ‘a.dat’ w l
文档格式批量转换(doc,txt,pdf等)
在Linux中常常涉及到多种文档格式,如doc、txt、html、rtf等等。为了方便文件传递,就可能需要在各种格式之间进行转换。OpenOffice.Org可以方便的打开多各文档格式并按需进行转换,但要一次处理大量文件或要编写脚本进行转换时,仅用OpenOffice就难以胜任了。
unoconv利用OpenOffice.Org的UNO接口实现了命令行文档格式转换功能,支持所有OpenOffice支持的文件格式,为文档的批量转换提供了可能。
目录
[隐藏]
* 1 下载及安装
* 2 使用方法
o 2.1 单个文件转换
o 2.2 批量转换
* 3 其它功能简介
o 3.1 支持的文件格式
o 3.2 服务器/客户端模式
* 4 附:支持的输出文件格式
* 5 相关资料
下载及安装
目前Debian的源已经有unoconv,如果你使用的发行版还没有unoconv,可以到它的主页下载: http://dag.wieers.com/home-made/unoconv/ 。
注意:
该软件依赖于OpenOffice.Org。
使用方法
单个文件转换
举一个例子:要转换一个doc文件为PDF格式,只需在命令中执行:
$ unoconv -f pdf myDoc.doc
即会生成一个名为myDoc.pdf的pdf文件。
批量转换
批量转换需要结合find命令或脚本使用,使用时需注意最好使用C/S模式以加快速度:
unoconv –listener &
unoconv -f pdf some-document.odt
unoconv -f doc other-document.odt
unoconv -f jpg some-image.png
unoconv -f xsl some-spreadsheet.csv
其它功能简介
支持的文件格式
可以执行unoconv –show查看截止到2008年3月11日,unoconv支持以下几种导出格式(见本文末尾)[1]
服务器/客户端模式
此模式使文档的集中处理成为可能。
附:支持的输出文件格式
bib – BibTeX [.bib]
doc – Microsoft Word 97/2000/XP [.doc]
doc6 – Microsoft Word 6.0 [.doc]
doc95 – Microsoft Word 95 [.doc]
docbook – DocBook [.xml]
html – HTML Document (OpenOffice.org Writer) [.html]
odt – Open Document Text [.odt]
ott – Open Document Text [.ott]
ooxml – Microsoft Office Open XML [.xml]
pdb – AportisDoc (Palm) [.pdb]
pdf – Portable Document Format [.pdf]
psw – Pocket Word [.psw]
rtf – Rich Text Format [.rtf]
latex – LaTeX 2e [.ltx]
sdw – StarWriter 5.0 [.sdw]
sdw4 – StarWriter 4.0 [.sdw]
sdw3 – StarWriter 3.0 [.sdw]
stw – Open Office.org 1.0 Text Document Template [.stw]
sxw – Open Office.org 1.0 Text Document [.sxw]
text – Text Encoded [.txt]
txt – Plain Text [.txt]
vor – StarWriter 5.0 Template [.vor]
vor4 – StarWriter 4.0 Template [.vor]
vor3 – StarWriter 3.0 Template [.vor]
xhtml – XHTML Document [.html]
图形格式:
bmp – Windows Bitmap [.bmp]
emf – Enhanced Metafile [.emf]
eps – Encapsulated PostScript [.eps]
gif – Graphics Interchange Format [.gif]
html – HTML Document (OpenOffice.org Draw) [.html]
jpg – Joint Photographic Experts Group [.jpg]
met – OS/2 Metafile [.met]
odd – OpenDocument Drawing [.odd]
otg – OpenDocument Drawing Template [.otg]
pbm – Portable Bitmap [.pbm]
pct – Mac Pict [.pct]
pdf – Portable Document Format [.pdf]
pgm – Portable Graymap [.pgm]
png – Portable Network Graphic [.png]
ppm – Portable Pixelmap [.ppm]
ras – Sun Raster Image [.ras]
std – OpenOffice.org 1.0 Drawing Template [.std]
svg – Scalable Vector Graphics [.svg]
svm – StarView Metafile [.svm]
swf – Macromedia Flash (SWF) [.swf]
sxd – OpenOffice.org 1.0 Drawing [.sxd]
sxd3 – StarDraw 3.0 [.sxd]
sxd5 – StarDraw 5.0 [.sxd]
tiff – Tagged Image File Format [.tiff]
vor – StarDraw 5.0 Template [.vor]
vor3 – StarDraw 3.0 Template [.vor]
wmf – Windows Metafile [.wmf]
xhtml – XHTML [.xhtml]
xpm – X PixMap [.xpm]
演示文稿:
bmp – Windows Bitmap [.bmp]
emf – Enhanced Metafile [.emf]
eps – Encapsulated PostScript [.eps]
gif – Graphics Interchange Format [.gif]
html – HTML Document (OpenOffice.org Impress) [.html]
jpg – Joint Photographic Experts Group [.jpg]
met – OS/2 Metafile [.met]
odd – OpenDocument Drawing (Impress) [.odd]
odg – OpenOffice.org 1.0 Drawing (OpenOffice.org Impress) [.odg]
odp – OpenDocument Presentation [.odp]
otp – OpenDocument Presentation Template [.otp]
pbm – Portable Bitmap [.pbm]
pct – Mac Pict [.pct]
pdf – Portable Document Format [.pdf]
pgm – Portable Graymap [.pgm]
png – Portable Network Graphic [.png]
pot – Microsoft PowerPoint 97/2000/XP Template [.pot]
ppm – Portable Pixelmap [.ppm]
ppt – Microsoft PowerPoint 97/2000/XP [.ppt]
pwp – PlaceWare [.pwp]
ras – Sun Raster Image [.ras]
sda – StarDraw 5.0 (OpenOffice.org Impress) [.sda]
sdd – StarImpress 5.0 [.sdd]
sdd3 – StarDraw 3.0 (OpenOffice.org Impress) [.sdd]
sdd4 – StarImpress 4.0 [.sdd]
sti – OpenOffice.org 1.0 Presentation Template [.sti]
stp – OpenDocument Presentation Template [.stp]
svg – Scalable Vector Graphics [.svg]
svm – StarView Metafile [.svm]
swf – Macromedia Flash (SWF) [.swf]
sxi – OpenOffice.org 1.0 Presentation [.sxi]
tiff – Tagged Image File Format [.tiff]
vor – StarImpress 5.0 Template [.vor]
vor3 – StarDraw 3.0 Template (OpenOffice.org Impress) [.vor]
vor4 – StarImpress 4.0 Template [.vor]
vor5 – StarDraw 5.0 Template (OpenOffice.org Impress) [.vor]
wmf – Windows Metafile [.wmf]
xhtml – XHTML [.xml]
xpm – X PixMap [.xpm]
电子表格:
csv – Text CSV [.csv]
dbf – dBase [.dbf]
dif – Data Interchange Format [.dif]
html – HTML Document (OpenOffice.org Calc) [.html]
ods – Open Document Spreadsheet [.ods]
ooxml – Microsoft Excel 2003 XML [.xml]
pdf – Portable Document Format [.pdf]
pts – OpenDocument Spreadsheet Template [.pts]
pxl – Pocket Excel [.pxl]
sdc – StarCalc 5.0 [.sdc]
sdc4 – StarCalc 4.0 [.sdc]
sdc3 – StarCalc 3.0 [.sdc]
slk – SYLK [.slk]
stc – OpenOffice.org 1.0 Spreadsheet Template [.stc]
sxc – OpenOffice.org 1.0 Spreadsheet [.sxc]
vor3 – StarCalc 3.0 Template [.vor]
vor4 – StarCalc 4.0 Template [.vor]
vor – StarCalc 5.0 Template [.vor]
xhtml – XHTML [.xhtml]
xls – Microsoft Excel 97/2000/XP [.xls]
xls5 – Microsoft Excel 5.0 [.xls]
xls95 – Microsoft Excel 95 [.xls]
xlt – Microsoft Excel 97/2000/XP Template [.xlt]
xlt5 – Microsoft Excel 5.0 Template [.xlt]
xlt95 – Microsoft Excel 95 Template [.xlt]
Linux curl使用简单介绍
Curl是Linux下一个很强大的http命令行工具,其功能十分强大。
1) 二话不说,先从这里开始吧!
$ curl http://www.linuxidc.com
回车之后,www.linuxidc.com 的html就稀里哗啦地显示在屏幕上了 ~
2) 嗯,要想把读过来页面存下来,是不是要这样呢?
$ curl http://www.linuxidc.com > page.html
当然可以,但不用这么麻烦的!
用curl的内置option就好,存下http的结果,用这个option: -o
$ curl -o page.html http://www.linuxidc.com
这样,你就可以看到屏幕上出现一个下载页面进度指示。等进展到100%,自然就 OK咯
3) 什么什么?!访问不到?肯定是你的proxy没有设定了。
使用curl的时候,用这个option可以指定http访问所使用的proxy服务器及其端口: -x
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com
4) 访问有些网站的时候比较讨厌,他使用cookie来记录session信息。
像IE/NN这样的浏览器,当然可以轻易处理cookie信息,但我们的curl呢?…..
我们来学习这个option: -D 下载后: 001-zzh.JPG 原来: ~nick/001.JPG —-> 下载后: 001-nick.JPG
这样一来,就不怕文件重名啦,呵呵
9)继续讲下载
我们平时在windows平台上,flashget这样的工具可以帮我们分块并行下载,还可以断线续传。curl在这些方面也不输给谁,嘿嘿
比如我们下载screen1.JPG中,突然掉线了,我们就可以这样开始续传
$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG
当然,你不要拿个flashget下载了一半的文件来糊弄我 别的下载软件的半截文件可不一定能用哦 ~
分块下载,我们使用这个option就可以了: -r
举例说明
比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 要下载(赵老师的电话朗诵
)我们就可以用这样的命令:
$ curl -r 0-10240 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 10241-20480 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 20481-40960 -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 &\
$ curl -r 40961- -o “zhao.part1″ http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3
这样就可以分块下载啦。不过你需要自己把这些破碎的文件合并起来如果你用UNIX或苹果,用 cat zhao.part* > zhao.MP3就可以如果用的是Windows,用copy /b 来解决吧,呵呵
上面讲的都是http协议的下载,其实ftp也一样可以用。用法嘛,
$ curl -u name:passwd ftp://ip:port/path/file
或者大家熟悉的
$ curl ftp://name:passwd@ip:port/path/file
10) 说完了下载,接下来自然该讲上传咯上传的option是 -T
比如我们向ftp传一个文件:
$ curl -T localfile -u name:passwd ftp://upload_site:port/path/
当然,向http服务器上传文件也可以比如
$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
注意,这时候,使用的协议是HTTP的PUT method
刚才说到PUT,嘿嘿,自然让老服想起来了其他几种methos还没讲呢! GET和POST都不能忘哦。
http提交一个表单,比较常用的是POST模式和GET模式
GET模式什么option都不用,只需要把变量写在url里面就可以了比如:
$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345
而POST模式的option则是 -d
比如,
$ curl -d “user=nickwolfe&password=12345″ http://www.linuxidc.com/login.cgi
就相当于向这个站点发出一次登陆申请 ~
到底该用GET模式还是POST模式,要看对面服务器的程序设定。
一点需要注意的是,POST模式下的文件上的文件上传,比如
这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:
$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
罗罗嗦嗦讲了这么多,其实curl还有很多很多技巧和用法比如 https的时候使用本地证书,就可以这样
$ curl -E localcert.pem https://remote_server
再比如,你还可以用curl通过dict协议去查字典 ~
$ curl dict://dict.org/d:computer
lynx -dump 得到文本模式
html2text html 转到文本
HTMLDOC 转成pdf
ImageMagick
1.生成縮圖
a.指定大小
# convert -sample 80x40 input.jpg output.jpg
b.利用比例
# convert -sample 25%x25% input.jpg output.jpg
2.旋轉圖形
利用cotate參數,+90表順時針旋轉90度,而-90則表逆時針轉90度
# convert -rotate 90 input.jpg output.jpg
3.轉換格式
以附檔名為準,如下例就是將jpg轉換成png的用法
# convert input.jpg output.png
4.一次使用多種命令
# convert -sample 25%x25% -spread 4 \ -charcoal 4 input.jpg output.jpg
LAMP(Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server) 安装
LAMP(Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server) 安装
在新立得软件包管理器中选择 编辑--使用任务分组标记软件包
在打开的窗口中, 勾选 LAMP SERVER 然后确定
phpmyadmin 默认并不是安装在/var/www下面的,而是在/usr/share/phpmyadmin,你可以 把phpmyadmin复制过去,或者,网上有人说可以创建一个链接,然后把链接复制过去
sudo ln -s /usr/share/phpmyadmin /var/www/
在浏览器输入地址:http://localhost/phpmyadmin/
perl
sudo apt-get install libapache2-mod-perl2
/var/www 下面创建一个cgi-bin的文件夹:perl文件如下(1.pl)
#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print “Hello, World.”;
http://localhost/cgi-bin/1.pl
sudo /etc/init.d/apache2 restart
/etc/apache2/apache2.conf
/etc/apache2/sites-available/default
ps:ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory “/usr/lib/cgi-bin”>
To this:
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory “/var/www/cgi-bin”>
把编译好的primer3_core放到cgi-bin的文件夹下,并把primer3_results.cgi,primer3_www_results.cgi 中的/bin/nice
-19 ./primer3_core -format_output -strict_tags 改成/usr/bin/nice -19 ./primer3_core -format_output -strict_tags
sudo /etc/init.d/apache2 restart
ubuntu启动中添加脚本
今天为服务器配置双网卡的时候,需要配置路由.因为路由是用命令添加的,所以每次关机或重起系统,路由就丢失了.于是想到每次重起的时候执行一段脚本用来添加路由,这样我就不用每次重起都手动添加了.
以下用添加路由为例.
我想在系统启动时执行:
sudo route add -net 10.35.0.0/24 gw 10.35.0.254 dev eth0
sudo route add -net 10.35.51.0/24 gw 10.35.0.254 dev eth0
sudo route add -net 10.35.60.0/24 gw 10.35.0.254 dev eth0
1.首先,我们创建一个 /etc/network.script 文件.输入命令:
sudo nano /etc/network.script
2.接着我们在文本编辑器中输入我们要执行的命令.如上面的:
sudo route add -net 10.35.0.0/24 gw 10.35.0.254 dev eth0
sudo route add -net 10.35.51.0/24 gw 10.35.0.254 dev eth0
sudo route add -net 10.35.60.0/24 gw 10.35.0.254 dev eth0
3.按 Ctrl + O 保存文件,然后按 Ctrl + X 退出.
4.接着我们再用 nano 打开 /etc/rc.local .输入命令:
sudo nano /etc/rc.local
5.在文本编辑中,我们会看到提示说 /etc/rc.local 默认是空的.但我打开的时候,会看到里面其它有一行:
exit 0
如果是这样,我们一定要在 exit 0 之前输入我们要执行的脚本文件.如下:
sh /etc/network.script
exit 0
在ubuntu系统中,系统启动项目放置在/etc/rcS.d,/etc/rc0.d,/etc/rc1.d,/etc/rc2.d, /etc/rc3.d,/etc/rc4.d,/etc/rc5.d这几个文件夹下。其中的rcS.d文件夹是系统最先启动的内容,然后根据系统运行级别 运行对应的rcx.d文件夹内的脚本文件。
在linux系统内,一般运行于3,如果运行X系统则是5。
在rcX.d系列文件夹内,脚本其实是链接,真正的脚本文件存放在/etc/init.d文件夹下。在rcX.d系列文件夹内的脚本链接名字,以K开头的 是传递stop参数用来停止相应的服务(kill),以S开头传递start参数用来启动相应的服务。K或者S后面的数字决定了这个脚本运行的先后顺序, 数字越大运行次序越靠后。
用户添加的一般启动项放在/etc/rc.local文件内。据某些资料说这个文件也是个链接,真正的文件放在/etc/init.d/rc.local文件内。不过我看到的好像不是这样的。/etc/rc.local就是单独的文件。
在ubuntu系统内,提供了rcconf程序和sysv-rc-conf程序用来帮助用户增加删除和调整启动项。比自己直接编辑rc.local文件要方便的多。
