商讯信箱
用户名: @
密  码:   注册|忘记密码
登录
个人用户经销商
信箱 E杂志
您的位置:首页 > 服务器专区 > 正文       

一个崭新的Linux服务器架设全过程(菜鸟篇)

作者:网络 佚名  2006-03-28   

  【IT168 服务器学院在朋友的推荐下,让我帮他一个兄弟去做台服务器!然后总结了点心得!写下来当笔记用。
   
  首先该哥们把我带到了机房,里面只有一个我不熟悉的环境,系统是FC4,没有用过,但是这次用过了,其实做过的就知道了,原理都是一样的。因为该服务器还没有正式运做起来,我就要求把该系统重做,因为他们把服务器全搞乱了,然后我最简安装了一下系统!所有个网络服务有关的选项都没有选择!
  接下来说说需要的工具!
  apache,mysql,php,vsftp,openssh为了给那位朋友对服务器维护带来方便,加了个webmin
   
  下面详细的说说:
   
   
  [root@localhost ~]# uname -a
  Linux localhost.localdomain 2.6.11-1.1369_FC4smp #1 SMP Thu Jun 2 23:08:39 EDT 2005 i686 i686 i386 GNU/Linux
  [root@localhost ~]# mysql
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 9 to server version: 4.1.18
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> \q
  Bye
  [root@localhost ~]#

  这样得到了mysql的版本和系统的信息。下面就下载mysql
   
  先下载Mysql2.1.18的源代码版,地址: http://dev.mysql.com/downloads/mysql/4.1.html
  把它下到/usr/local/src目录下,如果没有该目录,就自己建一个.下载回来的包名字叫 mysql-4.1.18.tar.gz,然后我们把它解压出来:
  # tar -zxvf mysql-4.1.18.tar.gz

  解压后生成mysql-4.1.18目录,我们进入该目录:

  # cd mysql-4.1.18

  进入后就开始配置mysql了,配置过程中我们要给mysql设置一个安装目录,我们设置在 /usr/local/mysql 下,以为把文件放到一个地方比较容易管理,如果你还想获得更多的配置信息,使用 ./configure --help:

  # ./configure --prefix=/usr/local/mysql

  然后等几秒钟,配置完成后就编译源代码:

  # make

  这个编译的过程比较长,如果机器比较慢的话,可能要近二十分种 ( PS:我的机器是很普通的机器,所有用了差不多15,6分种 ;) .
  编译完成后就安装:

  # make install

  # ./scripts/mysql_install_db --user=mysql #初试化表并且规定用mysql用户来访问

  # cd /usr/local/mysql

  # chown -R root .

  # /usr/local/mysql/bin/mysqld_safe --user=mysql &

  如果没有问题的话,应该会出现类似这样的提示:

  [1] 42264
  # Starting mysqld daemon with databases from /usr/local/mysql/var

  这就证明安装成功了

  为了每次系统重启后都能运行mysql,可以写一个脚本放到 /usr/local/etc/rc.d目录下,用来运行mysql,我们写一个脚本mysql_start.sh

  #! /bin/sh
  /usr/local/mysql/bin/mysqld_safe&

  然后保存到/usr/local/etc/rc.d目录下,那么以后reboot系统后都能启动mysql了.

  安装Apache要简单点,我这里安装的Apache版本是 httpd-2.0.55,去下载压缩包: http://httpd.apache.org/download.cgi.
  下载回来的包叫做 httpd-2.0.55.tar.gz 我们放在 /usr/local/src目录下.
  首先进入目录后解压缩:

  # cd /usr/local/src
  # tar -zxvf httpd-2.0.55.tar.gz

  然后就会得到 httpd-2.0.55目录,我们进入目录

  # cd httpd-2.0.55

  首先配置:

  # ./configure --prefix=/usr/local/apache --enable-shared=max --enable-module=rewrite --enable-module=so

  执行上面的命令,如果没有错误信息,证明配置成功,然后进行编译:

  #make

  #make install

  # /usr/local/apache/bin/httpd -k start  #启动apache
  # /usr/local/apache/bin/httpd -k stop  #停止apache
  # /usr/local/apache/bin/httpd -k restart #重启apache

  然后可以安装php了:

  [root@localhost ~]# php -v
  PHP 4.4.2 (cli) (built: Mar 28 2006 08:06:26)
  Copyright (c) 1997-2006 The PHP Group
  Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
  [root@localhost ~]#

  我使用的是php 4.4.2

  先去下载: http://www.php.net/downloads.php

  # ./configure --with-apxs2=/usr/local/apache/bin/apxs --disable-debug --enable-safe-mode --enable-trans-sid --with-xml --with-mysql --enable-short-tags --with-gd --with-zlib --with-jpeg --with-png --enable-memory-limit --disable-posix --with-config-file-path=/usr/local/lib

  开始提示没有libpng来着,后来去pbone下了一个安装上了!就没有错误提示了!

  然后出现了:

   

  +--------------------------------------------------------------------+
  |                        *** WARNING ***                             |
  |                                                                    |
  | You chose to compile PHP with the built-in MySQL support.  If you  |
  | are compiling a server module, and intend to use other server      |
  | modules that also use MySQL (e.g, mod_auth_mysql, PHP 3.0,         |
  | mod_perl) you must NOT rely on PHP's built-in MySQL support, and   |
  | instead build it with your local MySQL support files, by adding    |
  | --with-mysql=/path/to/mysql to your configure line.                |
  +--------------------------------------------------------------------+
  | License:                                                           |
  | This software is subject to the PHP License, available in this     |
  | distribution in the file LICENSE.  By continuing this installation |
  | process, you are bound by the terms of this license agreement.     |
  | If you do not agree with the terms of this license, you must abort |
  | the installation process at this point.                            |
  +--------------------------------------------------------------------+
  |                          *** NOTE ***                              |
  |            The default for register_globals is now OFF!            |
  |                                                                    |
  | If your application relies on register_globals being ON, you       |
  | should explicitly set it to on in your php.ini file.               |
  | Note that you are strongly encouraged to read                      |
  | http://www.php.net/manual/en/security.globals.php                  |
  | about the implications of having register_globals set to on, and   |
  | avoid using it if possible.                                        |
  +--------------------------------------------------------------------+

  Thank you for using PHP.

  这个就证明可以make了。

  #make

  #make install

  然后把php.ini-dist复制到/usr/local/lib/,并重命名为php.ini

  至于安全设置,这里就不多说了,xfocus里有很多相关的资料的!

  为了让Apache能够直接解析php,我们还要进行一些配置.
  首先进入apache的配置文件目录:

  # cd /usr/local/apache/conf

  然后用vi打开配置文件httpd.conf:

  # vi httpd.conf

  在httpd.conf文件中,添加

  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps

  应该将以上两句添加在其他AddType之后。

  确保文件中有以下一句话,没有就自己添加在所有LoadModule之后。

  LoadModule php4_module  modules/libphp4.so

  好了,在vi中使用":wq"保存httpd.conf文件,退出vi。启动apache server:

  # /usr/local/apache/bin/httpd start

  现在apache就能够运行php了,写个文件测试一下,在/usr/local/apache/htdocs目录下,新建一个phpinfo.php文件,
  文件中只有一行代码:

  <? phpinfo(); ?>

  浏览http://ip/phpinfo.php

  然后就可以看到我们的测试页了

  默认的首页在/usr/local/apache/htdocs下

  这个也可以自己改的。

  下面说说建虚拟主机的步骤:

  在/usr/local/apache/conf/httpd.conf文件的最后一行加入

  Include ./vhost-conf.d/*.conf

  保存退出

  在/usr/local/apache下

  #mkdir vhost-conf.d

  #cd vhost-conf.d

  vi ip-vhost.conf

  Listen 8888

  Listen 6666

  Listen 9999

  <VirtualHost IP*8888>

  ServerAdmin webmaster@localhost
      DocumentRoot /home/tom/public_html/
      ServerName localhost
      ErrorLog logs/localhost-error_log
      CustomLog logs/localhost-access_log combined
      DirectoryIndex index.html.zh-cn.gb2312  index.htm index.html index.php index.cgi index.pl
      DefaultLanguage zh-CN
      AddDefaultCharset GB2312
     <Directory "/usr/local/apache/htdocs/">
         Options FollowSymLinks
         AllowOverride None
         Order allow,deny
         Allow from all
     </Directory>
  ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
  <Directory "/usr/local/apache/cgi-bin/">
      AllowOverride None
      Options None
      Order allow,deny
      Allow from all
  </Directory>

  </VirtualHost>

   

  虚拟服务器这样就建好了

  然后就架ftp:

  pbone里找到了vsftpd,然后

  #rpm -ivh vsftpd

  #cd /etc/vsftpd

  #install -m 644 vsftpd.conf /etc/vsftpd-ano.conf

  为了测试方便,我们先建立一个名为kill-ano的脚本,是为了杀掉FTP程序的
  #!/bin/bash
  a=`/bin/ps -A | grep vsftpd-ano | awk '{print $1}'`
  kill -9 $a

  # vi /etc/vsftpd-loc.conf ,将如下三行加入文件
  listen=YES
  listen_port=21
  tcp_wrappers=YES //支持tcp_wrappers,限制访问(/etc/hosts.allow,/etc/hosts.deny)
  listen=YES的意思是使用standalone启动vsftpd,而不是super daemon(xinetd)控制它 (vsftpd推荐使用standalone方式),注意事项请参看匿名用户的配置。
  anonymous_enable=NO
  local_enable=YES  //这两项配置说不允许匿名用户登陆,允许本地用户登陆
  # /usr/local/sbin/vsftpd-loc /etc/vsftpd-loc.conf &   //以后台方式启动vsftpd

  # useradd 1jjk
  # passwd 1jjk

  这样,就都建好了,至于安全相关,经常登陆一些安全性的网站就可以找到了!

   

1
有问必答
【内容导航】
第1页:一个崭新的Linux服务器架设全过程..
©版权所有。未经许可,不得转载。
[责任编辑:服务器学院02] [我要挑错]
相关产品
本文相关产品
   没有相关产品