Ubuntu的使用

最近要用Ubuntu,以前用SUSE的经验貌似很少能用在这里, Ubuntu版本:10.10,内核2.6.35.24(由老内核2.6.35.22升级而来) 发这篇blog记录一下用法,顺便赞一下Ubuntu,偶笔记本的无线网卡终于可以干活了。 以下内容均为网上Google来,并经过测试,留存在这里,方便以后查找

1、ubuntu下使用alias

把 alias 语句写入 ~/.bashrc中即可方便使用。 命令:sudo vi ~/.bashrc进入即可,编辑了 ~/.bashrc 后, 使用 source ~/.bashrc 即可让它立刻生效。

bashrc文件中有这么一段说明,貌似是将所有的alias可以定义在一个叫做.bash_aliases的文件中:

1
2
3
4
5
6
7
8
9
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

这个功能不错,把自己常用的alias定义保存后,直接复制,以后到哪里都能用了。 附上几个自己用的alias:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# some more ls aliases

alias ll='ls -aluhp'
alias lt='ls -alFrSht'
alias lf='ls -alFrSh'
alias cd..='cd ..'
alias alg='arm-linux-gcc'
alias alr='arm-linux-readelf'
alias agi='apt-get install'
alias agg='apt-get'

#该命令是直接进入ftp文件夹,并列出该文件夹下的内容

alias g2ftp='cd /usr/local/arm/exports/ftp && ll'

#该命令将复制文件到指定的目录,这里是ftp目录
#用法 "c2ftp 文件名"即可

cp2ftp()
{
  cp $1 /usr/local/arm/exports/ftp/
}
alias c2ftp=cp2ftp
alias lsftp='ls /usr/local/arm/exports/ftp'
alias llftp='ll /usr/local/arm/exports/ftp'
alias duu='du -h --max-depth=1'
alias ecpath='echo $PATH'
alias g2armRoot='cd /usr/local/arm/exports/export'
alias aqmake='/opt/qte-4.7.1/bin/qmake'
alias g2src='cd/usr/local/arm/source/'

alias en1='export LANG="en_US:UTF-8"'
alias en2='export LANGUAGE="en_US:en"'
alias tree='tree -N'
alias ags='apt-cache search'
alias netreboot='/etc/init.d/networking restart'
alias ftpreboot='service proftpd restart'
alias wwwreboot='service apache2 restart'

# ffstr :Find File with String of..
# 在当前路径下搜索包含指定字符串的文件,并显示
# grep 参数-n:列出行号,-i:不区分大小写

alias ffstr='find . -type f -print | xargs grep -n -i'

7zaa()
{
7z a $1.7z $1
}
# 7z压缩
alias 7za='7zaa'
# 7z 将目录下所有文件和目录分别压缩
alias 7zz='for ITEM in `ls`; do 7za $ITEM ; done'
alias aip='arping -A 10.3.89.122 -I eth0'

2、安装ssh服务器

在“系统”->“系统管理”->“更新管理器”中,点击“设置”,并选中“Ubuntu软件”,将“下载自”一栏选择为“主服务器”,先修改更新服务器地址(默认安装的澳洲服务器挂了)。 然后就很简单了,使用apt-get install ssh安装吧.安装完成之后,ps -e|grep ssh,一定要看到sshd的进程,这就说明ssh服务器装好了,然后就很简单,可以使用putty的ssh登录搞了,

3、安装cross-4.2.2

这个很easy,就是下载之后解压,命令式tar jxvf cross-4.2.2-eabi.tar.bz2 -C /usr/local/armcross-4.2.2-eabi.tar.bz2 下载地址:这里,安装说明:这里 (用Google直接搜索cross-4.2.2-eabi,直接出来的第一第二个就是上面两个链接)

2012年7月28日更新: 今天遇到一个奇怪的问题: 运行编译器出错,arm-linux-gcc: 没有这个文件或者目录。Google了一下,发现了这个解决方法:apt-get install lsb-core解决,原文地址在这里。 仔细思考了一下,以前的都是32位系统,没出现这个问题,现在是64位,估计缺少依赖库。

