Linux 配置和管理

来源:互联网 发布:ubuntu最新版本是多少 编辑:程序博客网 时间:2024/04/29 03:54

Linux 配置和管理

索引

远程X
远程桌面
安装.src.rpm
HTTP服务器
USB设备
分区和创建文件系统
Mount
SSH登录不用输密码的方法
rsync
cron
Squid
TIPS

远程X

假设你想在本地(本地IP:192.168.0.1)运行192.168.0.2的X应用程序,首先在本地xhost +192.168.0.2,允许192.168.0.2连接本地的X Server(xhost的具体用法manxhost),然后登录到192.168.0.2上,exportDISPLAY=192.168.0.1:0。然后就可以在本地使用192.168.0.2的X应用程序了。

远程桌面

使用VNC。VNC既有Linux版,也有Windows版,所以就可以互相启动远程桌面了。

假设在本地192.168.0.1上远程使用192.168.0.2的桌面,两台机器上都装上VNC。

首先在192.168.0.2上,vncpasswd设置登录密码。然后启动vncserver(不需要root权限,每个用户可以启动自己的server),记住端口号(这儿是192.168.0.2:1)。修改$HOME/.vnc/xstartup文件,注释掉所有行,在最后加上一行startkde &,就可以使用KDE桌面了。当然可以使用其它窗口管理器,默认是twm。

在192.168.0.1上,执行vncviewer 192.168.0.2:1,就可以了。

关闭vncserver:vncserver -kill :1 (1是display number, man vncserver)

安装.src.rpm

有些软件包是以.src.rpm结尾的,这类软件包是包含了源代码的rpm包,在安装时需要进行编译。这类软件包有两种安装方法:

方法一:

1. 执行rpm -i your-package.src.rpm

2. cd /usr/src/redhat/SPECS

3. rpmbuild -bp your-package.specs 一个和你的软件包同名的specs文件

4. cd /usr/src/redhat/BUILD/your-package/ 一个和你的软件包同名的目录

5. ./configure 这一步和编译普通的源码软件一样,可以加上参数

6. make

7. make install

方法二:

1. 执行rpm -i you-package.src.rpm

2. cd /usr/src/redhat/SPECS (前两步和方法一相同)

3. rpmbuild -bb your-package.specs 一个和你的软件包同名的specs文件

这时,在/usr/src/redhat/RPM/i386/ (根据具体包的不同,也可能是i686,noarch等等) 在这个目录下,有一个新的rpm包,这个是编译好的二进制文件。执行:rpm -i new-package.rpm即可安装完成。

HTTP服务器

用户主页设置

(from httpd.conf)

The name of the directory that is appended onto a user's home directory if a ~user request is received.

The path to the end user account 'public_html' directory must beaccessible to the webserver userid. This usually means that ~useridmust have permissions of 711, ~userid/public_html must have permissionsof 755, and documents contained therein must be world-readable.Otherwise, the client will only receive a "403 Forbidden" message.

不过首先需要将允许用户主页设置的UserDir选项打开。

USB设备

连接上USB存储设备后,首先执行 fdisk -l/dev/sda,如果能看到sda1,sda2等分区的信息,则说明分区识别成功,按照普通分区mount即可;mount -oiocharset=gb2312,umask=0 /dev/sda /mnt/usb, 解决中文显示问题,其他用户可写。

如果重复使用两种USB设备,则第二个设备应为/dev/sdb。

分区和创建文件系统

一次具体操作过程:(创建新分区和新文件系统,并将/home挂载到该分区上)

/sbin/fdisk /dev/sda分区;

/sbin/mkfs -t ext3 /dev/sda7创建文件系统(作用类似于windows下的format)

修改/etc/fstab,将/home mount到该分区上

/sbin/fdisk /dev/sdb分区;

/sbin/mkfs -t ext3 /dev/sdb2创建文件系统(作用类似于windows下的format)

修改/etc/fstab,将/misc mount到该分区上

mount -t vfat /dev/hda1 /mnt/disk_c

