yhc's Blog

Simple Fast Strong & Friendly
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ubuntu10.04各种问题

Posted on 2012-09-26 23:08  yhcvb  阅读(1696)  评论(2)    收藏  举报

1、Ubuntu 10.04 修改主机名 hosname

关键字: Linux Ubuntu 主机名 hostname /etc/hostname /etc/hosts Unable to resolve hostname

一.需要修改两个地方
/etc/hostname
/etc/hosts

shily@hh-laptop:~$ cat /etc/hostname
hh-laptop
shily@hh-laptop:~$ cat /etc/hosts
127.0.0.1    localhost.localdomain    localhost
127.0.1.1    hh-laptop

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
shily@hh-laptop:~$

其中深色的地方需要统一, 否则会出现 Unable to resolve hostname的错误


二. 新建hostname的脚本[把下面内容保存文本中,并添加执行权限]

#!/bin/sh
host_name=`hostname`
host_name_new=
read -p "Input the new hostname[$host_name]: " host_name_new
echo "the hostname new you input is: $host_name_new"

if [ "$host_name_new" != "" ] && [ "$host_name_new" != "$host_name" ]
then
sed -i-`date '+%Y%m%d%H%M'` 's/'${host_name}'/'${host_name_new}'/g'  /etc/hostname  /etc/hosts
if [ $? -eq 0 ]
then
echo "hostname changed from [$host_name] to [$host_name_new]."
else
echo "execute error, are you root?"
fi
else
echo "hostname doesn't changed, leave [$host_name] default."
fi

 

2、ubuntu更新源

1. sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup (备份下当前的源列表,有备无患嘛) 首先备份Ubuntu 11.10源列表 

