centosLAMP環境搭建
說明:
1.官網採用LAMP框架,nginx做前端輪詢代理
2、移除系統自帶的rpm包的http mysql php
yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
3 安裝必備的開發包
/usr/bin/yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel
ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel
gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel
libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libxml2
libmhash-devel mysql-devel libxslt libxslt-devel curl tcl expect
4.同步系統時間:
vim /etc/ntp.conf
server 3.cn.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.asia.pool.ntp.org
chkconfig ntpd on
service ntpd restart
5.IP分配
nginx:192.168.201.4 192.168.201.5 192.168.201.6 192.168.201.7
apache:192.168.201.123—192.168.201.138
-
一.nginx搭建
-
1.下載原始碼包nginx-1.4.2
-
2.安裝nginx
-
./configuer –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module & make & make install
-
3.配置檔案如下
-
user nobody;
-
worker_processes 8;
-
pid logs/nginx.pid;
-
-
events {
-
use epoll;
-
worker_connections 65535;
-
}
-
-
http {
-
-
# 設定一個共享記憶體區域reqnum,以用於限制每個客戶端IP可以併發連線的請求數
-
# limit_conn_zone $binary_remote_addr zone=reqnum:10m;
-
# 每個客戶端IP每分鐘只允許5個連線
-
# limit_req_zone $binary_remote_addr zone=reqone:10m rate=10r/m;
-
include mime.types;
-
default_type application/octet-stream;
-
-
sendfile on;
-
tcp_nopush on;
-
tcp_nodelay on;
-
keepalive_timeout 60;
-
server_tokens off;
-
-
log_format wwwlog `$remote_addr – $remote_user [$time_local] “$request” `
-
`$status $body_bytes_sent “$http_referer” `
-
`”$http_user_agent” $http_x_forwarded_for`;
-
access_log /usr/local/nginx/logs/access.log wwwlog;
-
-
gzip on;
-
gzip_min_length 1k;
-
gzip_buffers 4 16k;
-
gzip_http_version 1.1;
-
gzip_comp_level 3;
-
gzip_types text/plain application/x-javascript text/css applicati
-
on/xml;
-
gzip_vary on;
-
-
server_names_hash_bucket_size 128;
-
client_header_buffer_size 32k;
-
client_max_body_size 300m;
-
client_body_buffer_size 512k;
-
large_client_header_buffers 4 32k;
-
-
proxy_connect_timeout 60;
-
proxy_send_timeout 120;
-
proxy_read_timeout 120;
-
proxy_buffer_size 16k;
-
proxy_buffers 4 64k;
-
proxy_busy_buffers_size 128k;
-
proxy_temp_file_write_size 128k;
-
-
index index.php index.htm index.html default.php default.htm defaul
-
t.html index.php3;
-
-
upstream os_server {
-
# ip_hash;
-
# server 192.168.201.122:80 weight=1;
-
server 192.168.201.123:80 weight=1;
-
server 192.168.201.124:80 weight=1;
-
server 192.168.201.125:80 weight=1;
-
server 192.168.201.126:80 weight=1;
-
server 192.168.201.127:80 weight=1;
-
server 192.168.201.128:80 weight=1;
-
server 192.168.201.129:80 weight=1;
-
server 192.168.201.130:80 weight=1;
-
server 192.168.201.131:80 weight=1;
-
server 192.168.201.132:80 weight=1;
-
server 192.168.201.133:80 weight=1;
-
server 192.168.201.134:80 weight=1;
-
server 192.168.201.136:80 weight=1;
-
server 192.168.201.137:80 weight=1;
-
server 192.168.201.138:80 weight=1;
-
}
-
upstream m_server {
-
# ip_hash;
-
# server 192.168.201.122:80 weight=1;
-
server 192.168.201.123:80 weight=1;
-
server 192.168.201.124:80 weight=1;
-
server 192.168.201.125:80 weight=1;
-
server 192.168.201.126:80 weight=1;
-
server 192.168.201.127:80 weight=1;
-
server 192.168.201.128:80 weight=1;
-
server 192.168.201.129:80 weight=1;
-
server 192.168.201.130:80 weight=1;
-
server 192.168.201.131:80 weight=1;
-
server 192.168.201.132:80 weight=1;
-
server 192.168.201.133:80 weight=1;
-
server 192.168.201.134:80 weight=1;
-
server 192.168.201.136:80 weight=1;
-
server 192.168.201.137:80 weight=1;
-
server 192.168.201.138:80 weight=1;
-
}
-
upstream weixin_server {
-
# ip_hash;
-
server 192.168.201.35:80 weight=1;
-
server 192.168.201.34:80 weight=1;
-
}
-
-
upstream op_server {
-
# ip_hash;
-
server 192.168.201.35:80 weight=1;
-
# server 192.168.201.34:80 weight=1;
-
}
-
#—————————www.lqxshop.com———————–
-
server {
-
listen 80;
-
server_name www.shop.com www.ilqx.cn www.chenggongfang.com wx.lqxshop.c
-
om;
-
#限制每個連線的頻寬大小
-
#limit_rate 40k;
-
#限制每個客戶端ip在指定時間內容允許連線的請求數,且超過限制連線頻率的連線數不
-
得超過burst指定
-
#limit_req zone=reqone burst=50;
-
#使用前面定義的共享記憶體區域,限制每個客戶端IP併發連線的最大數
-
#limit_conn reqnum 20;
-
location / {
-
proxy_set_header HTTP_REFERER $http_referer;
-
proxy_pass http://os_server;
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
index index.html index.php index.htm index.jsp;
-
}
-
}
-
-
#——————————–m.lqxshop.com———————-
-
server {
-
listen 80;
-
#限制每個連線的頻寬大小
-
#limit_rate 40k;
-
#限制每個客戶端ip在指定時間內容允許連線的請求數,且超過限制連線頻率的連線數不
-
得超過burst指定
-
#limit_req zone=reqone burst=50;
-
#使用前面定義的共享記憶體區域,限制每個客戶端IP併發連線的最大數
-
#limit_conn reqnum 20;
-
server_name m.shop.com m1.shop.com m2.shop.com;
-
location / {
-
proxy_pass http://m_server;
-
proxy_set_header HTTP_REFERER $http_referer;
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
index index.html index.htm index.jsp;
-
}
-
}
-
-
#——————————–weixin.lqxshop.com———————-
-
server {
-
listen 80;
-
#限制每個連線的頻寬大小
-
#limit_rate 40k;
-
#限制每個客戶端ip在指定時間內容允許連線的請求數,且超過限制連線頻率的連線數
-
得超過burst指定
-
#limit_req zone=reqone burst=50;
-
#使用前面定義的共享記憶體區域,限制每個客戶端IP併發連線的最大數
-
#limit_conn reqnum 20;
-
server_name weixin.shop.com;
-
location / {
-
proxy_pass http://weixin_server;
-
proxy_set_header HTTP_REFERER $http_referer;
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
index index.html index.htm index.jsp;
-
}
-
}
-
-
-
#——————————–op.lqxshop.com———————-
-
server {
-
listen 80;
-
#限制每個連線的頻寬大小
-
#limit_rate 30k;
-
#限制每個客戶端ip在指定時間內容允許連線的請求數,且超過限制連線頻率的連線數
-
得超過burst指定
-
#limit_req zone=reqone burst=50;
-
#使用前面定義的共享記憶體區域,限制每個客戶端IP併發連線的最大數
-
#limit_conn reqnum 20;
-
server_name op.shop.com;
-
location / {
-
proxy_pass http://op_server;
-
proxy_set_header HTTP_REFERER $http_referer;
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
index index.html index.htm index.jsp;
-
}
-
}
-
-
}
-
-
-
二.APP(Apache+php)搭建
-
1、移除系統自帶的rpm包的http mysql php
-
yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
-
2 安裝必備的開發包
-
/usr/bin/yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel
-
ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel
-
gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel
-
libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libxml2
-
libmhash-devel mysql-devel libxslt libxslt-devel curl tcl expect
3.同步系統時間:
-
vim /etc/ntp.conf
-
server 3.cn.pool.ntp.org
-
server 3.asia.pool.ntp.org
-
server 0.asia.pool.ntp.org
-
chkconfig ntpd on
-
service ntpd restart
-
4.安裝Apache:
-
##############安裝需要的外掛:apr、apr-util、pcre、libmcrypt######################################
-
cd /usr/local/src/
-
cd apr-1.4.8################(rm: cannot remove `libtoolT`: No such file or directory///////修改configure檔案,+++++把RM=`$RM`改為RM=`$RM -f`+++++)
-
./configure –prefix=/usr/local/apr && make && make install
-
cd ../apr-util-1.5.2/
-
./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/ && make && make install
-
cd ../pcre-8.33/
-
./configure –prefix=/usr/local/pcre –enable-utf8 && make && make install
-
cd ../libmcrypt-2.5.8/
-
./configure –prefix=/usr/local/libmcrypt && make && make install
-
###################開始安裝Apache,並修改開啟啟動##################################################
-
cd ../httpd-2.4.6/
-
./configure –prefix=/usr/local/apache –enable-so –enable-rewrite –enable-mods-shared=most –with-mpm=worker –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util/ –with-pcre=/usr/local/pcre/
-
make && make install
-
/usr/local/apache/bin/apachectl start
-
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
-
vim /etc/init.d/httpd(第二行新增註釋資訊,新增為系統服務)
-
# chkconfig: 35 61 61
-
# description: Apache
-
chkconfig –add httpd
-
chkconfig httpd on
-
5.安裝php:
-
cd ../php-5.5.3/
-
./configure –prefix=/usr/local/php –mandir=/usr/local/share/man –infodir=/usr/local/share/info –with-apxs2=/usr/local/apache/bin/apxs –enable-cgi –with-mysql –with-config-file-path=/usr/local/php/etc –with-pdo-mysql –with-mysqli –enable-zip -enable-sockets –enable-soap –enable-pcntl –enable-mbstring –enable-intl –enable-calendar –enable-bcmath –enable-exif –with-mcrypt –with-mhash –with-gd –with-png-dir –with-jpeg-dir –with-freetype-dir –with-libxml-dir –with-curl –with-zlib –with-openssl –with-kerberos=shared –with-gettext=shared –with-xmlrpc=shared –with-mcrypt=/usr/local/libmcrypt
-
make && make install
-
-
裝載XXX模組
-
-
-
cd /usr/local/httpd-2.2.22/modules/generators/
-
/usr/local/apache/bin/apxs -i -a -c mod_cgi.c
-
-
6.apache和php結合:
-
vim /usr/local/apache/conf/httpd.conf
-
查詢AddType application/x-gzip .gz .tgz,在該行下面新增
-
AddType application/x-httpd-php .php
-
查詢DirectoryIndex index.html 把該行修改成
-
DirectoryIndex index.html index.htm index.php
-
測試apache和php是否整合成功,下面我們測試apache和php是否整合成功,在apache文件跟目錄下新建一個小小的php程式
-
cd /usr/local/apache/htdocs
-
vi index.php //在index.php檔案中寫入下面三行
-
<?php
-
phpinfo();
-
?>
-
重啟apache服務
-
/sbin/service httpd restart
-
訪問,在瀏覽器中輸入http://localhost(ip地址)/index.php 出現php資訊介面則說明整合成功
-
elinks http://localhost/index.php
-
成功的頁面
-
-
三.mysql搭建
-
-
10 11
-
軟體原始碼包存放位置 /opt
-
軟體解壓位置 /usr/local/src
-
原始碼包編譯安裝位置(prefix) /usr/local/
-
指令碼以及維護程式存放位置 /script
-
資料庫檔案位置: /data/mysql/
-
資料庫日誌位置: /data/log
-
資料庫備份目錄: /data/backup
-
-
1.解除安裝預設的mysql及apache的rpm包
-
yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
-
yum install ntp
-
service ntpd stop
-
ntpdate cn.pool.ntp.org
-
service ntpd start
-
chkconfig –level 2345 ntpd on
-
-
2.安裝依賴包
-
yum install gcc gcc-c++ make cmake ncurses-devel vim -y
-
cd /opt
-
tar zxvf cmake-2.8.5.tar.gz -C /usr/local/src
-
cd /usr/local/src
-
cd cmake-2.8.5/
-
./configure
-
make && make install
-
cd /opt
-
-
3.編譯安裝mysql
-
tar zxvf mysql-5.5.23.tar.gz -C /usr/local/src/
-
cd /usr/local/src/mysql-5.5.23
-
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-
-DMYSQL_DATADIR=/data/mysql
-
-DWITH_MYISAM_STORAGE_ENGINE=1
-
-DWITH_INNOBASE_STORAGE_ENGINE=1
-
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-
-DENABLED_LOCAL_INFILE=1
-
-DDEFAULT_CHARSET=utf8
-
-DDEFAULT_COLLATION=utf8_general_ci
-
-DEXTRA_CHARSETS=all
-
make && make install
-
groupadd -r -g 3306 mysql
-
useradd -u 3306 -g mysql -r -M -s /sbin/nologin mysql
-
mkdir -p /data/mysql/
-
mkdir -p /data/log/
-
chown -R mysql:mysql /data/
-
chown -R mysql:mysql /usr/local/mysql/*
-
cp support-files/my-huge.cnf /etc/my.cnf
-
-
4.初始化
-
/usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql & //初始化資料庫
-
-
5.啟動項
-
cp support-files/mysql.server /etc/init.d/mysqld
-
chmod +x /etc/init.d/mysqld
-
/chkconfig –add mysqld
-
chkconfig –level 2345 mysqld on
-
service mysqld start
-
netstat -tnlp |grep 3306
-
-
6.相關命令
-
# cd /usr/local/bin //進入使用者的預設搜尋路徑下建立mysql命令的軟連線,可以直接執行mysql命令
-
# ln -s /usr/local/mysql/bin/mysql mysql
-
# ln -s /usr/local/mysql/bin/mysqldump mysqldump
-
# ln -s /usr/local/mysql/bin/mysqladmin mysqladmin
-
# ln -s /usr/local/mysql/bin/mysqlbinlog
-
vim /etc/my.cnf ,在[mysqld]配置引數下面新增下面幾行(大概37行下面),根據服務
-
skip-external-locking
-
key_buffer_size = 256M
-
max_allowed_packet = 500M
-
table_open_cache = 2048
-
sort_buffer_size = 8M
-
read_buffer_size = 4M
-
read_rnd_buffer_size = 16M
-
myisam_sort_buffer_size = 128M
-
-
###新增
-
log-error=/data/log/mysql.err.log
-
skip-name-resolv
-
max_connections = 3000
-
max_connect_errors = 2000
-
-
slow_query_log
-
long_query_time = 2
-
slow_query_log_file = /data/log/slow.log
-
-
bulk_insert_buffer_size = 64M
-
query_cache_type = 1
-
query_cache_size =256M
-
query_cache_limit = 4M
-
ft_min_word_len = 2
-
join_buffer_size = 16M
-
innodb_file_per_table
-
log-bin-trust-function-creators=1
-
myisam_repair_threads = 1
-
innodb_log_files_in_group = 3
-
thread_cache_size = 8
-
# Try number of CPU`s*2 for thread_concurrency
-
thread_concurrency = 8
-
-
innodb_buffer_pool_size = 2G //修改這個引數為實體記憶體的80%
-
-
:wq //儲存退出
-
rm -rvf /data/mysql/ib* myslq-bin* //刪除原來的預設檔案
-
service mysqld restart
-
mysql -u root
-
Mysql> grant all privileges on *.* to lqx@`%` identified by `shlqx1!`;
-
Mysql>flush privileges;
相關文章
- 環境搭建
- windows環境下Django環境搭建WindowsDjango
- react環境搭建React
- LNMP 環境搭建LNMP
- 搭建Java環境Java
- Vagrant 環境搭建
- Flutter環境搭建Flutter
- swoft 環境搭建
- OpenGL 環境搭建
- 搭建gym環境
- 搭建lnmp環境LNMP
- Angular環境搭建Angular
- JDK環境搭建JDK
- keil環境搭建
- Dubbo環境搭建
- mac搭建環境Mac
- FNA 環境搭建
- FNA環境搭建
- Maven 環境搭建Maven
- spark環境搭建Spark
- Hive環境搭建Hive
- lnmp環境搭建LNMP
- ZooKeeper環境搭建
- lnamp環境搭建
- java 環境 搭建Java
- MAVEN環境搭建Maven
- App環境搭建APP
- gogs環境搭建Go
- Windows環境下的Nginx環境搭建WindowsNginx
- window環境下testlink環境搭建(xammp)
- 以太坊-Win環境下remix環境搭建REM
- 【環境搭建】RocketMQ叢集搭建MQ
- Flutter Engine環境搭建Flutter
- iOS逆向環境搭建iOS
- docker搭建php環境DockerPHP
- Supervisor 環境搭建
- Mac 新環境搭建Mac
- Flutter 環境搭建 For MacFlutterMac