linux配置分步安裝lnmp環境----ghj

來源:互聯網
上載者:User

標籤:work   centos安裝   max   called   mini   密碼檔案   查看   dia   其他   

前台:nignx 後台:apache

【linux命令】
使用者
檔案目錄
啟動
定時任務:
【開啟RZ命令】

yum -y install lrzsz

【防火牆】

防火牆設定檔: /etc/sysconfig/iptables
服務作業命令 : /etc/init.d/iptables service iptables {start|stop...}
臨時改變命令 : iptables iptables-save iptables-restore等
service iptables status可以查看到iptables服務的目前狀態。
但是即使服務運行了,防火牆也不一定起作用,你還得看防火牆規則的設定 iptables -L
在此說一下關於啟動和關閉防火牆的命令:
1) 重啟後生效
開啟: chkconfig iptables on
關閉: chkconfig iptables off
2) 即時生效,重啟後失效
開啟: service iptables start
關閉: service iptables stop

【修改IP】
#vi /etc/syssconfig/network-scripts/ifcfg-eth0

  DEVICE=eth0

  BOOTPROTO=static

  HWADDR= ;這裡是你網卡的物理地址,通常檢測到的網卡你就不用輸入了

  ONBOOT=yes

  IPADDR=192.168.0.1

  NETMASK=255.255.255.0

  NETWORK=192.168.1.0

  BROADCAST=192.168.1.255

  GATEWAY= ;這裡輸入你的網關,路由器的IP地址

  儲存退出

  #/sbin/service network restart

  如果網卡啟動是OK的話就說明IP地址設定成功了。另外我們可以用ifconfig eth0來顯示當前的IP來確認是否設定正確。

  利用以下命令:

  /etc/init.d/network reload 命令或service network [命令]

【yum源】

.本地源製作

1、首先在/media目錄下建立一個目錄cdrom並將將光碟片掛載到系統/media/cdrom下
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom/
2、進入到/etc/yum.repos.d目錄CentOS-Base.repo重新命名。

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
vi CentOS-Media.repo
修改為
gpgcheck=0
enabled=1

***3、將所有的CentOS安裝包連結到/media/CentOS
ln -s /media/cdrom/CentOS/ /media/CentOS






#yum 安裝系統內容所需要的軟體包

yum -y install yum-fastestmirror ntp
yum -y install patch make flex bison tar
yum -y install libtool libtool-libs kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel
yum -y install libtiff libtiff-devel gettext gettext-devel
yum -y install libxml2 libxml2-devel zlib-devel  net-snmp
yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel
yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal unzip

# 安裝PHP支援GD庫模組
yum -y install freetype freetype-devel png jpeg zlib gd php-gd*
# 安裝PHP 5.* 組件
yum -y install libiconv libevent mhash mcrypt
# 安裝MYDSQL所需要系統庫相關庫檔案
yum install -y gcc gcc-c++ gcc-g77 autoconf automake  fiex* ncurses-devel libmcrypt* libtool-ltdl-devel*

# 安裝NGINX 組件
yum -y install pcre*

yum -y install gcc gcc-c++ gcc-g77 flex bison tar libtool libtool-libs kernel-devel  autoconf libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel gettext gettext-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel file glib2 glib2-devel bzip2diff* openldap-devel bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal unzip  automake make

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

【安裝nginx 之前要安裝pcre】

tar zvxf pcre-8.10.tar.gz
#cd pcre-8.10
#./configure
#make
#make install

【nginx】
下載安裝包:http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure
make && make install

啟動nginx:/usr/local/nginx/sbin/nginx  
重啟nginx: /usr/local/nginx/sbin/nginx -s reload


開機啟動nginx:在linux系統的/etc/init.d/目錄下建立nginx檔案

vi /etc/init.d/nginx

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it‘s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

chmod a+x /etc/init.d/nginx

最後將ngix加入到rc.local檔案中,這樣開機的時候nginx就預設啟動了
 vi /etc/rc.local  
添加  /etc/init.d/nginx start  
儲存並退出  下次重啟就會生效,實現nginx的自啟動。

【安裝mysql】
yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

