qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

两种Linux系统下配置路由信息服务器的方法

 路由器作为骨干网络核心交换设备之一,在网络中充当着网络交通站的职责,它将网络数据包通过既定规则进行转发和交换,从而使网络客户端节点设备能有效使用网络来进行信息的交换和交流。这样,网络中路由器相关的配置参数就成为了非常重要的网络基础资料之一。我单位企业网属于中等规模广域网范畴,下级接入路由器及汇聚层路由器有几十台之多。这些路由器一旦故障需要进行硬件更换时,路由器配置资料的查找总是让人头痛的问题之一,为此笔者使用Linux系统提供的TFTP服务器及apache网页服务器结合规划配置了方便的路由资料备份系统解决以上问题。因为目前主流的Linux系统基本是由RedHat及Debian衍生出来的发行版。所以笔者分别就以上两个操作系统的配置进行叙述,希望能给其他用户以帮助。

  一、Debian下配置TFTP及apache服务器

  (一)TFTP服务器配置

  1、TFTP服务器组件安装

  在Debian中可以使用新立得软件包管理器搜索tftpd-hpa软件包,并勾选“标记以便安装”选项,然后点击应用按扭,系统将自动进行该组件包的安装。用户也可是直接再命令行下执行apt-get install tftpd-hpa来进行安装命令模式如下:

root@AkBirdofpreyWorkStation:~# apt-get install tftpd-hpa

  之后系统将创建相关的应用启动脚本及配置文件,并会在跟目录下创建/srv/tftp目录。

  2、TFTP配置文件及相关目录权限修改

  系统安装完TFTP服务组件后,会自动创建TFTP服务需要的用户组及配置文件,该文件为/etc/default/tftpd-hpa,初始配置内容如下:

  1. # /etc/default/tftpd-hpa 
  2. TFTP_USERNAME="tftp" 
  3. TFTP_DIRECTORY="/srv/tftp" 
  4. TFTP_ADDRESS="0.0.0.0:69" 
  5. TFTP_OPTIONS="-secure"

  我们需要将该文件修改为如下内容:

  1. # /etc/default/tftpd-hpa 
  2. TFTP_USERNAME="tftp" 
  3. TFTP_DIRECTORY="/srv/tftp" 
  4. TFTP_ADDRESS="0.0.0.0:69" 
  5. TFTP_OPTIONS="-l -c -secure"

  其中在TFTP_OPTIONS选项中加入了-l -c参数,这样当我们使用路由器参数备份命令时,可以将文件顺利的上传之TFTP服务器目录。

  于此同时我们需要修改TFTP服务器指定目录的用户及属组,命令模式如下:

root@AkBirdofpreyWorkStation:/etc/default# chown tftp:tftp /srv/tftp

  这样/srv/tftp目录的属组就修改为了tftp用户,修改用户属组必须要进行,笔者测试中发现,TFTP服务组件安装后/srv/tftp目录的属组为root,如果不进行用户属组修改时,当使用路由器参数备份命令时,服务器将会出现transfer time out错误。

  此时只要使用/etc/init.d/tftpd-hpa restart重启TFTP服务,TFTP服务器应该就可以正常使用了,命令模式如下:

  1. root@AkBirdofpreyWorkStation:/etc/default# /etc/init.d/tftpd-hpa restart 
  2. [ ok ] Restarting HPA's tftpd: in.tftpd.
我们需要将它修改为如下内容:

  1. <VirtualHost *:80> 
  2. ServerAdmin webmaster@localhost 
  3. #DocumentRoot /var/www 
  4. DocumentRoot /srv/tftp 
  5. <Directory /> 
  6. Options FollowSymLinks Indexes 
  7. AllowOverride All 
  8. <limit GET POST OPTIONS PROPFIND> 
  9. Order allow,deny 
  10. Allow from all 
  11. </Limit> 
  12. </Directory> 
  13. #<Directory /var/www/> 
  14. #<Directory /var/www/> 
  15. #Options Indexes FollowSymLinks MultiViews 
  16. #AllowOverride None 
  17. #Order allow,deny 
  18. #allow from all 
  19. #</Directory> 
  20. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
  21. <Directory "/usr/lib/cgi-bin"> 
  22. AllowOverride None 
  23. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
  24. Order allow,deny 
  25. Allow from all 
  26. </Directory> 
  27. ErrorLog ${APACHE_LOG_DIR}/error.log 
  28. # Possible values include: debug, info, notice, warn, error, crit, 
  29. # alert, emerg. 
  30. LogLevel warn 
  31. CustomLog ${APACHE_LOG_DIR}/access.log combined 
  32. </VirtualHost>

  使用vi命令编辑/srv/tftp/.htaccess文件,命令模式如下:

root@AkBirdofpreyWorkStation:/# vi /srv/tftp/.htaccess

  文件内容如下:

  AuthUserFile /etc/secure.user  ##用户帐号密码文件名

  AuthName akcwdCA   用户登录认证信息提示

  AuthType Basic

  1. <Limit GET> 
  2. require valid-user 
  3. </Limit>

  使用htpasswd -c /etc/secure.user建立用户密码文件,命令模式如下:

