Ubuntu 方便宜用,最值得让人称道的便是其安装软件的方式, 一条命令: sudo apt-get install xxx 就几乎能帮你搞定所有的软件安装难题。但是有时你可能有这样的需求,查看某个软件包是否安装、安装在哪..., 那我们就来介绍一下 Ubuntu 的软件包管理方式。
一、Ubuntu 采用 Debian 的软件包管理器 dpkg 来管理软件包, 类似 RPM. 系统中所有 packages 的信息都在 /var/lib/dpkg/
目录下, 其子目录 /var/lib/dpkg/info 用于保存各个软件包的配置文件列表:
(1).conffiles 记录了软件包的配置文件列表
(2).list 保存软件包中的文件列表, 用户可以从 .list 的信息中找到软件包中文件的具体安装位置.
(3).md5sums 记录了软件包的md5信息, 这个信息是用来进行包验证的.
(4).prerm 脚本在 Debian 包解包之前运行, 主要作用是停止作用于即将升级的软件包的服务, 直到软件包安装或升级完成.
(5).postinst 脚本是完成 Debian 包解开之后的配置工作, 通常用于执行所安装软件包相关命令和服务重新启动.
/var/lib/dpkg/available 文件的内容是软件包的描述信息, 该软件包括当前系统所使用的 Debian 安装源中的所有软件包,
其中包括当前系统中已安装的和未安装的软件包.
/var/cache/apt/archives 目录是在用 apt-get install 安装软件时,软件包的临时存放路径
/etc/apt/sources.list 存放的是软件源站点, 当你执行 sudo apt-get install xxx 时,Ubuntu 就去这些站点下载软件包到本地并执行安装
二、相关命令使用示例:
(1)查看某软件包的安装内容
dpkg -L xxx
(2)查找软件库中的软件包
apt-cache search 正则表达式
(3)显示系统安装包的统计信息
apt-cache stats
(4)显示系统全部可用软件包的名称
apt-cache pkgnames
(5)显示某软件包的详细信息
apt-cache show xxx
(6)查找某文件属于哪个包
apt-file search xxx
(7)查看已经安装了哪些软件包
dpkg -l
(8)查询某软件依赖哪些软件包
apt-cache depends xxx
(9)查询某软件被哪些软件包依赖
apt-cache rdepends xxx
(10)增加一个光盘源
sudo apt-cdrom add
注: 顾名思义, 就是安装更新软件包时让其优先从Ubuntu 光盘上找(如果你不能上网安装/更新, 但有 Ubuntu 的 DVD ISO, 这会对你非常有用)
(11)系统升级
sudo apt-get update
(12)清除所有已删除软件包的残馀配置文件
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
(13)编译时缺少h文件的自动处理
sudo auto-apt run ./configure
(14)查看安装软件时下载软件包的临时存放目录
ls /var/cache/apt/archives
(15)备份当前系统安装的所有软件包的列表
dpkg --get-selections | grep -v deinstall > ~/somefile
(16)从上面备份的安装包的列表文件恢复所有包
dpkg --set-selections < ~/somefile
sudo dselect
(17)清理旧版本的软件缓存
sudo apt-get autoclean
(18)清理所有软件缓存
sudo apt-get clean
(19)删除系统不再使用的孤立软件
sudo apt-get autoremove
(20)查看软件包在服务器上面的地址
apt-get -qq --print-uris install ssh | cut -d\' -f2
(21)rpm命令用来管理RPM软件包
rpm -ivh xxxx.rpm 安装软件包
rpm -ivh --replacefiles xxx.rpm 如果产生冲突,可以用--replacefiles忽略
rpm -Fvh xxx.rpm 刷新软件包
rpm -q 查询系统内所有已安装的RPM软件包
ubuntu 11.10 安装与配置libvirt0.9.11.3
解压libvirt-0.9.11.3.tar.gz
cd libvirt-0.9.11.3
./configure
出现:
checking libxml2 xml2-config >= 2.6.0..
则:
sudo apt-get install libxml2 libxml2-dev
configrue: error: you must install the gnutls library in order to compile and run libvirt
sudo apt-get install gnutls-doc gnutls-bin
sudo apt-get install libneon27-gnutls libcurl4-gnutls-dev
又提示缺少device-mapper-devel
从网上下载device-mapper.1.02.28.tgz,然后解压缩tar -zxvf device-mapper.1.02.28.tgz,
进入解压后的文件夹中:cd device-mapper.1.02.28。安装device-mapper。
(1) ./configure
(2) sudo make
(3) sudo make install
然后退出该文件夹,重新安装libvirt
You must install python-devel to build Python bindings
sudo apt-get install python-dev
configure: error: libnl-devel >= 1.1 is required for macvtap support
sudo apt-get install libnl-dev
最后:
sudo make
sudo make install
启动libvirt后台进程
sudo libvirtd &
更新动态链接库缓存
sudo ldconfig
c语言库的使用
编辑好.c源码(例如myxm.cpp)后,在命令行下编译 gcc myxm.c -lvirt -o myxm
然后运行./myxm即可
例子:
#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>
int main()
{
printf("Hello World!\n");
virConnectPtr conn=NULL;
conn=virConnectOpenReadOnly(NULL);
if(conn==NULL)
{
printf("conn is null!\n");
}
else
{
printf("connecting is successful!\n");
}
return 0;
}
使用过程出现的问题:
解决error while loading shared libraries: libvirt.so.0
第一种:
定义shell变量 LD_LIBRARY_PATH
$ LD_LIBRARY_PATH=/usr/local/lib
$ export LD_LIBRARY_PATH
$ ./example
第二种:
修改系统动态链接库配置文件
(the system dynamic linker configuration)
进入目录/etc/ld.so.conf.d
添加一个文件libvirt.conf,内容是:
# libvirt default configuration
/usr/local/lib
更新动态链接库缓存
sudo ldconfig
sudo apt-get install libxml2 libxml2-dev gnutls-doc gnutls-bin libneon27-gnutls libcurl4-gnutls-dev python-dev libnl-dev
出现的问题及解决办法
解决failed to connect socket to '/usr/local/var/run/libvirt/libvirt-sock':no such file or directory添加libvirt用户组sudo groupadd libvirt添加当前用户到libvirt组里sudo gpasswd yaxin libvirt记得要重启,才能有用 error: ebiptablesDriverInit:4129 : essential tools to support ip(6) tables firewalls could not be located编辑文件/usr/local/etc/libvirt/libvirtd.conf 取消一下几项的注释unix_sock_group = "libvirt"unix_sock_ro_perms = "0777"unix_sock_rw_perms = "0770"unix_sock_dir = "/var/run/libvirt"修改为unix_sock_dir = "/usr/local/var/run/libvirt"auto_unix_ro = "none"auth_unix_rw = "none" 如果要启动自动运行libvirtd编辑文件/etc/rc.local在exit 0之前添加sudo libvirtd &
import java.awt.Dimension;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.BoxLayout;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
/*
JTree的构造函数:
JTree()
JTree(Hashtable value)
JTree(Object[] value)//只有这个构造函数可以创建多个根结点
JTree(TreeModel newModel)
JTree(TreeNode root)
JTree(TreeNode root, boolean asksAllowsChildren)
JTree(Vector value)
*/
public class JTreeDemo {
public static void main(String[] args) {
// 构造函数:JTree()
JTree example1 = new JTree();
// 构造函数:JTree(Object[] value)
Object[] letters = { " a ", " b ", " c ", " d ", " e " };
JTree example2 = new JTree(letters);
// 构造函数:JTree(TreeNode root)(TreeNode空)
// 用空结点创建树
DefaultMutableTreeNode node1 = new DefaultMutableTreeNode(); // 定义树结点
JTree example3 = new JTree(node1); // 用此树结点做参数调用 JTree的构造函数创建含有一个根结点的树
// 构造函数:JTree(TreeNode root)(同上,只是TreeNode非空)
// 用一个根结点创建树
DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(" Color ");
JTree example4 = new JTree(node2); // 结点不可以颜色,默认为白面黑字
example4.setBackground(Color.lightGray);
// 构造函数:JTree(TreeNode root, boolean
// asksAllowsChildren)(同上,只是TreeNode又有不同)
// 使用DefaultMutableTreeNode类先用一个根结点创建树,设置为可添加孩子结点,再添加孩子结点
DefaultMutableTreeNode color = new DefaultMutableTreeNode(" Color ",
true);
DefaultMutableTreeNode gray = new DefaultMutableTreeNode(" Gray ");
color.add(gray);
color.add(new DefaultMutableTreeNode(" Red "));
gray.add(new DefaultMutableTreeNode(" Lightgray "));
gray.add(new DefaultMutableTreeNode(" Darkgray "));
color.add(new DefaultMutableTreeNode(" Green "));
JTree example5 = new JTree(color);
// 构造函数:JTree(TreeNode root)(同上,只是TreeNode非空)
// 通过逐个添加结点创建树
DefaultMutableTreeNode biology = new DefaultMutableTreeNode(" Biology ");
DefaultMutableTreeNode animal = new DefaultMutableTreeNode(" Animal ");
DefaultMutableTreeNode mammal = new DefaultMutableTreeNode(" Mammal ");
DefaultMutableTreeNode horse = new DefaultMutableTreeNode(" Horse ");
mammal.add(horse);
animal.add(mammal);
biology.add(animal);
JTree example6 = new JTree(biology);
horse.isLeaf();
horse.isRoot();
// 构造函数:JTree(TreeModel newModel)
// 用DefaultMutableTreeNodel类定义一个结点再用这个结点做参数定义一个用DefaultTreeMode
// 创建一个树的模型,再用JTree的构造函数创建一个树
DefaultMutableTreeNode root = new DefaultMutableTreeNode(" Root1 ");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(" Child1 ");
DefaultMutableTreeNode child11 = new DefaultMutableTreeNode(" Child11 ");
DefaultMutableTreeNode child111 = new DefaultMutableTreeNode(
" Child111 ");
root.add(child1);
child1.add(child11);
child11.add(child111);
DefaultTreeModel model = new DefaultTreeModel(root);
JTree example7 = new JTree(model);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setPreferredSize(new Dimension(700, 400));
panel.add(new JScrollPane(example1)); // JTree必须放在JScrollPane上
panel.add(new JScrollPane(example2));
panel.add(new JScrollPane(example3));
panel.add(new JScrollPane(example4));
panel.add(new JScrollPane(example5));
panel.add(new JScrollPane(example6));
panel.add(new JScrollPane(example7));
JFrame frame = new JFrame(" JTreeDemo ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.show();
}
}
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
import java.awt.GridLayout;
public class TreeDemo extends JPanel
implements TreeSelectionListener {
private JEditorPane htmlPane;
private JTree tree;
private URL helpURL;
private static boolean DEBUG = false;
//Optionally play with line styles. Possible values are
//"Angled" (the default), "Horizontal", and "None".
private static boolean playWithLineStyle = false;
private static String lineStyle = "Horizontal";
//Optionally set the look and feel.
private static boolean useSystemLookAndFeel = false;
public TreeDemo() {
super(new GridLayout(1,0));
//Create the nodes.
DefaultMutableTreeNode top =
new DefaultMutableTreeNode("The Java Series");
createNodes(top);
//Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
//Listen for when the selection changes.
tree.addTreeSelectionListener(this);
if (playWithLineStyle) {
System.out.println("line style = " + lineStyle);
tree.putClientProperty("JTree.lineStyle", lineStyle);
}
//Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
//Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
//Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100);
splitPane.setPreferredSize(new Dimension(500, 300));
//Add the split pane to this panel.
add(splitPane);
}
/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf()) {
BookInfo book = (BookInfo)nodeInfo;
displayURL(book.bookURL);
if (DEBUG) {
System.out.print(book.bookURL + ": \n ");
}
} else {
displayURL(helpURL);
}
if (DEBUG) {
System.out.println(nodeInfo.toString());
}
}
private class BookInfo {
public String bookName;
public URL bookURL;
public BookInfo(String book, String filename) {
bookName = book;
bookURL = getClass().getResource(filename);
if (bookURL == null) {
System.err.println("Couldn't find file: "
+ filename);
}
}
public String toString() {
return bookName;
}
}
private void initHelp() {
String s = "TreeDemoHelp.html";
helpURL = getClass().getResource(s);
if (helpURL == null) {
System.err.println("Couldn't open help file: " + s);
} else if (DEBUG) {
System.out.println("Help URL is " + helpURL);
}
displayURL(helpURL);
}
private void displayURL(URL url) {
try {
if (url != null) {
htmlPane.setPage(url);
} else { //null url
htmlPane.setText("File Not Found");
if (DEBUG) {
System.out.println("Attempted to display a null URL.");
}
}
} catch (IOException e) {
System.err.println("Attempted to read a bad URL: " + url);
}
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode category = null;
DefaultMutableTreeNode book = null;
category = new DefaultMutableTreeNode("Books for Java Programmers");
top.add(category);
//original Tutorial
book = new DefaultMutableTreeNode(new BookInfo
("The Java Tutorial: A Short Course on the Basics",
"tutorial.html"));
category.add(book);
//Tutorial Continued
book = new DefaultMutableTreeNode(new BookInfo
("The Java Tutorial Continued: The Rest of the JDK",
"tutorialcont.html"));
category.add(book);
//JFC Swing Tutorial
book = new DefaultMutableTreeNode(new BookInfo
("The JFC Swing Tutorial: A Guide to Constructing GUIs",
"swingtutorial.html"));
category.add(book);
//Bloch
book = new DefaultMutableTreeNode(new BookInfo
("Effective Java Programming Language Guide",
"bloch.html"));
category.add(book);
//Arnold/Gosling
book = new DefaultMutableTreeNode(new BookInfo
("The Java Programming Language", "arnold.html"));
category.add(book);
//Chan
book = new DefaultMutableTreeNode(new BookInfo
("The Java Developers Almanac",
"chan.html"));
category.add(book);
category = new DefaultMutableTreeNode("Books for Java Implementers");
top.add(category);
//VM
book = new DefaultMutableTreeNode(new BookInfo
("The Java Virtual Machine Specification",
"vm.html"));
category.add(book);
//Language Spec
book = new DefaultMutableTreeNode(new BookInfo
("The Java Language Specification",
"jls.html"));
category.add(book);
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
private static void createAndShowGUI() {
if (useSystemLookAndFeel) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.err.println("Couldn't use system look and feel.");
}
}
//Create and set up the window.
JFrame frame = new JFrame("TreeDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new TreeDemo());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
可以用Image中的getScaledInstance方法得到一个按照指定宽度和高度缩放以后的Image实例,然后再用setImage方法设置ImageIcon所显示的图像。
private final static int WIDTH=147;
private final static int HEIGHT=136;
img=new ImageIcon("1.png");
img.setImage(img.getImage().getScaledInstance(test.WIDTH,test.HEIGHT,Image.SCALE_DEFAULT));
showImg=new JLabel();
showImg.setIcon(img);
1.下载相关软件
2.建立共享目录
3.修改该配置文件
4.重启服务
5.测试服务器
6.测试客户端
7。卸载nfs
测试系统:Ubuntu11.10
1.下载相关软件
使用如下命令,可以在ubuntu下很方便的获取并安装相关软件(经过试验,还是都安装的好)
#sudo apt-get install protmap nfs-kernel-server nfs-common
如果是要客户端和服务器端分开,可以使用如下命令
服务器端:
#sudo apt-get install portmap nfs-kernel-server
客户机端:
#sudo apt-get install portmap nfs-common
2.建立共享目录 (这一步我当时配置时没有用到)
#sudo mkdir /nfsboot
#sudo chmod 777 /nfsboot
3.修改该配置文件
刚安装完配置文件只有一些说明,其路径是:/etc/exports
#gedit /etc/exports
在文档末尾加:
/nfsboot *(rw,async,no_subtree_check,no_root_squash)
说明:
/nfsboot是要共享的目录
*代表允许所有的网络段访问(也可一制定特定网段,如192.168.11.*)
rw是可读写权限
sync是资料同步写入内存和硬盘
no_root_squash是NFS客户端分享目录使用者的权限,如果客户端使用的是root用户,那么对于该共享目录而言,该客户端就具有root权限
最后重新扫描配置文件,使用户修改/etc/exports配置文件不必重启NFS服务(这一不好像也没有用到)
#sudo exportfs -ra
4.重启服务
使用如下命令重启一下服务
#sudo /etc/init.d/portmap restart
#sudo /etc/init.d/nfs-kernel-server restart
5.测试服务器
查看服务目录和权限
#showmount -e
我得到的结果是:
Export list for ubuntu:
/nfsboot *
6.测试客户端
在/nfsboot里新建文件,主要是作测使用
#touch /nfsboot/testfile
在其他分区挂载nfs文件系统,记得该目录要先存在才行
#sudo mount -t nfs 127.0.0.1:/nfsboot /mnt(注意:nfsboot与/mnt之间有空格,当时试验了n次都不对就是因为这一个问题)
查看一下:(其中代表本主机)
#ls /mnt
testfile
如何关闭还未试验成功
7.卸载nfs
sudo umount /mnt/12
说明:/mnt/12 表示:本地挂在的路径