debian/ubuntuserver学习整理系列之一:基本日常使用与软件包管理


索引 说明
基础安装使用,系统升级等 tasksel,系统升级do-release-upgrade,关机,终端命令,特殊设备,特殊挂载点,配置默认编辑器,基本命令,exit code,清除缓存,删除内核,
软件包管理简介

管理命令列表,基本操作列表,高级操作列表,日志文件,软件备份与还原,软件包副本位置,软件包清除命令,

update-alternatives默认软件配置,dpkg, apt-get/apt-cache, aptitude,自动更新unattended-upgrades,常用操作列表

一、基础安装与系统升级,初步使用

0.对于desktop发行版本要注意:在配置/boot/default/grub时开启特性和功能支持:

GRUB_CMDLINE_LINUX_DEFAULT="queit splash acpi_osi=Linux"

1.tasksel

使用tasksel命令可以安装配置好的各种服务器套件。如LAMP,mail server ,dns-server等等。

tasksel; tasksel --list-tasks; 显示各种套件包中的具体tasksel --task-packages dns-server

安装套件tasksel install dns-server

2.Upgradeing更新:

系统版本更新对于debian系列来说一般使用apt-get dist-upgrade

但是对于ubuntu来说推荐使用do-release-upgrade命令。

do-release-upgrade:更新到稳定发行版

do-release-upgrade -d :更新到开发版

说到这里我们说说centos的系统更新吧:

yum update 下载更新系统已安装的所有软件包
yum upgrade 大规模的版本升级,与yum update不同的是,连旧的淘汰的包也升级

3.登录界面:

ctrl+Alt+F1-F6进入字符界面,Alt+F7进入图像界面

字符界面shell prompt欢迎词位置:/etc/motd

4.关机:

在多用户情形下关机:shutdown -h now

在单用户情形下关机:poweroff -i -f

同时你也可以使用ctrl+Alt+del关机,但是需要确保/etc/inittab(debian下)或者/etc/init/rc-sysinit.conf(ubuntu下)包含

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -h now

5.有趣的终端命令:

clear/reset

mc : A text-mode full-screen file manager

w3m:Text-mode WWW browsers

gpm:The Unix style cut-and-paste on the text console

6.添加和删除用户

adduser xby

deluser --remove-home xby

7.有趣的特殊设备:

/dev/zero; /dev/null, /dev/random,