2. 有图形界面的话执行 sudo gedit /etc/apt/sources.list       如果是字符界面执行  sudo vi /etc/apt/sources.list 编辑你的源列表,将原来的内容全部删除,添加下面列表中最适合你的源(注意不要全部添加),选择一个最合适你的即可,复制到你的列表中,然后保存列表。 将下面的代码粘贴进去(“#”开头的那一行为注释,可以直接复制进文件中)

3. sudo apt-get update 更新源列表信息 可以在运行“sudo apt-get update ”时查看一下错误信息,把不能连接的源删除再重新运行“sudo apt-get update ”。

4. sudo apt-get upgrade 升 级或者用ubuntu自带的更新管理器升级也可以

电子科技大学Ubuntu镜像服务http://ubuntu.uestc.edu.cn/

 ubuntu10.04更新源

1.sudo gedit /etc/apt/sources.list

  编辑你的源列表,将原来的内容全部删除,添加下面列表中最适合你的源(注意不要全部添加),选择一个最合适你的即可,复制到你的列表中,然后保存列表。

  2.sudo apt-get update 更新源列表信息

  可以在运行“sudo apt-get update ”时查看一下错误信息,把不能连接的源删除再重新运行“sudo apt-get update ”。

  3.sudo apt-get upgrade 升 级或者用ubuntu自带的更新管理器升级也可

  Ubuntu 10.04源列表:

  网易(速度很快)

  代码:

deb http://mirrors.163.com/ubuntu/ lucid main universe restricted multiverse

deb-src http://mirrors.163.com/ubuntu/ lucid main universe restricted multiverse

deb http://mirrors.163.com/ubuntu/ lucid-security universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ lucid-security universe main multiverse restricted

deb http://mirrors.163.com/ubuntu/ lucid-updates universe main multiverse restricted

deb http://mirrors.163.com/ubuntu/ lucid-proposed universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ lucid-proposed universe main multiverse restricted

deb http://mirrors.163.com/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ lucid-updates universe main multiverse restricted

  搜狐

  代码:

deb http://mirrors.shlug.org/ubuntu/ lucid main universe restricted multiverse

deb-src http://mirrors.shlug.org/ubuntu/ lucid main universe restricted multiverse

deb http://mirrors.shlug.org/ubuntu/ lucid-security universe main multiverse restricted

deb-src http://mirrors.shlug.org/ubuntu/ lucid-security universe main multiverse restricted

deb http://mirrors.shlug.org/ubuntu/ lucid-updates universe main multiverse restricted

deb http://mirrors.shlug.org/ubuntu/ lucid-proposed universe main multiverse restricted

deb-src http://mirrors.shlug.org/ubuntu/ lucid-proposed universe main multiverse restricted

deb http://mirrors.shlug.org/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirrors.shlug.org/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirrors.shlug.org/ubuntu/ lucid-updates universe main multiverse restricted

  SRT Sources

  代码:

deb http://ubuntu.srt.cn/ubuntu/ lucid main restricted universe multiverse

deb http://ubuntu.srt.cn/ubuntu/ lucid-security main restricted universe multiverse

deb http://ubuntu.srt.cn/ubuntu/ lucid-updates main restricted universe multiverse

deb http://ubuntu.srt.cn/ubuntu/ lucid-proposed main restricted universe multiverse

deb http://ubuntu.srt.cn/ubuntu/ lucid-backports main restricted universe multiverse

deb-src http://ubuntu.srt.cn/ubuntu/ lucid main restricted universe multiverse

deb-src http://ubuntu.srt.cn/ubuntu/ lucid-security main restricted universe multiverse

deb-src http://ubuntu.srt.cn/ubuntu/ lucid-updates main restricted universe multiverse

deb-src http://ubuntu.srt.cn/ubuntu/ lucid-proposed main restricted universe multiverse

deb-src http://ubuntu.srt.cn/ubuntu/ lucid-backports main restricted universe multiverse

  ubuntu官方上海源

  代码:

deb http://mirror.rootguide.org/ubuntu/ lucid main universe restricted multiverse

deb-src http://mirror.rootguide.org/ubuntu/ lucid main universe restricted multiverse

deb http://mirror.rootguide.org/ubuntu/ lucid-security universe main multiverse restricted

deb-src http://mirror.rootguide.org/ubuntu/ lucid-security universe main multiverse restricted

deb http://mirror.rootguide.org/ubuntu/ lucid-updates universe main multiverse restricted

deb http://mirror.rootguide.org/ubuntu/ lucid-proposed universe main multiverse restricted

deb-src http://mirror.rootguide.org/ubuntu/ lucid-proposed universe main multiverse restricted

deb http://mirror.rootguide.org/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirror.rootguide.org/ubuntu/ lucid-backports universe main multiverse restricted

deb-src http://mirror.rootguide.org/ubuntu/ lucid-updates universe main multiverse restricted

3、SecureCrt and ubuntu

(一)配置SecureCrt 和 ubuntu
1. 首先要明白什么是ssh?
可以把ssh看做是telnet的加强版,telnet的密码和信息都是不加密的,而ssh则加密。
2. 开启ubuntu上的ssh功能
先安装,安装后就自动开启了.
sudo apt-get install openssh-server openssh-client
3. 安装secureCRT
4. 查看ubuntu的ip
ifconfig(注意是ifconfig,不是windows上的ipconfig)
5. 连接
secureCRT => Quick Connect, 连接ubuntu, 输入ubuntu的id和pwd
6. 汉字乱码问题的解决
连接成功了,发现secureCRT对汉字显示乱码。google了下,好像说ubuntu 2.6 kernel的ssh默认编码是utf8,而secureCRT的默认显示编码好像不是utf8,那么只要把secureCRT的显示编码修改成utf8就可以正确显示了。在secureCRT中,选择option->session option->apperance里把字符编码改成utf8。

(二)wmware配置,可以让别的机器使用SecureCrt连上来
vmware网络配置环境:Windows XP 上用Vmware安装Linux(windows host + linux guest )vmware网络配置步骤:

1. 在vmware workstation上安装Linux的时候,网络接口选hostonly(如果你已经安装好 了,用了nat或bridge也没有关系,在虚拟机的属性里改成hostonly就行了。)

2. 到windows XP中查看网络连接,你会发现除了原有的网卡之外,又多了Vmnet1和Vmnet8。如果你看了一下说明书应该知道,vmnet1是hostonly的接口,而Vmnet8是使用NAT的网络接口。在这里我们既不想用VMWARE自带的DHCP也不想用他的NAT所以我们只关心VMnet1 。

3. 查看你的连接外网的网卡的属性,选择“高级”标签,设置成允许共享,并设定允许的网络接口VMNET1。

4. 再看一下你的VMnet1 的属性,看一下TCP/IP协议的设置,会发现已经被自动设置为192.168.0.1/255.255.255.0,如下图。

5. windows下的设置完成,转入到跑Linux的虚拟机。将你的eth0的ip地址设置为静态的(如果安装时没有选静态的话)

vmware 网络配置 原理简述:
使用hostonly这个网络接口连接虚拟机和主机,然后利用windows Xp/2000里面自带的internet连接共享(实际上是一个简单的路由NAT)来让虚拟机 通过原来的网卡进行外网的访问。 

 

4、查看linux版本,内核版本,系统位数,gcc版本

1. 查看linux版本

  sunny@ubuntu:~$cat /etc/issue
Ubuntu 11.04 \n \l

 

2. 查看内核版本

1) sunny@ubuntu:~$ cat /proc/version
Linux version 2.6.38-13-generic (buildd@rothera) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) ) #57-Ubuntu SMP Mon Mar 5 18:10:14 UTC 2012

