> CentOS > CentOS教程 >

CentOS6.2安装配置

一、安装CentOS6.2系统

1、选择Desktop进行安装

注:如果修改了主机名,则需要在/etc/hosts文件中增加设置的主机名

2、ssh安全设置(配置文件:/etc/ssh/sshd_config):

   1)更改默认22端口:去掉 Port的注释,改成如:22123

   2)禁止root账号登录:去掉PermitRootLogin yes注释,改成:PermitRootLogin no

   3)新增SSH登录用户,登录成功后再su到root:

# useradd xiaoma
# passwd xiaoma
     然后修改ssh配置文件,最后加入:AllowUsers xiaoma

   4)重启SSH服务:service sshd restart

   5)更改防火墙配置,允许22123端口,加入:-A INPUT -m state –state NEW -m tcp -p tcp –dport 22123 -j ACCEPT,并重启防火墙生效:service iptables restart

二、软件环境配置

1、安装编译环境:

# yum install gcc gcc-c++
注:代理上网,命令行:export http_proxy=http://ip:port

2、安装一些必备的库

# yum install ncurses-devel zlib-devel libjpeg* libpng* freetype*
注:ncurses-devel – 编译安装mysql5.5时需要
    zlib-devel – 编译安装httpd需要
    libjpeg*、libpng*、freetype* – 编译安装php需要

3、安装clamAV杀毒软件

# tar xzf clamav-0.97.4.tar.gz
# cd clamav-0.97.4
# ./configure --prefix=/usr/local/clamav --disable-clamav
# make
# make install

# groupadd clamav
# useradd -g clamav clamav
# chown -R clamav.clamav /usr/local/clamav
    操作示例:
    1)更新病毒库:bin/freshclam(需要修改etc/freshclam.conf文件把Example行注释掉)
    2)扫描指定的目录:bin/clamscan –bell -i -r /usr/local

4、安装JDK

# chmod +x jdk-6u33-linux-i586.bin
# ./jdk-6u33-linux-i586.bin
# mv jdk1.6.0_33/ /usr/local
    设置JDK环境变量,/etc/profile文件中最后加入如下配置:

JAVA_HOME=/usr/local/jdk1.6.0_33
export JAVA_HOME
export PATH=/usr/local/mysql5/bin/JAVA_HOME/bin/PATH
    然后更新环境变量使之生效:

# source /etc/profile
    查看安装的java版本:

# java -version
5、安装Mysql5.5(mysql5.5需要cmake编译,需要先安装cmake)

# tar xzf cmake-2.8.7.tar.gz
# cd cmake-2.8.7
# ./configure
# make && make install

# mkdir -p /usr/local/mysql5
# groupadd mysql
# useradd -g mysql mysql
# chown mysql.mysql -R /usr/local/mysql5

# tar xzf mysql-5.5.19.tar.gz
# cd mysql-5.5.19/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 -DMYSQL_UNIX_ADDR=/usr/local/mysql5/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql5/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
# make
# make install
    配置Mysql,进行如下操作:

# cp support-files/my-medium.cnf /etc/my.cnf
# chmod 755 scripts/mysql_install_db
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5 --datadir=/usr/local/mysql5/data

# cp support-files/mysql.server /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql
# chkconfig mysql on
    启动mysql并设置root账号密码:

# /etc/init.d/mysql start 或 service mysql start
# /usr/local/mysql5/bin/mysqladmin -uroot password 'root'
    加入环境变量,在/etc/profile文件中最后加入:

export PATH=/usr/local/mysql5/bin/PATH
    修改默认的mysql最大连接数(默认只有151),打开/etc/my.cnf文件,在[mysqld]的下面加入:max_connections=1000,然后重启mysql即可生效,查看最大连接数:

mysql>show VARIABLES LIKE '%conn%';
6、安装httpd

# tar xzf httpd-2.2.21.tar.gz
# cd httpd-2.2.21/
# cd srclib/apr
# ./configure --prefix=/usr/local/apr
# make
# make install

# cd ../apr-util
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install

# cd ../..
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-dav --enable-proxy --enable-proxy-ajp
# make
# make install
    启动httpd并访问http://ip进行测试(注意iptables需要打开80端口):

# /usr/local/apache2/bin/apachectl start
    如果需要禁止对某个目录的访问,可以在该目录下新建.htaccess文件,并输入如下内容:

order allow,deny
deny from all
7、安装php

# tar xzf libxml2-2.7.5.tar.gz
# cd libxml2-2.7.5
# ./configure --prefix=/usr/local/libxml2
# make
# make install

# cd ..
# rpm -qa php
# rpm -e --nodeps --allmatches php-5.1.6-27.el5
# tar xzf php-5.3.1.tar.gz
# cd php-5.3.1
# ./configure --prefix=/usr/local/php5 --with-libxml-dir=/usr/local/libxml2/ --with-mysql=/usr/local/mysql5/ --with-apxs2=/usr/local/apache2/bin/apxs  --with-mbstring --enable-mbstring=all --with-gd
# make
# make install
# cp php.ini-production /usr/local/php5/lib/php.ini
    修改httpd.conf文件:

    1)在AddType application/x-gzip .gz .tgz之后加一行:AddType application/x-httpd-php  .php
    2)在DirectoryIndex index.html后加入index.php

    重启httpd后即可使php生效!

8、安装Tomcat7

# unzip -q apache-tomcat-7.0.23.zip
# mv apache-tomcat-7.0.23 tomcat-7
    配置tomcat的虚拟主机,打开conf/server.xml配置文件,加入如下段(多个则加入多个如下段即可):

      <Host name="www.mzone.cc"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
          <Alias>chinapis.com</Alias>
          <Context path="" docBase="/webapps/www.mzone.cc" />
      </Host>
    配置完tomcat后,还需要配置apache的虚拟主机文件(conf/extra/httpd-vhosts.conf):

<VirtualHost *:80>
    DocumentRoot "/kington/webapps/chinapis"
    ServerName www.mzone.cc
    ServerAlias mzone.cc

    ErrorLog "| /usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/mzone.cc_%Y-%m-%d_error_log 86400 480"
    CustomLog "| /usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/mzone.cc_%Y-%m-%d_access_log 86400 480" common

    ProxyPass /images/ !
    ProxyPass /styles/ !

    ProxyPreserveHost On
    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
    上述配置中的说明如下:

    1)ErrorLog和CustomLog配置了日志文件的轮询时间(86400表示秒是一天,480是时区的偏移)

三、常见问题

1、编译安装php时遇到:configure: error: libpng.(a|so) not found,首先安装各个依赖组件(libjpeg、libpng、freetype),然后做如下处理:

# ln -s /usr/lib64/libjpeg.so /usr/lib/
# ln -s /usr/lib64/libpng.so /usr/lib/
2、解压bin格式的jdk时候报错:/lib/ld-linux.so.2: bad ELF interpreter,需要安装一些缺少的文件:

# yum install ld-linux.so.2
(责任编辑:IT)