8.linux文档系统说明文档位置:/usr/share/doc/linux-doc-*/Documentation/filesystems/*

9.特殊挂载点:
/proc ; /sys; /var/run ; /var/lock;

10.终端特殊快捷键:ctrl+z/d/c; ctrl+alt+del; tab ;

11.配置默认文本编辑器方式:/usr/bin/editor(通过创建连接方式)

A: export EDITOR=vim>> ~/.bashrc添加这个

B:$ sudo update-alternatives --config editor

12.配置vim初步:~/vimrc

Example:

set nocompatible
set nopaste
set pastetoggle=<f2>
syn on
if $USER == "root"
 set nomodeline
 set noswapfile
else
 set modeline
 set swapfile
endif
13.基本的命令:

pwd ;

whoami;

id: display current user identity (name, uid, gid, and associated groups)

file: display the file type

type -p <commandname> : display a file location of coommand

for Exam:# type -p apache2
/usr/sbin/apache2

which和type -p类似

type <commd>展示命令信息

apropos <key-word> find commands related to "<key-word>"
whatis <comd> 展示一行命令信息

man <cmd>

ls ; ls -a ;ls -A; ls -al; ls-ali; ls -d;

tree

lsof [-p] filename:显示打开文件的进程

mkdir; rm -rf; rmdir

cd ; cd .. ;cd -; cd ~xby;

touch; cp ; mv; chomd ;chown; chgrp;

find ; updateda && locate ; grep -e <pattern>

top; ps aux; ps -fe ; pstree; kill; killall;

jobs;fg;bg;

gzip;bzip2;xz;zcat;bzcat;tar;

15终端语言环境设置:export LANG=en_US.UTF-8

16.shell中的匹配模式glob:

*; .; ?; [..]; [a-z]; [^..]

示例:

$ echo [^1-3]*
4.h
17.终端命令执行结果exit codes: 

Table 1.21. Command exit codes

command exit statusnumeric return valuelogical return value
successzero, 0TRUE
errornon-zero, -1FALSE

For example, try the following.

$ [ 1 = 1 ] ; echo $?0$ [ 1 = 2 ] ; echo $?1

18:shell常用符号

>>, <<, >, < , | , &; &&; || ; !!; 2>&1; - ; ; ;

19.命令别名:

alias, unalias

内键命令查看:type ls

20:脚本与管道:

find ,seq, xargs, grep, cut, awk,sed, sort, uniq, tr, head, tail

21.

清理opera firefox的缓存文件:

ls ~/.opera/cache4

ls ~/.mozilla/firefox/*.default/Cache

22.删除多余内核

1,首先要使用这个命令查看当前Ubuntu系统使用的内核

uname -r

2,再查看所有内核

dpkg --get-selections|grep linux

3,最后小心翼翼地删除吧

sudo apt-get remove linux-image-2.6.32-22-generic

ps:linux-image-xxxxxx-generic 就是要删除的内核版本

还有

linux-headers-xxxxxx

linux-headers-xxxxxx-generic 总之中间有“xxxxxx”那段的旧内核都能删,注意一般选内核号较小的删。

你可以通过这条命令来进行以上部分工作:

dpkg --get-selections | grep linux| grep -v "$(uname -r)"

二、软件包管理简介:

Table 2.1. List of Debian package management tools

package popcon size description
apt V:857, I:999 3569 Advanced Packaging Tool (APT), front-end fordpkgproviding "http", "ftp", and "file" archive access methods (apt-get/apt-cachecommands included)
aptitude V:227, I:991 4488 interactive terminal-based package manager with aptitude(8)
tasksel V:51, I:966 715 tool for selecting tasks for installation on the Debian system (front-end for APT)
unattended-upgrades V:59, I:471 312 enhancement package for APT to enable automatic installation of security upgrades
dselect V:8, I:80 2516 terminal-based package manager (previous standard, front-end for APT and other old access methods)
dpkg V:910, I:999 6427 package management system for Debian
synaptic V:111, I:478 7667 graphical package manager (GNOME front-end for APT)
apt-utils V:429, I:997 1364 APT utility programs: apt-extracttemplates(1), apt-ftparchive(1), and apt-sortpkgs(1)
apt-listchanges V:369, I:757 203 package change history notification tool
apt-listbugs V:9, I:15 418 lists critical bugs before each APT installation
apt-file V:20, I:87 69 APT package searching utility — command-line interface
apt-rdepends V:1, I:8 64 recursively lists package dependencies

新手注意事项:1。不要使用dpkg -i/-r ;2.出现问题不要删除/var/lib/dpkg;3.不要安装编译的软件覆盖系统文件。自己编译的软件应该安装到/usr/local或者/opt,如--prefix=/usr/local;4.不要安装不稳定的软件或版本

相关常用操作一览:

update:aptitude update" or "apt-get update

upgrade:"aptitude safe-upgrade" and "aptitude full-upgrade", or "apt-get upgrade" and "apt-get dist-upgrade"

install:"aptitude install …" or "apt-get install …"

remove:aptitude remove …" or "apt-get remove …"

purge:"aptitude purge …" or "apt-get purge …"

0.1基本的包管理操作:apt-get/apt-cacheandaptitude.

Table 2.6. Basic package management operations with the commandline using aptitude(8) and apt-get(8) /apt-cache(8)

aptitudesyntax apt-get/apt-cachesyntax description
aptitude update apt-get update update package archive metadata
aptitude install foo apt-get install foo install candidate version of "foo" package with its dependencies
aptitude safe-upgrade apt-get upgrade install candidate version of installed packages without removing any other packages
aptitude full-upgrade apt-get dist-upgrade install candidate version of installed packages while removing other packages if needed
aptitude remove foo apt-get remove foo remove "foo" package while leaving its configuration files
N/A apt-get autoremove remove auto-installed packages which are no longer required
aptitude purge foo apt-get purge foo purge "foo" package with its configuration files
aptitude clean apt-get clean clear out the local repository of retrieved package files completely
aptitude autoclean apt-get autoclean clear out the local repository of retrieved package files for outdated packages
aptitude show foo apt-cache show foo display detailed information about "foo" package
aptitude search <regex> apt-cache search <regex> search packages which match <regex>
aptitude why <regex> N/A explain the reason why <regex> matching packages should be installed
aptitude why-not <regex> N/A explain the reason why <regex> matching packages can not be installed

[Note]
日志文件:

Table 2.12. The log files for package activities

file content
/var/log/dpkg.log Log ofdpkglevel activity for all package activities
/var/log/apt/term.log Log of generic APT activity
/var/log/aptitude Log ofaptitudecommand activity

0.2高级管理:

Table 2.13. List of advanced package management operations

command action
COLUMNS=120 dpkg -l <package_name_pattern> list status of an installed package for the bug report
dpkg -L <package_name> list contents of an installed package
dpkg -L <package_name> | egrep '/usr/share/man/man.*/.+' list manpages for an installed package
dpkg -S <file_name_pattern> list installed packages which have matching file name
apt-file search <file_name_pattern> list packages in archive which have matching file name
apt-file list <package_name_pattern> list contents of matching packages in archive
dpkg-reconfigure <package_name> reconfigure the exact package
dpkg-reconfigure -p=low <package_name> reconfigure the exact package with the most detailed question
configure-debian reconfigure packages from the full screen menu
dpkg --audit audit system for partially installed packages
dpkg --configure -a configure all partially installed packages
apt-cache policy <binary_package_name> show available version, priority, and archive information of a binary package
apt-cache madison <package_name> show available version, archive information of a package
apt-cache showsrc <binary_package_name> show source package information of a binary package
apt-get build-dep <package_name> install required packages to build package
aptitude build-dep <package_name> install required packages to build package
apt-get source <package_name> download a source (from standard archive)
dget <URL for dsc file> download a source packages (from other archive)
dpkg-source -x <package_name>_<version>-<debian_version>.dsc build a source tree from a set of source packages ("*.orig.tar.gz" and "*.debian.tar.gz"/"*.diff.gz")
debuild binary build package(s) from a local source tree
make-kpkg kernel_image build a kernel package from a kernel source tree
make-kpkg --initrd kernel_image build a kernel package from a kernel source tree with initramfs enabled
dpkg -i <package_name>_<version>-<debian_version>_<arch>.deb install a local package to the system
debi <package_name>_<version>-<debian_version>_<arch>.dsc install local package(s) to the system
dpkg --get-selections '*' >selection.txt savedpkglevel package selection state information
dpkg --set-selections <selection.txt setdpkglevel package selection state information
echo <package_name> hold | dpkg --set-selections setdpkglevel package selection state for a package to hold (equivalent to "aptitude hold <package_name>")