4、Ubuntu 架設nfs server

  1. Install

    1
    2
    $ sudo apt-get install nfs-common
    $ sudo apt-get install nfs-kernel-server

  2. 设定 /etc/exports (For example: 將/mnt/iso share給all net使用)

    1
    2
    $ sudo vi /etc/exports
    /mnt/iso *(ro,sync)

  3. 启动 nfs server

    1
    $ sudo /etc/init.d/nfs-kernel-server start

  4. 检查

    1
    $ showmount -e localhost
    成功的话应该可以看到这样的信息:
    1
    2
    Export list for localhost:
    /mnt/iso *

5、相当给力的find命令:

1)查找并删除某个文件(或目录)

这里以删除当前目录(含子目录)下所有*.svn目录为例

1
 find . -name .svn -exec rm -rf {} \;
2)将包含某文本的所有文件及其对应行显示出来。

如下命令,在/usr目录中查找所有包含error、并以.log结尾的文件

1
find /usr -name '*.log' | xargs grep 'error'

3)批量命名文件。 如下命令,查找所有文件名包含“[www.网址111.com]”字符串的文件,并将文件名中的该字符串删除。

1
find -type f | grep '\[www\.网址111\.com\]' | xargs rename 's/'\[www\.网址111\.com\]'//'
4) 查找文件,并将对其权限进行修改
1
for l in $(find . -type f -name "*"); do chmod 664 $l; done
5) 查找当前目录下(含子目录)包含指定字符串的文件名
1
2
3
4
5
6
7
#该命令查找当前目录下(含子目录)包含指定字符串的文件名
#用法 “find_files_with_string 文件名”即可
find_files_with_string()
{
grep -il -R $1 *
}
alias ffwstr=find_files_with_string

6 FTP配置

6.1、VsFTPd的配置

搞个简易的自己用用(开通匿名账号,并且可以上传、下载、删除)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
listen=YES
anonymous_enable=YES
write_enable=YES
local_enable=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
ftpd_banner=Welcome to Ferret's FTP service.
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem

#设置匿名账号的主目录
anon_root=/usr/local/arm/exports
#可进行其他操作
anon_other_write_enable=YES

#这句必须加上,否则只能上传删除等不能下载
anon_umask=022
注意: 上述配置文件将匿名账号的路径设为/usr/local/arm/exports,在Ubuntu下要该目录改为root所有,在其下的路径都改为ftp匿名账号所有,即可。

6.2、ProFTPd的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#
# /etc/proftpd/proftpd.conf -- This is a basic ProFTPD configuration file.
# To really apply changes reload proftpd after modifications.
#

# Includes DSO modules
Include /etc/proftpd/modules.conf

# Set off to disable IPv6 support which is annoying on IPv4 on
ly boxes.
UseIPv6                off
# If set on you can experience a longer connection delay in many cases.
IdentLookups            off

ServerName            "Ferret's FTP Server"
ServerType            standalone
DeferWelcome            off

MultilineRFC2228        on
DefaultServer            on
ShowSymlinks            on


TimeoutNoTransfer        180
TimeoutStalled            180
TimeoutIdle            300

DisplayLogin                    .welcome.msg
DisplayChdir                   .message true
ListOptions                    "-l"

DenyFilter            \*.*/

# Use this to jail all users in their homes
 DefaultRoot            /usr/ftpService

# Users require a valid shell listed in /etc/shells to login.
# Use this directive to release that constrain.
# RequireValidShell        off

# Port 21 is the standard FTP port.
Port                21

# In some cases you have to specify passive ports range to by-pass
# firewall limitations. Ephemeral ports can be used for that, but
# feel free to use a more narrow range.
# PassivePorts                  49152 65534

# If your host was NATted, this option is useful in order to
# allow passive tranfers to work. You have to use your public
# address and opening the passive ports used on your firewall as well.
# MasqueradeAddress        1.2.3.4