Mount

fat32的分区:mount -o codepage=936,iocharset=cp936 /dev/hda7 /mnt/cdrom

ntfs分区用上述方法可显示部分中文,2.6内核需要用nls=cp936参数

iso文件 :mount -o loop /abc.iso /mnt/cdrom

软盘 :mount /dev/fd0 /mnt/floppy

USB闪存 :mount /dev/sda1 /mnt/cdrom

所有/etc/fstab内容 mount -a

注:mount时可以指定文件格式"-t 格式", 格式可以为vfat, ext2, ext3等.

SSH登录不用输密码的方法

首先生成dsa的密钥对:ssh-keygen -t dsa

输出:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/sj/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sj/.ssh/id_dsa.
Your public key has been saved in /home/sj/.ssh/id_dsa.pub.
The key fingerprint is:
1b:8c:3d:6d:eb:e3:10:c3:b7:c0:68:a3:5f:7e:b3:51 sj@192.168.0.1

然后把其中的公钥加入到远程机器的.ssh/authorized_keys文件中。如果authorized_keys文件不存在,直接将公钥复制即可,比如: scp .ssh/id_dsa.pub 192.168.0.2:.ssh/authorized_keys。

还有ssh-agent的方法,暂无研究。

rsync

可以用于备份文件。

我用这个把我的主页定期更新到服务器,如:

rsync -e ssh -av --delete ~/WiKi/publish net:~/

cron

cron可以用来建立能够按照指定的时间或时间间隔定期执行的作业。所以如果你想要定期让计算机干什么,就需要这个工具了。

每个用户使用crontab -e的命令来编辑你自己的crontab文件,文件中每一行是一个你要运行的作业,格式如下:

minute  hour  dayofmonth  month  dayofweek  command

minute: 从0到59之间的一个值
hour: 从0到23之间的一个值
dayofmonth: 从1到31之间的一个值
month: 从1到12之间的一个值
dayofweek: 从0到6之间的一个值(0表示星期天)
command: 在指定时间执行的命令
(上面的日期和时间域中可以使用*号,表示该域为true)

举例:
0 1 * * * echo "It is 1 am"
将会使得crontab的文件的所有者在每天1点接收到一个电子邮件,如果不想用邮件,可以把命令的输出重定向的文件。

Squid

配置HTTP代理服务器,参考文档。

- Starting Squid -

After you've finished editing the configuration file, you can start
Squid for the first time. First, you must create the swap directories.
Do this by running Squid with the -z option:

/usr/local/squid/sbin/squid -z

Once that completes, you can start Squid and try it out. Probably the
best thing to do is run it from your terminal and watch the debugging
output. Use this command:

/usr/local/squid/sbin/squid -NCd1

If everything is working okay, then your console displays: "Ready to
serve requests".

If you want to run squid in the background, as a daemon process, just
leave off all options:

/usr/local/squid/sbin/squid

Here depending on your configuration, you may need to start squid as root.

TIPS

修改系统时间:

date -s 11:10:00 +"%T" 或者 date --set=11:10:00 +"%T"
修改主机名:

uname可以查询主机信息,hostname可以修改主机名;

修改/etc/sysconfig/network,将HOSTNAME一行改为HOSTNAME=主机名,重启后也能生效;

在终端下输入hostname <nop>YourNewHostname,也能暂时生效;但是重起后失效。
一些配置文件:

/etc/sysctl.conf:可以关闭ping等;

/etc/inittab:修改运行级别,运行级别3时系统进入命令行模式,运行级别5时系统进入图形化界面;

/etc/xinetd.d:修改相应服务的disable参数,可以关闭或打开相应服务;
ssh和sftp指定端口:

sftp -oPort=2000 lop
ssh -p 2000 lop
添加新的library路径:

after modify /etc/ld.so.conf, run /sbin/ldconfig to update the dynamic loader cache.

or set environment variable: LD_LIBRARY_PATH
查看系统版本:

cat /proc/version to see kernel version and distribution.