[Note]

0.3备份安装软件列表及还原:

备份软件列表:dpkg --get-selections > back.txt;

还原并安装:dpkg -set-selections <back .txt && apt-get dselect-upgrade

但是debian官方推荐方式为:这样可以连配置文件一起备份

备份:

# dpkg --get-selections '*' > selection.dpkg
# debconf-get-selections    > selection.debconf
还原:

# dselect update
# debconf-set-selections < myselection.debconf
# dpkg --set-selections  < myselection.dpkg
# apt-get -u dselect-upgrade    # or dselect install

0.4已安装软件状态信息:

"/var/lib/apt/extended_states"

0.5本地存放的apt安装的软件包副本位置:

/var/cache/apt/archives

没有下载完的软件包在:/var/cache/apt/archives/partial

注意:这里无法通过apt-get autoclean清除,但可以通过apt-get clean清除。

几个清除命令的区别:

sudo apt-get autoclean 清理旧版本的软件缓存

sudo apt-get clean 清理所有软件缓存

sudo apt-get autoremove 删除系统不再使用的孤立软件

这三个命令主要清理升级缓存以及无用包的。

0.6软件删除与清理常用方式:

sudo apt-get remove --purge 软件名

sudo apt-get autoremove 删除系统不再使用的孤立软件

sudo apt-get autoclean 清理旧版本的软件缓存

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 清除残余的配置文件,保证干净。


0.7 update-alternatives命令:用于管理相同功能的软件,默认软件。

 sudo update-alternatives --display vi
...
$ sudo update-alternatives --config vi

The Debian alternatives system keeps its selection as symlinks in "/etc/alternatives/". The selection process uses corresponding file in "/var/lib/dpkg/alternatives/".

0.8转换rpm或其他格式包至deb包:alien

0.9:

dpkg 来管理软件包, 类似 RPM. 系统中所有 packages 的信息都在 /var/lib/dpkg/

目录下, 其子目录 /var/lib/dpkg/info 用于保存各个软件包的配置文件列表:

(1)*.conffiles 记录了软件包的配置文件列表

(2)*.list 保存软件包中的文件列表, 用户可以从 .list 的信息中找到软件包中文件的具体安装位置.

(3)*.md5sums 记录了软件包的md5信息, 这个信息是用来进行包验证的.

(4)*.prerm 脚本在 Debian 包解包之前运行, 主要作用是停止作用于即将升级的软件包的服务, 直到软件包安装或升级完成.

(5)*.postinst 脚本是完成 Debian 包解开之后的配置工作, 通常用于执行所安装软件包相关命令和服务重新启动.

0.10:ppa源管理:

添加一个PPA源

sudo add-apt-repository ppa:user/ppa-name

如添加cairo-dock到weekly update源

sudo add-apt-repository ppa:cairo-dock-team/weekly/ubuntu

删除一个PPA源

sudo add-apt-repository -r ppa:user/ppa-name

sudo add-apt-repository -r ppa:cairo-dock-team/weekly/ubuntu

添加apt-key

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 72D340A3

1.dpkg:

一般debian系列发行版本都会使用dpkg作为底层的package management.与其他包管理器不同的是,

注意哦,dpkg并不处理软件包之间的依赖关系,也不会自动下载软件包和其依赖,所以dpkg只能安装local package