yum -y install cmake

groupadd mysql
useradd -r -g mysql mysql

tar -zxvf mysql-5.6.21.tar.gz
cd mysql-5.6.21

cmake .
make && make install

-------------------------預設情況下是安裝在/usr/local/mysql

chown -R mysql.mysql /usr/local/mysql

cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cd /usr/local/mysql/support-files
cp mysql.server /etc/rc.d/init.d/mysql
cp my-default.cnf /etc/my.cnf
chkconfig --add mysql
chkconfig mysql on
service mysql start




修改密碼:/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘

登陸:/usr/local/mysql/bin/mysql -u root -p
 

修改遠端存取許可權:

1。 改表法。可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"

Sql代碼 複製代碼

   1. mysql -u root -p
   2. use mysql;  
   3. mysql>update user set host = ‘%‘ where user = ‘root‘;  
   4. mysql>select host, user from user;

2. 授權法。例如,你想myuser使用mypassword從任何主機串連到mysql伺服器的話。

Sql代碼 複製代碼
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;

FLUSH PRIVILEGES;


【安裝apache】

cd /usr/local/src

groupadd www
useradd -g www -s /sbin/nologin -M www

wget http://apache.freelamp.com//httpd/httpd-2.2.17.tar.gz

tar zxvf httpd-2.2.17.tar.gz

cd httpd-2.2.17


Apache預設最大串連數和最大用戶端數為40000,如果你的伺服器要求更大,可以編譯Apache安裝檔案中的:

    server/mpm/worker/worker.c

找到下面幾行,並改成如下的數值,其目的是在源碼中修改apache可支援的最大線程數和最大用戶端數目。

    define DEFAULT_SERVER_LIMIT 32
    define MAX_SERVER_LIMIT 40000
    define DEFAULT_THREAD_LIMIT 64
    define MAX_THREAD_LIMIT 40000

以上數值據說改小後,能減低伺服器消耗。不過柒月修改後,發現沒什麼實質變化

依次安裝apr和apr-util     
    tar zxvf apr-1.5.2.tar.gz
    cd apr-1.5.2    
    ./configure --prefix=/usr/local/apr
    make && make install
    
    tar zxvf apr-util-1.5.4.tar.gz

    cd apr-util-1.5.4

    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql
    make && make install

安裝Apache 2.4

    cd /usr/local/src/httpd-2.4.20

    ./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-rewrite --with-mpm=prefork --disable-cgid --disable-cgi

    make && make install

如果你需要編譯apache其他功能,可以自行增加。不過在這裡,我們只是用Apache作為後端並處理偽靜態,無需添加過多設定來浪費記憶體

註解:

    ./configure //配置原始碼樹
    --prefix=/usr/local/apache //體系無關檔案的頂級安裝目錄PREFIX ,也就Apache的安裝目錄。
    --enable-module=so //開啟 so 模組,so 模組是用來提 DSO 支援的 apache 核心模組
    --enable-mods-shared=all //編譯全部的模板,對於不需要我們可以在httpd.conf去掉。
    --enable-cache //支援緩衝
    --enable-file-cache //支援檔案快取
    --enable-mem-cache //支援記憶緩衝
    --enable-disk-cache //支援磁碟緩衝
    --enable-static-support //支援靜態串連(預設為動態串連)
    --enable-static-htpasswd //使用靜態串連編譯 htpasswd - 管理用於基本認證的使用者檔案
    --enable-static-htdigest //使用靜態串連編譯 htdigest - 管理用於摘要認證的使用者檔案
    --enable-static-rotatelogs //使用靜態串連編譯 rotatelogs - 滾動 Apache 日誌的管道日誌程式
    --enable-static-logresolve //使用靜態串連編譯 logresolve - 解析 Apache 日誌中的IP地址為主機名稱
    --enable-static-htdbm //使用靜態串連編譯 htdbm - 操作 DBM 密碼資料庫
    --enable-static-ab //使用靜態串連編譯 ab - Apache HTTP 伺服器效能測試工具
    --enable-static-checkgid //使用靜態串連編譯 checkgid
    --disable-cgid //禁止用一個外部 CGI 守護進程執行CGI指令碼
    --disable-cgi //禁止編譯 CGI 版本的 PHP
    --with-mpm=worker // 讓apache以worker方式運行
    --enable-ssl // 編譯 ssl模組。