# This is useful for masquerading address with dynamic IPs:
# refresh any configured MasqueradeAddress directives every 8 hours
<IfModule mod_dynmasq.c>
# DynMasqRefresh 28800
</IfModule>

# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at on
ce, simply increase this value.  Note that this ON
LY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances            10

# Set the user and group that the server normally runs at.
#User                proftpd
User                ftp
Group                nogroup

# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.
Umask                022  022
# Normally, we want files to be overwriteable.
AllowOverwrite            on

AllowStoreRestart on

# Uncomment this if you are using NIS or LDAP via NSS to retrieve passwords:
# PersistentPasswd        off

# This is required to use both PAM-based authentication and local passwords
# AuthOrder            mod_auth_pam.c* mod_auth_unix.c

# Be warned: use of this directive impacts CPU average load!
# Uncomment this if you like to see progress and transfer rate with ftpwho
# in downloads. That is not needed for uploads rates.
#
# UseSendFile            off

TransferLog /var/log/proftpd/xferlog
SystemLog   /var/log/proftpd/proftpd.log

<IfModule mod_quotatab.c>
QuotaEngine off
</IfModule>

<IfModule mod_ratio.c>
Ratios off
</IfModule>


# Delay engine reduces impact of the so-called Timing Attack described in
# http://security.lss.hr/index.php?page=details&ID=LSS-2004-10-02
# It is on by default.
<IfModule mod_delay.c>
DelayEngine on
</IfModule>

<IfModule mod_ctrls.c>
ControlsEngine        off
ControlsMaxClients    2
ControlsLog           /var/log/proftpd/controls.log
ControlsInterval      5
ControlsSocket        /var/run/proftpd/proftpd.sock
</IfModule>

<IfModule mod_ctrls_admin.c>
AdminControlsEngine off
</IfModule>

#
# Alternative authentication frameworks
#
#Include /etc/proftpd/ldap.conf
#Include /etc/proftpd/sql.conf

#
# This is used for FTPS connections
#
#Include /etc/proftpd/tls.conf

#
# Useful to keep VirtualHost/VirtualRoot directives separated
#
#Include /etc/proftpd/virtuals.con

# A basic anonymous configuration, no upload directories.

<Limit SITE_CHMOD>
    DenyAll
</Limit>

<Directory /wd_1t/ftpService>
    <Limit ALL>
        DenyAll
    </Limit>
</Directory>


# <Anonymous ~ftp>
 <Anonymous /wd_1t/ftpService/pub>
   User                ftp
   Group                nogroup
#   # We want clients to be able to login with "anonymous" as well as "ftp"
   UserAlias            anonymous ftp
#   # Cosmetic changes, all files belongs to ftp user
   DirFakeUser    on ftp
   DirFakeGroup on ftp
#
   RequireValidShell        off
#
#   # Limit the maximum number of anonymous logins
   MaxClients            10
#
#   # We want 'welcome.msg' displayed at login, and '.message' displayed
#   # in each newly chdired directory.
   DisplayLogin            welcome.msg
#   DisplayChdir        .message
#
#   # Limit WRITE everywhere in the anonymous chroot
   <Directory /wd_1t/ftpService/pub>
     <Limit WRITE>
       DenyAll
     </Limit>
   </Directory>

   <Directory /wd_1t/ftpService/upload>
    <Limit ALL>
        DenyAll
    </Limit>


    <Limit DIRS WRITE CMD RMD STOR>
        AllowAll
    </Limit>

    <Limit DELE>
        DenyAll
    </Limit>
   
#        <Limit WRITE>
#       AllowAll
#    </Limit> #如果不想让下载,只让上载 可以加上
#     <Limit READ>
#        DenyAll
#    </Limit>
   </Directory> #到这差不多就完了,每个目录可以写 .ftpaccess 设置权限


   <Directory /wd_1t/ftpService/www>
     <Limit ALL>
    DenyAll
     </Limit>
   </Directory>

