显示标签为“Linux”的博文。显示所有博文
显示标签为“Linux”的博文。显示所有博文

2011年10月19日星期三

Linux中自动注销用户

当用户连上服务器后,如果中途走开了,闲置太久就不太好了,此时为了安全起见就需要自动注销当前已登录的用户

方法如下:
编辑用户主目录下面的.bashrc文件,添加如下一行即可:
TMOUT=1800      //表示当前用户多久不操作就注销当前用户,单位为秒

或者:
编辑/etc/profile文件,同样添加一行:
TMOUT=1800     //时间间隔根据不同的环境自行设定

TMOUT=0        //表示永不注销

注:/etc/profile文件中的TMOUT参数对全局有效,即对所有用户均有效;当用户主目录下的
      .bashrc也定义了TMOUT,则以.bashrc文件中的TMOUT值为准,.bashrc文件的优先级高于
      /etc/profile,如果希望root用户例外,可将root用户主目录中.bashrc文件的TMOUT值
      设为0即可。

      修改配置文件后记得source(或者.)一下,使之即时生效。

Debian下iptables的save、restart及永久保存

系统环境:Debian-6 32-bit
iptables是即时生效的,所以无需重启,如果要停止iptables,请使用iptables -F命令,如果要iptables配置重启后仍然有效,请按如下操作步骤:

1.创建/etc/iptables文件(文件名可以随意取)

2.创建/etc/network/if-pre-up.d/iptables文件,并给予其执行权限
root@godontop:~# touch /etc/network/if-pre-up.d/iptables
root@godontop:~# chmod +x /etc/network/if-pre-up.d/iptables

3.编辑/etc/network/if-pre-up.d/iptables文件,使其内容如下:
#!/bin/sh
/sbin/iptables-restore < /etc/iptables

4.配置iptables,过程略,配置好iptables后,将配置保存到/etc/iptables文件中即可
root@godontop:~# iptables-save > /etc/iptables

iptables -F  //将内存中iptables的所有配置清空,效果等同于停止了iptables

2011年10月16日星期日

Debian 5升级至Debian 6

1.使用Debian 5的网络版镜像(debian-5.0.0-i386-netinst.iso)进行最小化安装,下载地址:http://www.yunfile.com

2.系统安装好后,编辑/etc/apt/source.list文件,整个文件只需如下两行即可:
deb http://ftp.us.debian.org/debian/ squeeze main contrib
deb http://security.debian.org/ squeeze/updates main

3.下载Debian 6的PUBLIC KEY
wget http://ftp-master.debian.org/archive-key-6.0.asc

4.导入PUBLIC KEY,命令如下:
apt-key add archive-key-6.0.asc

5.更新源
apt-get update

6.更新现有软件包
apt-get upgrade 

7.更新内核
apt-cache search linux-image-2.6    //查找最适合的内核
apt-get install linux-image-2.6.32-5-686    //更新内核

8.安装udev,之后重启电脑
apt-get install udev

9.版本升级,之后再次重启电脑
apt-get dist-upgrade

注:更新的过程中报过一个小错误,说locale的设置不正确,但并没有影响系统版本的升级,
      可能是因为我很多东西都是选的美国的,但时区选的中国的原因吧,下次全选美国的,
      装好后再更改系统时区。

2011年10月12日星期三

为CentOS-5.5升级PHP到5.2.10

系统环境:CentOS-5.5-x86
PHP默认版本:5.1.6
因最新版的WordPress需要PHP-5.2.4以上版本,所以不得不升级PHP