啟動Apache(建議先不要啟動,等我們全部設定完畢後,和Nginx啟動)

    /usr/local/apache/bin/apachectl start|stop|restart

查看apache是否啟動

    ps aux|grep httpd

將apache設定成開機自啟動:

echo ‘/usr/local/apache/bin/apachectl start ‘ >> /etc/rc.local  //將 apachectl 的調用加入到你的系統開機檔案中。

問題:httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

在httpd.conf (/usr/local/apache/conf/httpd.conf)中找到
#ServerName www.example.com:8080   把#去掉

error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

試著執行: ldd /usr/local/apache/bin/httpd
會看到這麼一行
libiconv.so.2 => Not found
以前編譯運行是可以的,可能是不久前升級一些庫檔案影響。在/usr/local/lib下可以找到libiconv.so.2,把/usr/local/lib加到路徑中也不行。
在/etc/ld.so.conf中加一行/usr/local/lib,運行ldconfig。再運行apache,OK。
ld.so.conf和ldconfig是維護系統動態連結程式庫的。


【軟體版本:PHP 5.6.3】

一、安裝libiconv庫

tar -zvxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure –help
./configure --prefix=/usr/local

make && make install

echo "/usr/local/lib">>/etc/ld.so.conf

/sbin/ldconfig

下載php5.6.12
      
wget http://cn2.php.net/distributions/php-5.6.3.tar.gz

解壓 php 5.6.3 源碼包
      
tar -zxvf php-5.6.3.tar.gz



./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mb --enable-bcmath --enable-mbstring --enable-sockets --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-t --with-zlib --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache/bin/apxs

編譯完畢後,我們再來make。在make時,我們注意要加上-liconv參數。如果不加上-liconv參數,系統在make編譯會報錯。報錯資訊如下:

Generating phar.php

//php-5.3.16/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make: *** [sapi/cli/php] Error 1

使用命令如下:

make ZEND_EXTRA_LIBS=‘-liconv‘

make install

[注意]上述命令中:
–enable-fpm的作用是開啟php的fastcgi功能,即開啟php-fpm功能。

–with-mysql=/usr/local/mysql是啟用php支援mysql的功能,/usr/local/mysql是mysql資料庫的安裝路徑。

–enable-mbstring表示啟用mbstring模組mbstring模組的主要作用在於檢測和轉換編碼,提供對應的多位元組操作的字串函數。目前php內部的編碼只支援ISO-8859-*、EUC-JP、UTF-8,其他的編碼的語言是沒辦法在php程式上正確顯示的,所以我們要啟用mbstring模組。

–with-iconv-dir=/usr/local指定php存放libiconv庫的位置。

–with-apxs2=/usr/local/apache/bin/apxs指定php尋找apache的位置。

配置php的環境變數

echo "PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile
source !$  # 重新整理系統內容

cp php.ini-production /usr/local/php/etc/php.ini

cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf

vi etc/php-fpm.conf

user = www
group = www

在安裝目錄下:

cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod 755 /etc/init.d/php-fpm

/usr/local/php/sbin/php-fpm -t

啟動和關閉php 並查看php狀態
service php-fpm start
或者
/usr/local/php/sbin/php-fpm
service php-fpm stop
service php-fpm status
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status}

添加php到系統服務,並隨機啟動
      
chkconfig --add php-fpm && chkconfig php-fpm on



【php與apache】

/usr/local/apache/conf/httpd.conf:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

重啟apache /usr/local/apache/bin/apachectl restart

echo "<?php phpinfo();?>">/usr/local/apache/htdocs/index.php

cat /usr/local/apache/htdocs/index.php