#
#   # Uncomment this if you're brave.
#   # <Directory incoming>
#   #   # Umask 022 is a good standard umask to prevent new files and dirs
#   #   # (second parm) from being group and world writable.
#   #   Umask                022  022
#   #            <Limit READ WRITE>
#   #            DenyAll
#   #            </Limit>
#   #            <Limit STOR>
#   #            AllowAll
#   #            </Limit>
#   # </Directory>
#
 </Anonymous>


<Anonymous /wd_1t/ftpService>
    User   ferret
    Group   nogroup
#    Umask 022
     <Directory *>
      <Limit ALL>
       AllowAll
      </Limit>
     </Directory>     
</Anonymous>

#<Anonymous /usr/ftpService/www>
#      User   ferret
#      Group   nogroup
#  #   Umask 022
#       <Directory *>
#        <Limit ALL>
#         AllowAll
#        </Limit>
#       </Directory>
# </Anonymous>

<Anonymous /wd_1t/ftpService/Movies>
    User xmj
    Group nogroup
#    Umask 022
    <Directory *>
     <Limit READ DIRS CMD RMD STOR>
         AllowAll
     </Limit>
   
      <Limit WRITE>
        DenyAll
      </Limit>
    </Directory>
</Anonymous>

<Anonymous /home/bt/rtorrent/torrents>
    User bt
    Group nogroup
#   Umask 022
    <Directory *>
      <Limit ALL>
        AllowAll
      </Limit>
    </Directory>
</Anonymous>

注:Proftpd的错误,今天将服务器有10.10升级至12.04版本,proftpd出现如下错误:

1
proftpd[3644]: Fatal: LoadModule: error loading module 'mod_vroot.c': 不允许的操作 on line 68 of '/etc/proftpd/modules.conf'
解决方法:proftpd没有安装依赖库“proftpd-mod-vroot”,
1
apt-get install proftpd-mod-vroot,
重启ftp,OK

7、Ubuntu多系统启动相关

  1. 更改启动顺序 登录为root权限,进入/etc/grub.d目录,找到30_os-prober这个文件,把 30_os-prober这个文件名的数字30改为05到10之间的数字即可(没多少可选06、07、08、09)。 比如改为08_os-prober,这样创建出来的grub.cfg内的菜单项,windows的排序就会自动在ubuntu之前;

另一种方法没试验,如下: 打开/boot/grub/grub.cfg,各个启动项都以menuentry为开头,将menuentry中的内容copy下来,如:menuentry中的"Ubuntu Live Desktop 10.04 32bit zh_TW"抄起來。

1
menuentry "Ubuntu Live Desktop 10.04 32bit zh_TW" {
然后打开/etc/default/grub,搜索GRUB_DEFAULT=0项,将后面的0,使用上述复制的字符串替换:
1
GRUB_DEFAULT="Ubuntu Live Desktop 10.04 32bit zh_TW"
最后更新下grub:update-grub, (如要还原成原样,使用GRUB_DEFAULT=0,再重新更新下grub即可)。

  1. 删除启动项中的多余项(主要是linux升级后的多个内核) 首先显示系统已安装内核:
    1
    dpkg --get-selections | grep linux-image
    结果如下(本机):
    1
    2
    3
    4
    root@njuFerret:/home/ferret# dpkg --get-selections | grep linux-image
    linux-image-2.6.35-22-generic                   install
    linux-image-2.6.35-24-generic                   install
    linux-image-generic                             install
    运行以下命令删除旧内核:
    1
    apt-get remove linux-image-2.6.35-22-generic    #删除旧的内核
    更新grub,然后重启就可以了:
    1
    update-grub     # 更新grub,(可能不需要)

附命令:

1
2
3
dpkg --get-selections [<表达式> ...] 把已选中的软件包列表打印到标准输出
grep linux-image 匹配查找
uname -a 查看已安装的linux内核版本

8、shell脚本的几个技巧

1)使用命令的返回值:

1
2
3
4
5
6
7
8
#!/bin/sh
a=$(pwd) #或 a=`pwd` "`"是撇号,非单引号
if [ "$a" = "/root" ]
then
echo "you are in the root directory"
else
echo "you are in the "$a" directory"
fi

2)判断目录是否存在   

1
2
3
4
5
6
7
#!/bin/sh
export srcPath=$(pwd)
if [ ! -d "$srcPath/installing..." ]; then
echo " **** tslib未安装 **** "
echo "请先运行1.build_tslib安装tslib"
exit
fi

3)定义函数并返回字符串

1
2
3
4
5
6
7
8
9
10
function getUbootFolder()
{
fname=$1
fname=${fname%".7z"}; # "%"表示从右侧开始将匹配的字符串删除
fname=${fname%".bak"};
fname=${fname%".tar.bz2"};
echo $fname;
}
ubootFolder=$(getUbootFolder "$UBOOT_SRC");
echo $ubootFolder;
关于字符串的更多操作,详见这里

4)case语句的一个很经典的用法

1
2
3
4
5
6
7
8
9
10
ftype=`file "$UBOOT_SRC"`   # Note ' and ` is different

case "$ftype" in
"$UBOOT_SRC: 7-zip archive data"*)
fullPath=
  7z x "$UBOOT_SRC" > /dev/NULL;;
"$UBOOT_SRC: bzip2 compressed"*)
   tar xvf "$UBOOT_SRC" > /dev/NULL;;
*) echo "$UBOOT_SRC:未知文件类型,请确认该文件为7zip或bzip2压缩";;
esac
上述命令中,利用file命令来判断文件类型,并根据不同的类型选择不同的处理方法

9、0k6410的两个命令

1)设置本机地址

1
2
3
4
5
6
7
8
# 设置IP地址
ifconfig eth0 192.168.10.120 netmask 255.255.255.0
# 设置默认网关
route delete default
route add default gw 192.168.10.1
# 修改域名服务器
将 etc/resolv.conf 文件内容修改如下:
nameserver 192.168.10.1

2)设置mount文件夹,注意-o nolock必须加上

1
mount -t nfs 10.0.242.120:/usr/local/arm/exports /tmp -o nolock
3)设置uboot的nfs引导
1
2
3
4
# 设置环境变量
setenv bootargs "root=/dev/nfs nfsroot=192.168.10.101:/usr/local/arm/exports/export ip=192.168.10.120:192.168.10.101:192.168.10.1:255.255.255.0:aaa.bbb:eth0:off console=ttySAC0,115200"
printenv         # 列出当前的环境变量
saveenv          # 保存环境变量

10、Ubuntu(10.10)设置命令行启动与恢复

1)打开 /etc/default/grub ,在GRUB_CMDLINE_LINUX_DEFAULT="quite splash"的末尾添加text

1
GRUB_CMDLINE_LINUX_DEFAULT="quite splash text" 
2) 执行 update-grub 命令,重启即可。 如果需要恢复: 1)启动后,暂时性恢复,执行命令: /etc/init.d/gdm start (或使用alias,将下句命令添加到~/.bash_aliases中)
1
alias startGUI='/etc/init.d/gdm start'
2)启动前暂时性恢复,在ubuntu启动,显示启动菜单时按下e,删除kernel命令行中的text即可。 3)永久性恢复:移除上面添加的text,然后update-grub,再重新启动

注:貌似11.10版本改了,临时性启动gui命令是/etc/init.d/lightdm start,我这里是10.10,没做测试。 另外,如果希望恢复桌面,可以使用nxServer,安装后可以通过网络使用远程桌面,很强大。

11、Ubuntu Server 12.04 “初始化月份字符串出错”的解决方法

本部分来源:来源1来源2 1、修改local文件: 执行:sudo vi /var/lib/locales/supported.d/local 将文件内容修改如下:

1
2
3
4
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GBK GBK
zh_CN GB2312
2、更新语言:执行sudo locale-gen 3、编辑默认locale文件:sudo vi /etc/default/locale,修改文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
注意:最后一个文件中都是半角英文双引号,在上述两个来源中,均为中文全角双引号。注意修正。

12、给系统打补丁的命令

下载了内核之后,进入内核源码所在位置:cd /xxxx/xxx/linux-3.4.6 使用下面的命令对内核打补丁:

1
patch -p1 -i ../patch-3.4.6 -R
-p1是略过最高层,此处是linux-3.4.6-i表示所需要打的补丁文件,patch-3.4.6是补丁文件; -R是循环命令,在命令运行时有很多需要用户确认的,此处表示循环确认。

13、创建一个带有主目录和能够执行基本脚本的用户:

1
2
useradd -d /home/"username" -g "gid" -u "uid" -m -s /bin/bash "username"
passwd "username"

14、解决Ubuntu 12.04升级到14.04时,fontConfig错误

1
2
3
4
5
6
7
8
9
Setting up fontconfig (2.11.0-0ubuntu4.1) ...
Regenerating fonts cache... failed.
See /var/log/fontconfig.log for more information.
dpkg: error processing package fontconfig (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up apt-utils (1.0.1ubuntu2.6) ...
Errors were encountered while processing:
fontconfig
E: Sub-process /usr/bin/dpkg returned an error code (1)

查看日志,出现以下内容:

1
2
3
4
5
6
7
8
9
10
Fontconfig warning: "/etc/fonts/conf.d/99-language-selector-zh.conf", line 
11: Having multiple values in <test> isn't supported and may not work as  
expected
/usr/share/fonts: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/truetype/ttf-dejavu: caching, new cache contents: 6 fonts,     0 dirs
/usr/X11R6/lib/X11/fonts: skipping, no such directory
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/.local/share/fonts: fc-cache: symbol lookup error: fc-cache:
undefined symbol: FcStrListFirst
解决方法:运行apt-get remove --purge fontconfig-config,删除 fontConfig-config即可。 然后重新运行apt-get upgrade,直接升级,问题解决。 参考链接:askubuntu

15、增加启动时执行的命令

这个网上很多,这里说的主要是为了ftp能够自动将不同硬盘的目录挂接在一起。proftpd中,利用mount命令,将第二块硬盘的一个目录,挂接到ftp的主目录下:

1
mount --bind /usr/ftpService/MTV /wd_1t/ftpService/Movies/MTV
上述命令将usr路径下的目录挂接到wd_1t目录下(wd_1t/ftpService是ftp的主目录),用户在访问wd_1t/.../MTV目录时等同访问usr下的MTV目录。 启动项的建立比较简单,以#!/bin/sh开头,写上要执行的命令,并给于可执行权限755就可以了。

1)在/etc/init.d/目录下新建一个脚本my-start-up,如下:

1
2
#!/bin/sh
mount --bind /usr/ftpService/MTV /wd_1t/ftpService/Movies/MTV
2)执行
1
update-rc.d my-start-up defaults
执行完成之后,系统会提示:
1
update-rc.d: warning: /etc/init.d/my-start-up missing LSB information
原因不详,如果想删除该启动脚本,执行以下命令:
1
/etc/init.d$ sudo update-rc.d -f my-start-up remove
3)ubuntu 20.04 需要使用systemctl 启用该服务,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 查看状态
/etc/init.d$ systemctl status my-start-up.service
# output
# ● my-start-up.service - LSB: start my-start-up
# Loaded: loaded (/etc/init.d/my-start-up; generated)
# Active: generated
# Docs: man:systemd-sysv-generator(8)
# Process: 2285 ExecStart=/etc/init.d/my-start-up start (code=exited, # status=0/SUCCESS)

# 启用服务
/etc/init.d$ sudo systemctl enable my-start-up.service
# 输出:
# my-start-up.service is not a native service, redirecting to systemd-sysv-install.
# Executing: /lib/systemd/systemd-sysv-install enable my-start-up

重启即可看到效果

