RedHat 6.4 下源碼安裝LANMP架構

   
lanmp表示的是Linux,apache,nginx,mysql,php的簡稱,目前支持三種環境安裝,即是lamp,lnmp,lnamp,也是linux服務器WEB環境一鍵安裝包,可去wdlinux官網下載。

MYSQL安裝
軟件包依賴yum install gcc gcc-c++ make cmake ncurses-developenssl-devel bison zlib-devel
1.get mysql-5.6.10.tar.gz
tar zxf mysql-5.6.10.tar.gz
cd mysql-5.6.10
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all
然後make && make install
重新編譯時,需要清除舊的對象文件和緩存信息
make clean
rm -fr CmakeCache.

useradd -M -s /sbin/nologin mysql
cd /usr/local/lnmp/mysql
cp support-file/my-medium.cnf /etc/my.cnf
chown -R mysql.mysql .
cd scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql/--datadir=/usr/local/lnmp/mysql/data/
cd mysql/
chown -R root .
chown -R mysql data
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start

vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile
/etc/init.d/mysqld restart
mysql_secure_installation #按提示完成 mysql 安全設置,生產環境推薦使用

Nginx安裝
yum install pcre-devel -y
tar zxf nginx-1.2.7.tar.gz

vi auto/cc/gcc
註釋CFLAGS="$CFLAGS -g"
vi src/core/nginx.h
#define NGINX_VER "nginx" 修改此行,去掉後面的NGINX_VERSION,這樣編譯後外界無法獲取程序的版本號
cd nginx-1.2.7
./configure --help
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module
然後make && make install
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
vi /usr/local/lnmp/nginx/conf/nginx.conf
#user nginx nginx ;                      ##1行
location / {                             ##43行
           root   html;
           index  index.html index.htm;
       }
       location /status {
       stub_status on;
       access_log off;
       }
nginx -t           ##檢測語法
nginx              ##運行 nginx
nginx -s reload    ##重載主配置文件
nginx -s stop      ##關閉 nginx
瀏覽器輸入ip/status

加密證書通過https訪問
vi nginx.conf
打開 HTTPS server 下的所有註釋
修改 server_name  主機名;
修改 ssl_certificate_key cert.pem;

cd /etc/pki/tls/certs
make cert.pem
cp cert.pem /usr/local/lnmp/nginx/conf/
nginx -t
nginx -s reload
netstat -antpl               ##443端口就是https打開的
瀏覽器輸入https://server1.example.com

兩個虛擬主機(純靜態-html 支持
cd /
mkdir /www
cd /www  
mkdir linux.org   cd linux.org   echo www.linux.org > index.html
mkdir westos.org  cd westos.org  echo www.westos.org > index.html\
vi nginx.conf
在最後添加:
server {
listen          80;
server_name     www.westos.org;
access_log      logs/westos.org.access.log main;
location / {
index index.html;
root /www/westos.org;
}
}
server {
listen          80;
server_name     www.linux.org;
access_log      logs/linux.org.access.log main;
location / {
index index.html;
root /www/linux.org;
}
}
}
並打開下列註釋
   log_format  main '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status$body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
在宿主機上vi /etc/hosts
192.168.0.1    www.westos.org   www.linux.org
測試結果
在瀏覽器分別輸入www.westos.org www.linux.org 得到相應主機名

一個簡單的負載均衡的示例,把www.domain.com均衡到本機不同的端口,也可以改爲均衡到不同的地址上
在server2,server3上安裝啓動httpd
cd /var/www/html
分別輸入echo `hostname` > index.html                  ##便於以後測試分別
在server1上 vi nginxc.conf
在http { 裏添加
 upstream westos {
 server 192.168.0.2:80;
 server 192.168.0.3:80;
修改
server {
listen          80;
server_name     www.westos.org;
access_log      logs/westos.org.access.log main;
location / {
proxy_pass http://westos;
}
}

相關配置文檔可以在wiki.nginx.org 裏查看

Php 安裝
tar zxf libiconv-1.13.1.tar.gz      ##加強系統對支持字符編碼轉換的功能
cd libiconv-1.13.1/
./configure --libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64             ##加載上述安裝
tar jxf libmcrypt-2.5.8.tar.bz2     ##mcrypt mhash 是 php 加密算法擴展庫
cd libmcrypt-2.5.8
./configure –libdir=/usr/local/lib64
make && make install
ldconfig  /usr/local/lib64
cd libltdl
./configure –libdir=/usr/local/lib64 –enable-ltdl-install
make && make install
ldconfig  /usr/local/lib64
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure –libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure --libdir=/usr/local/lib64
make && make install
#./configure 時可能會報這個錯:/bin/rm: cannot remove`libtoolT’: No such file or directory 直接忽略
cd /usr/local/lnmp/mysql
ln -s lib  lib64
軟件包依賴性:
yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-develfreetype-
devel gmp-devel openldap-devel -y

tar jxf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc--with-mysql=/usr/local/lnmp/mysql/ --with-openssl --with-snmp --with-gd--with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir--with-freetype-dir --with-pear --with-gettext --with-gmp--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-libdir=lib64--with-mcrypt --with-mhash
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
cd sapi/fpm/
cp init.d.php-fpm /etc/ini.t/fpm
chmod +x /etc/init.d/fpm
cd  /usr/local/lnmp/php/etc/
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
pid=run/php-fpm.pid        ##去掉註釋
vi /usr/local/lnmp/php/etc/php.ini
cgi.fix_pathinfo=0          ## 防止nginx文件類型錯誤解析漏洞
/etc/init.d/fpm start
cd /usr/local/lnmp/nginx/conf
vi nginx.conf
在server中的location 中修改
index index.php index.html index.htm;
並打開如下
location ~ \.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
       }
nginx -t
nginx -s reload
cd html
vi index.php
<?php
phpinfo(();
?>
/etc/init.d/mysqld start
輸入ip/index.php

發佈論壇
get Discuz_X2.5_SC_UTF8.zip
unzip Discuz_X2.5_SC_UTF8.zip -C /usr/local/lnmp/nginx/html
mv upload/ bbs
cd bbs/
chown -R nginx.nginx bbs/
瀏覽器輸入ip/bbs/install/

Memcache 是 danga.com 的一個開源項目,它是一個高性能的分佈式的內存對象緩存系統,通過在
內存裏維護一個統一的巨大的 Hash 表,能夠用來存儲各種格式的數據。可以類比於 MySQL 這樣的服
務,而 PHP 擴展的 Memcache 實際上是連接 Memcache 的方式
yum install libevent libevent-devel -y
tar zxf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make && make install
memcached -u root -m 10 -d
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/local/lnmp/php/bin/
source ~/.bash_profile
yum install autoconf -y
tar zxf memcache-2.2.5.tar.gz
cd memcache-2.2.5
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd /usr/local/lnmp/php/etc/
vi php.ini
修改
extension=memcache.so
/etc/init.d/fpm reload
cd memcache-2.2.5
cp memcache.php /usr/local/lnmp/nginx/html/
cd /usr/local/lnmp/nginx/html/
vi memcache.php
define('ADMIN_PASSWORD','westos');
輸入 ip/memchace.php


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章