【php與nginx】 nginx-> php-fpm(502)->  php

 location ~ .php$ {
                root html;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

【主從複製】


【讀寫分離】

【反向 Proxy】

【git】

【svn】

=======================================================

svn配置

1.安裝svn伺服器端
yum install subversion 從鏡像下載安裝svn伺服器端
cd /usr/local/ //進入目錄,準備建立svn目錄
mkdir svn //建立一個svn目錄
chmod -R 777 svn //修改目錄許可權為777
svnadmin create /usr/local/svn/sunny //建立一個svn版本倉庫sunny(sunny可以隨便起名字)
cd svn/sunny/conf //進入sunny版本倉庫下的設定檔目錄

下面要修改這個目錄下的三個設定檔
(1)vi svnserve.conf //配置版本庫資訊和使用者檔案和使用者密碼檔案的路徑、版本庫路徑


# anon-access = read
# auth-access = write
# password-db = passwd
//這四行,前面的#號和空格去掉(注意去掉#要頂格寫,不要留有多餘空格),變成
anon-access = none //改成none
auth-access = write
password-db = passwd
realm = sunny //改成自己的版本庫
儲存

(2)vi authz //檔案,建立svn組和組使用者的許可權
[group]
sunny = gep,wce //建立一個sunny的組,並指定兩個使用者gep和wce

[/] //制定根目錄下的許可權
@sunny = rw //sunny組使用者權限為讀寫
* = r //其他使用者只有讀許可權
儲存退出

(3) vi passwd //建立或修改使用者密碼
[users]
gep = 123456 //使用者名稱為gep的使用者的密碼為123456
wce = 123456 //。。。
儲存退出


啟動svn:
svnserve -d -r /usr/local/svn/ //這裡採用多版本庫的方式啟動 如果是單版本庫 可以svnserve -d -r /usr/local/svn/sunny
添加一行
然後要設定自啟動
vi /etc/rc.local 開啟自開機檔案添加
/usr/bin/svnserve -d -r /usr/local/svn/

到此為止可以從服務端檢出檔案了.

svn命令:
netstat -tnl |grep :3690 查看svn是否啟動
ps aux |grep ‘svn‘ 尋找所有svn啟動的進程
kill -9 2505 殺死2505這個尋找到的svn進程


svn checkout svn://172.19.5.2/sunny /data0/htdocs/blog //檢出一份版本庫檔案到指定目錄
svn up //更新檔案

自動更新
在vi /usr/local/svn/sunny/hooks/post-commit中加入

#!/bin/sh
#設定一些變數
SVN=/usr/bin/svn
WEB=/home/testsvn #要更新的目錄
export LANG=en_US.UTF-8
$SVN update $WEB --username xxx --password xxx


其中SVN=右邊改成 svn 命令位置 一般預設為/usr/bin/svn
WEB=右邊改成你實際的web目錄
賦予可執行許可權
chmod 777 /usr/local/svn/sunny/hooks/post-commit
安裝完畢


=========================================================================
其他動作

#svn commit -m "注釋" xxx.php //提交檔案
svn ci -m‘aaa‘ test.php //提交檔案

#svn add file //建立檔案並添加到svn
svn add *.php //(添加目前的目錄下所有的php檔案)
svn delete test.php //刪除test.php
svn log test.php //查看test檔案的log資訊
svn cleanup //清理目前的目錄

 

svn switch --relocate svn://192.168.1.253 svn://172.19.10.250 //重新置放SVN版本庫地址


 

// SVN版本庫起動方式,現在SVN下面有 sunny、test 兩個版本庫
1:單版本庫起動 svnserve -d -r /usr/local/svn/sunny
2:多版本庫起動 svnserve -d -r /usr/local/svn
區別在於起動svn時候的命令中的啟動參數-r指定的目錄。

限制不同的使用者對不同的版本庫操作許可權,修改版本庫中的conf目錄下的 authz檔案

以配置 sunny 版本庫為例
vi authz
[groups]
teacher = sunny,sunny1
[sunny:/] //指定版本庫跟目錄下的許可權
@teacher = rw //teacher組使用者權限為讀寫
* = r //其他使用者只有讀許可權
儲存退出

vi passwd 設定組中使用者的帳號和密碼
[users]
sunny = 123456
sunny1 = 123456

【memecache radius】


【負載平衡】

linux配置分步安裝lnmp環境----ghj

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.