2)  uname命令

sunny@ubuntu:~$ uname -a
Linux ubuntu 2.6.38-13-generic #57-Ubuntu SMP Mon Mar 5 18:10:14 UTC 2012 i686 i686 i386 GNU/Linux

 

[ -------------------------------------------------------------------------------
  -a, --all                print all information, in the following order,       查看全部信息
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name                               查看内核名字
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release                              查看内核发行版本
  -v, --kernel-version     print the kernel version                              查看内核版本
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"           
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system                      查看操作系统
      --help     display this help and exit
      --version  output version information and exit

--------------------------------------------------------------------------------------]

 

3.查看系统位数

1) sunny@ubuntu:~$ getconf WORD_BIT
32

2)sunny@ubuntu:~$ file /bin/bash
/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

 

4. 查看gcc版本

sunny@ubuntu:~$ gcc --version
gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2

 

如何解决Ubuntu上压缩包乱码问题

安装Linux版7zip:

 

sudo apt-get install p7zip p7zip-full p7zip-rar

 

  卸载可能安装过的rar相关包(默认是没有安装的):

 

sudo apt-get remove rar unrar

 

  经过这样操作,以后解压rar和zip文件时,file-roller(归档管理器)自动会调用7z来解压,而7z能识别中文编码,不会出现乱码,解压和压缩都通过图形程序file-roller操作,完全不用涉及命令行。

 

  如果不卸载掉rar,file-roller默认使用rar解压,而rar不能识别中文编码,所以可能会出现乱码。当然你也就不能在Linux上创建rar文件了,但有必要打包成rar格式吗?

 

  unrar虽然能识别中文编码,但它和rar一样不是自由软件,它们都是WinRAR那家公司的商业软件,既然7z能解压rar文件,我又何必用它呢?

 

  总之file-roller默认使用7z解压7z/rar/zip,创建7z/zip包时也是使用7z,所以统一使用7z格式能保证自己的压缩包不会乱码。在Linux创建7z包时,也可以像Windows版那样加密压缩包目录。

 解压zip文件:
#好像第一句就起效果了
LANG=C 7z e zip_file
convmv -f gbk -t utf8 -r --notest *
使用第一行命令时会解压出一些乱码文件,此时输入第二行命令即可将这些乱码处理掉,

ubuntu zip 文件乱码解决 压缩乱码

1.1 通过unzip行命令解压,指定字符集

unzip -O CP936 xxx.zip (用GBK, GB18030也可以)
有趣的是unzip的manual中并无这个选项的说明, unzip --help对这个参数有一行简单的说明。

1.2 在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件
解决办法: 引用 vi /etc/environment
再最后加入后面的代码即可 UNZIP="-O CP936"
ZIPINFO="-O CP936"

 

 

安装ubuntu-tweak

Ubuntu Tweak is an application to config Ubuntu easier for everyone.

It provides many useful desktop and system options that the default desktop environment doesn't provide.

With its help, you will enjoy with the experience of Ubuntu!

第一步:添加tweak源
sudo add-apt-repository ppa:tualatrix/ppa
 