显示已安装package:

dpkg -l

显示某个文件属于的软件.

#dpkg -S /etc/apache2/apache2.conf

apache2.2-common: /etc/apache2/apache2.conf

属于apache2.2-common这个软件安装是产生

有用的dpkg命令:

dpkg --set-selections; dpkg --get-selections

dpkg -P <old>移除旧的或残存的包或配置文件

dpkg --configure -a修复软件损坏

使用dpkg安装与卸载软件(不推荐,因为dpkg不处理软件包之间的依赖关系):dpkg -i xxx.deb安装;dpkg -r xxx (不推荐)

2.Apt-Get(Advance Package Tool)

配置目录 /etc/apt/apt.conf.d/

/etc/cron.daily/apt

ubuntu官方推荐的管理工具。

它由一个或多个远程软件仓库取出要安装的软件包。同时它会在本地建立远程仓库的索引以便随时查找可安装的软件包

配置远程仓库/etc/apt/sources.list与/etc/apt/sources.list.d/目录。

更新索引:apt-get update

更新已安装的软件:apt-get upgrade

apt-get install zip p7zip-full

apt-get remove zip

apt-get remove p7zip-full --purge

apt-get help

日志文件/var/log/dpkg.log

添加key文件apt-key add

常用:

1. 更新或升级操作:

   apt-get update                  # 更新源  

   apt-get upgrade                 # 更新所有已安装的包  

   apt-get dist-upgrade                # 发行版升级(如,从10.10到11.04)  

2. 安装或重装类操作:

   apt-get install <pkg>         # 安装软件包<pkg>,多个软件包用空格隔开  

   apt-get install --reinstall <pkg> # 重新安装软件包<pkg>  

   apt-get install -f <pkg>          # 修复安装(破损的依赖关系)软件包<pkg>  

3. 卸载类操作:

   apt-get remove <pkg>          # 删除软件包<pkg>(不包括配置文件)  

   apt-get purge <pkg>           # 删除软件包<pkg>(包括配置文件)  

4. 下载清除类操作:

   apt-get source <pkg>              # 下载pkg包的源代码到当前目录  

   apt-get download <pkg>            # 下载pkg包的二进制包到当前目录  

   apt-get source -d <pkg>           # 下载完源码包后,编译  

   apt-get build-dep   <pkg>     # 构建pkg源码包的依赖环境(编译环境?)  

   apt-get clean                   # 清除缓存(/var/cache/apt/archives/{,partial}下)中所有已下载的包  

   apt-get autoclean               # 类似于clean,但清除的是缓存中过期的包(即已不能下载或者是无用的包)  

   apt-get autoremove              # 删除因安装软件自动安装的依赖,而现在不需要的依赖包  

5. 查询类操作:

   apt-cache stats             # 显示系统软件包的统计信息  

   apt-cache search <pkg>            # 使用关键字pkg搜索软件包  

   apt-cache show   <pkg_name>   # 显示软件包pkg_name的详细信息  

   apt-cache depends <pkg>       # 查看pkg所依赖的软件包  

   apt-cache rdepends <pkg>      # 查看pkg被那些软件包所依赖  

3.Aptitude

aptitude有一个纯文字界面的管理

不过一般还是使用命令行方便:

aptitude install/remove zip

4.Automatic Update自动更新

安装unattended-upgrades可以进行自动更新,或者有选择性的安全更新。同时可以添加软件黑名单不允许其更新

首先安装它:apt-get install unattended-upgrades

配置文件/etc/apt/apt.conf.d/50-unattended-upgrades,进行调整如下:

Unattended-upgrades::Allowed-Origins{

"Ubuntu precise-security";

// "Ubuntu precise-updates";

}

添加软件黑名单不允许更新:

Unattended-upgrades::Package-Blacklist{

"vim";

// “libc6”;

}

配置运行自动更新vim /etc/apt/apt.conf.d/02periodic 添加:

APT::Periodic::Update-Package-Lists "1"; //每天更新索引

APT::Periodic::Download-Upgradeable-Packages "1"; //每天下载更新

APT::Periodic::AutocleanInterval "7" //每个星期清理一次

APT::Periodic::Unattended-Upgrade "1";

关于此文件的更多设置信息可在/etc/cron.daily/apt中头部注释可见。

日志文件/var/log/unattended-upgrades

通知管理员

在/etc/apt/apt.conf.d/50unattended-upgrades文件中配置Unattended-Upgrade::Mail可以通知管理员要安装的更新和出现的问题

也可以使用apticron来完成通知apt-get install apticron,然后配置/etc/apticron/apticron.conf来进行通知

关于universe与Multiverse仓库

这两个仓库是由社区进行维护的,安全性对于服务器来说要慎重。

你也可以参考本人博客小站

相关内容

    暂无相关文章