1.编辑/etc/yum.repos.d/CentOS-Base.repo文件,将下面的内容添加到文件的末尾:
[CentOS-Testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

# CentOS-Testing:
# !!!! CAUTION !!!!
# This repository is a proving grounds for packages on their way to CentOSPlus 
# and CentOS Extras.
# They may or may not replace core CentOS packages, and are not guaranteed to 
# function properly.
# These packages build and install, but are waiting for feedback from testers as 
# to functionality and stability. Packages in this repository will come and go 
# during the development period, so it should not be left enabled or used on 
# production systems without due consideration. 

在CentOS-Base.repo文件中不要启用CentOS-Testing,必要的时候用yum的enablerepo参数就可以了,所以上面enabled参数后面的值是0.

2.检查CentOS-Testing中是否有关于PHP的可用更新;
yum --disablerepo=* --enablerepo=CentOS-Testing check-update php*

3.更新PHP相关的软件
yum --disablerepo=* --enablerepo=CentOS-Testing update php*

2011年10月10日星期一

编译PHP时提示:"configure:error:xml2-config not found. Please check your libxml2 installation."

系统环境:CentOS-5.5-x86

[root@huage php-5.3.8] # ./configure
configure:error:xml2-config not found. Please check your libxml2 installation.

[root@godontop ~]# rpm -qa |grep libxml2
libxml2-2.6.26-2.1.12
libxml2-python-2.6.26-2.1.2.8.el5_5.1

这里显示libxml2是安装了的,但仍提示libxml2可能没装,最后试着安装了libxml2-devel,结果成功编译。

注:如果在编译软件时,如果提示说"你的某个包没有安装",而这个包又的的确确存在于你的
    系统中,这时候很可能是你没有安装这个包对应的开发库(即:如果提示说:"你可
    能没有安装lzo这个软件包,而你系统里又确实装了lzo这个包,那么很可能是你没
    有安装lzo-devel这个包")。如果编译失败是因某个package-devel没有装导致的,系统
    并不会提示说"你的package-devel包没装",它只会提示说"你的package可能没装"。

2011年10月6日星期四

压缩与解压缩之tar

压缩与解压缩之tar
[root@huage ~]#tar -zcvf website.tgz public_html
将当前目录下的public_html目录打包并用gzip压缩,以website.tgz作为文件名

[root@huage ~]#tar -zxvf website.tgz
将website.tgz文件解压到当前目录

[root@huage ~]#tar -zxvf website.tgz -C /var/www
将website.tgz文件解压到指定目录"/var/www"

tar选项:
-z 用gzip压缩
-c 创建新的archive
-v 显示详细信息
-f 指定文件
-C change to directory

2011年9月30日星期五

linux中的cron服务

[root@huage ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 1 * * * root run-parts /etc/cron.daily
03 2 * * 0 root run-parts /etc/cron.weekly
04 3 1 * * root run-parts /etc/cron.monthly

       The first four lines are variables used to configure the environment in which the cron tasks are run. The SHELL variable tells the system which shell environment to use (in this example the bash shell), while the PATH variable defines the path used to execute commands. The output of the cron tasks are emailed to the username defined with the MAILTO variable. If the MAILTO variable is defined as an empty string (MAILTO=""), email is not sent. The HOME variable can be used to set the home directory to use when executing commands or scripts.
 
      As shown in the /etc/crontab file, the run-parts script executes the scripts in the /etc/cron.hourly/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly/ directories on an hourly, daily, weekly, or monthly basis respectively. The files in these directories should be shell scripts.

      If a cron task is required to be executed on a schedule other than hourly, daily, weekly, or monthly, it can be added to the /etc/cron.d/ directory. All files in this directory use the same syntax as /etc/crontab.

      Users other than root can configure cron tasks by using the crontab utility. All user-defined crontabs are stored in the /var/spool/cron/ directory and are executed using the usernames of the users that created them. To create a crontab as a user, login as that user and type the command crontab -e to edit the user's crontab using the editor specified by the VISUAL or EDITOR environment variable. The file uses the same format as /etc/crontab. When the changes to the crontab are saved, the crontab is stored according to username and written to the file /var/spool/cron/username.

      The cron daemon checks the /etc/crontab file, the /etc/cron.d/ directory, and the /var/spool/cron/ directory every minute for any changes. If any changes are found, they are loaded into memory. Thus, the daemon does not need to be restarted if a crontab file is changed.

Controlling Access to Cron
      The /etc/cron.allow and /etc/cron.deny files are used to restrict access to cron. The format of both access control files is one username on each line. Whitespace is not permitted in either file. The cron daemon (crond) does not have to be restarted if the access control files are modified. The access control files are read each time a user tries to add or delete a cron task.

      The root user can always use cron, regardless of the usernames listed in the access control files.

      If the file cron.allow exists, only users listed in it are allowed to use cron, and the cron.deny file is ignored.

      If cron.allow does not exist, users listed in cron.deny are not allowed to use cron.

2011年9月26日星期一

用screen命令来管理远程会话

screen -S http:创建一个名为http的会话
screen -ls:列出当前的所有screen会话
screen -d:分离所有会话,切换到Shell控制台
screen -d http:将名为http的会话分离出来
screen -r http:恢复一个状态为Detached的会话
screen -d -r http:先将一个状态为Attached的会话Detached掉,然后再Attached
screen -x   Attach to a not detached screen session. (Multi display mode).
screen -x http:将一个名为http且状态为Attached的screen会话Attach,之后所有处于http screen会话中的虚拟终端的所有操作都将同步,操作任何一个http screen会话,其他的http screen会话会显示相同的操作(适用于一人操作,其他人观看学习)

screen程序的快捷键:
Ctrl-a d:分离当前screen会话(先按住Ctrl,然后依次按a、d键),退到Shell控制台
exit:退出当前的screen终端

运维法则

1.使用screen命令来管理会话
在远程管理中为避免出现突然断开连接造成的损失,登录后应使用screen命令来创建和管理虚拟终端,这样即使断开了,之前的会话也可以恢复;

2.用script命令来记录屏幕输出
有些输出可能会因为显示的行太多而不会再显示,特别是在控制台操作时,所以登录终端后应使用script命令来记录所有操作及终端输出;

3.备份配置文件
在修改任何配置之前都应该先备份配置文件,当确认新的配置文件无误的时候,再删除备份的就配置文件;

2011年9月23日星期五

linux下踢出已登录用户

linux下踢出已登录用户
[root@huage ~]# pkill -kill -t pts/1
 pts/1代表用户登录的终端号,可以用w命令查看

[root@huage ~]# w
 16:26:42 up 3 min,  2 users,  load average: 0.01, 0.03, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.1.16     16:23    3:20   0.03s  0.00s man pkill
root     pts/2    192.168.1.16     16:24    0.00s  0.03s  0.00s w

2011年7月4日星期一

RPM specification file

rpm包的制作:
其实制作RPM软件包并不是一件复杂的工作(有点心虚^_^),其中的关键在于编写SPEC软件包描述文件。要想制作一个rpm软件包就必须写一个软件包描述文件(SPEC)。这个文件中包含了软件包的诸多信息,如软件包的名字、版本、类别、说明摘要、创建时要执行什么指令、安装时要执行什么操作、以及软件包所要包含的文件列表等等。
spec文件规范如下:
1)文件头
一般的spec文件头包含以下几个域:
Summary
用一句话概括该软件包尽量多的信息。
Name
软件包的名字,最终RPM软件包是用该名字与版本号、释出号及体系号来命名软件包的。
Version
软件版本号。仅当软件包比以前有较大改变时才增加版本号。
Release
软件包释出号。一般我们对该软件包做了一些小的补丁的时候就应该把释出号加1
Vendor
软件开发者的名字。
License
软件包所采用的版权规则。具体有:GPL(自由软件),BSDMITPublic Domain(公共域),Distributable(贡献),commercial(商业),Share(共享)等,一般的开发都写GPL
Group
软件包所属类别,具体类别有:
Amusements/Games (娱乐/游戏)
Amusements/Graphics(娱乐/图形)
Applications/Archiving (应用/文档)
Applications/Communications(应用/通讯)
Applications/Databases (应用/数据库)
Applications/Editors (应用/编辑器)
Applications/Emulators (应用/仿真器)
Applications/Engineering (应用/工程)
Applications/File (应用/文件)
Applications/Internet (应用/因特网)
Applications/Multimedia(应用/多媒体)
Applications/Productivity (应用/产品)
Applications/Publishing(应用/印刷)
Applications/System(应用/系统)
Applications/Text (应用/文本)
Development/Debuggers (开发/调试器)
Development/Languages (开发/语言)
Development/Libraries (开发/函数库)
Development/System (开发/系统)
Development/Tools (开发/工具)
Documentation (文档)
System Environment/Base(系统环境/基础)
System Environment/Daemons (系统环境/守护)
System Environment/Kernel (系统环境/内核)
System Environment/Libraries (系统环境/函数库)
System Environment/Shells (系统环境/接口)
User Interface/Desktops(用户界面/桌面)
User Interface/X (用户界面/X窗口)
User Interface/X Hardware Support (用户界面/X硬件支持)
Source
源程序软件包的名字。如 stardict-2.0.tar.gz
%description
软件包详细说明,可写在多个行上。
2%prep
这个段是预处理段,通常用来执行一些解开源程序包的命令,为下一步的编译安装作准备。%prep和下面的%build%install段一样,除了可以执行RPM所定义的宏命令(以%开头)以外,还可以执行SHELL命令,命令可以有很多行,如我们常写的tar解包命令。
3%build
本段是建立段,所要执行的命令为生成软件包服务,如make 命令。
4%install
本段是安装段,其中的命令在安装软件包时将执行,如make install命令。
5%files
本段是文件段,用于定义软件包所包含的文件,分为三类--说明文档(doc),配置文件(config)及执行程序,还可定义文件存取权限,拥有者及组别。

6%changelog
本段是修改日志段。你可以将软件的每次修改记录到这里,保存到发布的软件包中,以便查询之用。每一个修改日志都有这样一种格式:第一行是:星期 月 日 年 修改人电子信箱。其中:星期、月份均用英文形式的前3个字母,用中文会报错。接下来的行写的是修改了什么地方,可写多行。一般以减号开始,便于后续的查阅。

2011年6月22日星期三

RHEL-6下使用如何翻墙

1.使用firefox+autoproxy+tor即可;
2.以上是基本组件,为了更好的控制tor,还需要安装vidalia和privoxy,vidalia、privoxy和tor都属于第三方源;
3.tor位于RPMforge源中,且是针对RHEL-5的,不过6也可以用,privoxy位于RHEL-5的源中,vidalia位于EPEL的源中,版本为RHEL-5;


vidalia——GUI controller for the Tor Onion Routing Network
tor成功启动后会看到绿色的洋葱头标志,此时只要将autoproxy中的默认代理设置为tor,然后订阅一个gfwlist就可以访问被墙网站了。