這是自己配置linux中CentOS-6.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_33export JAVA_HOMEexport PATH=/usr/local/mysql5/bin:$JAVA_HOME/bin:$PATH 然後更新環境變數使之生效:
# source /etc/profile 查看安裝的java版本:
# java -version5、安裝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,denydeny from all7、安裝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