第二步:更新
sudo apt-get update
 
第三步:安装ubuntu-tweak
 
sudo apt-get install ubuntu-tweak
 

安装kscope1.6

1、下载kscope包

 

kscope-1.6.0.tar.gz包括了kscope_1.6.0-1_i386.deb 和 kate_3.5.9.dfsg.1-6_i386.deb

2、解压kscope-1.6.0.tar.gz后,直接安装kscope_1.6.0-1_i386.deb

3、完成后在终端输入:
  tar x kate_3.5.9.dfsg.1-5_i386.deb
  tar xzf data.tar.gz
  然后把libkateinterfaces.so.0.0.0 和 libkateutils.so.0.0.0
  拷到下面的目录
  /usr/local/lib
  sudo mv libkateinterfaces.so.0.0.0 libkateutils.so.0.0.0 /usr/local/lib
  记住也要sudo ldconfig
  如果没有意外的话,这时应该能运行Kscope.

--------------------------------------------------------------------------------------------------------------

安装1.6.2

下载skcope 的程序;最新版不好用,所有就是用1.6.2 版本 


http://download.chinaunix.net/download/0006000/5469.shtml

下载完解压;

tar zxvf kscope-1.6.2.tar.gz


cd kscope-1.6.2

执行 ./configure
结果如下
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for -p flag to install... yes
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for kde-config... not found
configure: error: The important program kde-config was not found!
Please check whether you installed KDE correctly.
 

最后两行出现错误这是因为少了 如下这个库;
kdelibs4c2a

直接 sudo apt-get install kdelibs4c2a安装

然后 从新出现问题了 

checking for X... configure: error: Can't find X includes. Please check your installation and add the correct paths!
lipeng@lipeng-desktop:~/Downloads/kscope-1.6.2$ sudo apt-get install libx11-dev xorg-dev

sudo apt-get install libx11-dev xorg-dev


checking for Qt... configure: error: Qt (>= Qt 3.3 and < 4.0) (headers and libraries) not found. Please check your installation!
For more details about this problem, look at the end of config.log.

原因:系统中没有软件所需的Qt 
直接输入如下命令安装
sudo apt-get install qt3-apps-dev


checking for KDE... configure: error:
in the prefix, you've chosen, are no KDE headers installed. This will fail.
So, check this please and use another prefix!

原因:在Gnome 环境中安装 KDE 应用程序
解决: 
sudo apt-get update
udo apt-get install kdelibs4-dev kdelibs4c2a 

 

configure error: The important program mcopidl was not found!
Please check whether you installed aRts correctly or use
--without-arts to compile without aRts support(this will remove functionality)


使用 ./configure --without-arts

error: Lex/Flex is required in order to build KScope
解决办法:
sudo apt-get install flex


安装完后:
Good - your configure finished. Start make now
此时 已经成功,可以make 了;

如果你安装了4.0以上版本,则在make 的时候可能出现如下错误:

File generated with too old version of Qt Designer (3.3)

此时 可以重新设置一下环境变量:(以上默认Qt3.3 的qmake 默认安装在如下目录)

export QTDIR=/usr/bin  

 

继续make错误1: /usr/bin/ld: cannot find -lkateinterfaces

  make时提示找不到 -lkateinterfaces,不用担心,该参数是要找动态链接库,其实没有动态链接库,只有静态链接库,该库位于/usr/lib/libkatepartinterfaces.la,这个时候,切换到src目录下:

  [ /home/lanch/Download/kscope-1.6.2]$cd src

  [ /home/lanch/Download/kscope-1.6.2/src]$grep -n -lkateinterfaces Makefile

  将Makefile文件中使用-lkateinterfaces 的地方,替换为/usr/lib/libkatepartinterfaces.la,接着,退回到上层目录cd ,进行make,就会大功告成。

  5. sudo make install

  这个过程中没现过错误。

  6. 安装cscope,ctags,graphviz

  sudo apt-get install cscope ctags graphviz

  到此安装kscope1.6.2完成,可以在终端中输入kscope打开kscope1.6.2了,当然你可以作成一个快捷方式,这里就不再说明。

http://blog.csdn.net/huwen415/article/details/7655575