root@AkBirdofpreyWorkStation:/# htpasswd -c /etc/secure.user user1

  程序会提示你输入两次用户的口令,然后用户密码文件就已经创建,user1这个用户也同时创建完成了。

  使用命令/etc/init.d/apache2 restart重启apache服务器,命令模式如下:

  1. root@AkBirdofpreyWorkStation:/# /etc/init.d/apache2 restart 
  2. [....] Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.253 for ServerName 
  3. ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.253 for ServerName 
  4. . ok

 

  (二)apache服务器服务器配置

  1、apache服务器服务器组件安装

  该组件安装和TFTP服务组件安装差别不大,用户可以选择图形界面或者命令行界面进行安装即可

  2、apache服务器服务器配置


  因为之前笔者一直较多的使用RedHat及其衍生Linux版本。使用Debian/Linux系统后发现apache服务器配置文件与RedHat及其衍生Linux版本apache服务器配置文件差别很大,Debian/Linux系统的apache服务器配置文件没有被集中在像httpd.conf文件中,而是被分别放置在了不同的配置文件里。因为路由器资料涉及到安全性问题,因此我们配置的apache服务器访问时需要进行用户安全审核,下面我们来做具体配置。

  Debian/Linux系统的apache服务器配置文件保存在/etc/apache2中,使用vi /etc/apache2/apache2.conf查看帮助中的对该目录结构对应配置文件的说明,我们需要修改的配置文件为 /etc/apache2/sites-enabled/000-default,该文件实际才是apache用户定义的配置文件,其中包括服务器目录以及访问权限等内容,初始配置文件为如下内容:

  1. <VirtualHost *:80> 
  2. ServerAdmin webmaster@localhost 
  3. DocumentRoot /var/www 
  4. <Directory /> 
  5. Options FollowSymLinks Indexes 
  6. AllowOverride None 
  7. </Directory> 
  8. <Directory /var/www/> 
  9. <Directory /var/www/> 
  10. Options Indexes FollowSymLinks MultiViews 
  11. AllowOverride None 
  12. Order allow,deny 
  13. allow from all 
  14. </Directory> 
  15. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
  16. <Directory "/usr/lib/cgi-bin"> 
  17. AllowOverride None 
  18. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
  19. Order allow,deny 
  20. Allow from all 
  21. </Directory> 
  22. ErrorLog ${APACHE_LOG_DIR}/error.log 
  23. # Possible values include: debug, info, notice, warn, error, crit, 
  24. # alert, emerg. 
  25. LogLevel warn 
  26. CustomLog ${APACHE_LOG_DIR}/access.log combined 
  27. </VirtualHost>

我们需要将它修改为如下内容:

  1. <VirtualHost *:80> 
  2. ServerAdmin webmaster@localhost 
  3. #DocumentRoot /var/www 
  4. DocumentRoot /srv/tftp 
  5. <Directory /> 
  6. Options FollowSymLinks Indexes 
  7. AllowOverride All 
  8. <limit GET POST OPTIONS PROPFIND> 
  9. Order allow,deny 
  10. Allow from all 
  11. </Limit> 
  12. </Directory> 
  13. #<Directory /var/www/> 
  14. #<Directory /var/www/> 
  15. #Options Indexes FollowSymLinks MultiViews 
  16. #AllowOverride None 
  17. #Order allow,deny 
  18. #allow from all 
  19. #</Directory> 
  20. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
  21. <Directory "/usr/lib/cgi-bin"> 
  22. AllowOverride None 
  23. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
  24. Order allow,deny 
  25. Allow from all 
  26. </Directory> 
  27. ErrorLog ${APACHE_LOG_DIR}/error.log 
  28. # Possible values include: debug, info, notice, warn, error, crit, 
  29. # alert, emerg. 
  30. LogLevel warn 
  31. CustomLog ${APACHE_LOG_DIR}/access.log combined 
  32. </VirtualHost>

  使用vi命令编辑/srv/tftp/.htaccess文件,命令模式如下:

root@AkBirdofpreyWorkStation:/# vi /srv/tftp/.htaccess

  文件内容如下:

  AuthUserFile /etc/secure.user  ##用户帐号密码文件名

  AuthName akcwdCA   用户登录认证信息提示

  AuthType Basic

  1. <Limit GET> 
  2. require valid-user 
  3. </Limit>

  使用htpasswd -c /etc/secure.user建立用户密码文件,命令模式如下:

root@AkBirdofpreyWorkStation:/# htpasswd -c /etc/secure.user user1

  程序会提示你输入两次用户的口令,然后用户密码文件就已经创建,user1这个用户也同时创建完成了。

  使用命令/etc/init.d/apache2 restart重启apache服务器,命令模式如下:

  1. root@AkBirdofpreyWorkStation:/# /etc/init.d/apache2 restart 
  2. [....] Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.253 for ServerName 
  3. ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.253 for ServerName 
  4. . ok

posted on 2013-06-08 12:23 顺其自然EVO 阅读(230) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年6月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