16、安装无线网卡驱动并开机自动登录WiFi

老笔记本新安装了14.04服务器版Ubuntu。无线网卡是BroadCom的BCM4318(HP nx6120),安装时没有网线,也没有WiFi驱动,所有网络都不可用。网络这些东西都是必须要的,首先解决这几个问题(以下均为管理员权限下操作)。 1)插上网线,临时使用网卡。

1
2
3
4
lspci | grep -i eth    # 查看网卡
iwconfig # 列出所有的网络接口interfaces
ifconfig eth0 up # 确定是eth0之后,启用eth0
dhclient eth0 # 开启dhcp客户端,现在应该可以了
2)能够上网之后,先更新一次(update就行,不用upgrade),然后安装BCM4318的驱动:
1
2
3
4
5
6
7
lspci | grep -i wireless     # 查看无线网卡的信息
# 上述命令显示
# 02:04.0 Network controller: Broadcom Corporation BCM4318 [AirForce One 54g] 802.11g Wireless LAN Controller (rev 02)
# lspci | grep -i eth # 显示以太网卡的信息

apt-get purge bcmwl-kernel-source
apt-get install --reinstall b43-fwcutter firmware-b43-installer

安装完成之后,可以使用第一步的方法启用无线网卡,但是一般的WiFi均有密码,很烦。我这里的WiFi使用的是WEP,最简单的一种,因此可以用下面的方法解决。 3)编辑文件interfaces(注意备份),启动时自动加载网卡。

1
vi /etc/network/interfaces
前两句是原来文件的内容,在这之后,添加后面的内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
auto lo
iface lo inet loopback


# 网络接口名可用iwconfig查看
auto wlan0
iface wlan0 inet static
address 192.168.10.105
netmask 255.255.255.0
gateway 192.168.10.1
wireless-essid 路由的SSID
wireless-key 路由访问密码


auto eth0
iface eth0 inet dhcp
## 17、添加用户并将其加入sudo组中 以下命令均在root权限下执行:
1
2
adduser test
usermod -aG sudo test
## 18、配置nginx服务器使用https加密传输 1)准备工作:
1
2
3
4
5
# 秘钥和crt文件位置
sudo mkdir /etc/nginx/ssl
# 使用openssl创建秘钥和加密文件
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
# 填入相应的内容
注意:Common Name是网站的域名或者IP
1
2
3
4
5
6
7
Country Name (2 letter code) [AU]:CN 
State or Province Name (full name) [Some-State]:Jiangsu
Locality Name (eg, city) []:Nanjing
Organization Name (eg, company) [Internet Widgits Pty Ltd]:OrganizationName
Organizational Unit Name (eg, section) []:SectionName
Common Name (e.g. server FQDN or YOUR name) []:10.3.89.127
Email Address []:email@email.com
2)配置nginx
1
sudo vi /etc/nginx/sites-available/default
按照以下内容修改: a)设定将所有http重定向至https
1
2
3
4
5
6
7
8
9
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server ipv6on
ly=on;

# 重定向到 HTTPS
rewrite ^(.*) https://$host$1 permanent;
}
b) 设定HTTPS的秘钥与凭证路径
1
2
3
4
5
6
7
8
9
10
11
server{
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

# ssl凭证与秘钥路径
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
# 其他设定,保持不变
...
3)重启nginx
1
sudo service nginx resart
当使用 HTTPS浏览时,浏览器会发错凭证不可靠的警告,如果凭证FQDN跟服务器的FQDN不符时,也会出现浏览告警,解决方法是重新使用openssl生成一个与服务器FQDN一致的凭证。

19、批量重命名文件

总是遇到重命名的情况,这次一定要记录下来,

1
rename 's/src_string/target_string/g' *.txt
将所有txt文件中,文件名含有的src_string字符串替换为target_string,支持正则表达式。对于含有空格的可以使用's/ /_/g'做替换,然后重复上述替换步骤。

本文来自:http://ferret.blog.163.com/blog/static/64423780201103014710258