一、安裝CentOS6.2系統(tǒng)
1、選擇Desktop進(jìn)行安裝
注:如果修改了主機(jī)名,則需要在/etc/hosts文件中增加設(shè)置的主機(jī)名
2、ssh安全設(shè)置(配置文件:/etc/ssh/sshd_config):
1)更改默認(rèn)22端口:去掉 Port的注釋?zhuān)某扇纾?2123
2)禁止root賬號(hào)登錄:去掉PermitRootLogin yes注釋?zhuān)某桑篜ermitRootLogin no
3)新增SSH登錄用戶(hù),登錄成功后再su到root:
# useradd xiaoma
# passwd xiaoma
然后修改ssh配置文件,最后加入:AllowUsers xiaoma
4)重啟SSH服務(wù):service sshd restart
5)更改防火墻配置,允許22123端口,加入:-A INPUT -m state –state NEW -m tcp -p tcp –dport 22123 -j ACCEPT,并重啟防火墻生效:service iptables restart
二、軟件環(huán)境配置
1、安裝編譯環(huán)境:
# yum install gcc gcc-c++
注:代理上網(wǎng),命令行:export http_proxy=http://ip:port
2、安裝一些必備的庫(kù)
# yum install ncurses-devel zlib-devel libjpeg* libpng* freetype*
注:ncurses-devel – 編譯安裝mysql5.5時(shí)需要
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)更新病毒庫(kù):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
設(shè)置JDK環(huán)境變量,/etc/profile文件中最后加入如下配置:
JAVA_HOME=/usr/local/jdk1.6.0_33
export JAVA_HOME
export PATH=/usr/local/mysql5/bin:$JAVA_HOME/bin:$PATH
然后更新環(huán)境變量使之生效:
# 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,進(jìn)行如下操作:
# 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
啟動(dòng)mysql并設(shè)置root賬號(hào)密碼:
# /etc/init.d/mysql start 或 service mysql start
# /usr/local/mysql5/bin/mysqladmin -uroot password 'root'
加入環(huán)境變量,在/etc/profile文件中最后加入:
export PATH=/usr/local/mysql5/bin:$PATH
修改默認(rèn)的mysql最大連接數(shù)(默認(rèn)只有151),打開(kāi)/etc/my.cnf文件,在[mysqld]的下面加入:max_connections=1000,然后重啟mysql即可生效,查看最大連接數(shù):
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
啟動(dòng)httpd并訪問(wèn)http://ip進(jìn)行測(cè)試(注意iptables需要打開(kāi)80端口):
# /usr/local/apache2/bin/apachectl start
如果需要禁止對(duì)某個(gè)目錄的訪問(wèn),可以在該目錄下新建.htaccess文件,并輸入如下內(nèi)容:
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的虛擬主機(jī),打開(kāi)conf/server.xml配置文件,加入如下段(多個(gè)則加入多個(gè)如下段即可):
Host name="www.jb51.net" appBase="webapps"
unpackWARs="true" autoDeploy="true">
Alias>chinapis.com/Alias>
Context path="" docBase="/webapps/www.jb51.net" />
/Host>
配置完tomcat后,還需要配置apache的虛擬主機(jī)文件(conf/extra/httpd-vhosts.conf):
VirtualHost *:80>
DocumentRoot "/kington/webapps/chinapis"
ServerName www.jb51.net
ServerAlias jb51.net
ErrorLog "| /usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/jb51.net_%Y-%m-%d_error_log 86400 480"
CustomLog "| /usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/jb51.net_%Y-%m-%d_access_log 86400 480" common
ProxyPass /images/ !
ProxyPass /styles/ !
ProxyPreserveHost On
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
/VirtualHost>
上述配置中的說(shuō)明如下:
1)ErrorLog和CustomLog配置了日志文件的輪詢(xún)時(shí)間(86400表示秒是一天,480是時(shí)區(qū)的偏移)
三、常見(jiàn)問(wèn)題
1、編譯安裝php時(shí)遇到:configure: error: libpng.(a|so) not found,首先安裝各個(gè)依賴(lài)組件(libjpeg、libpng、freetype),然后做如下處理:
# ln -s /usr/lib64/libjpeg.so /usr/lib/
# ln -s /usr/lib64/libpng.so /usr/lib/
2、解壓bin格式的jdk時(shí)候報(bào)錯(cuò):/lib/ld-linux.so.2: bad ELF interpreter,需要安裝一些缺少的文件:
# yum install ld-linux.so.2