1. 程式人生 > >centos6.8下安裝部署LNMP(備註:nginx1.8.0+php5.6.10+mysql5.6.12)

centos6.8下安裝部署LNMP(備註:nginx1.8.0+php5.6.10+mysql5.6.12)

debug pcr chkconfig c++ sam libjpeg php 執行 btool

在平時運維工作中,經常需要用到LNMP應用框架。
以下對LNMP環境部署記錄下:

1)前期準備:為了安裝順利,建議先使用yum安裝依賴庫
[root@opd ~]#yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt mhash mcrypt libmcrypt-devel pcre-devel openssl-devel freetype-devel libcurl-devel

2)安裝nginx
[root@opd ~]#cd /opt/src
[root@src ~]#wget http://nginx.org/download/nginx-1.8.0.tar.gz
[root@src ~]#tar -zxvf nginx-1.8.0.tar.gz
[root@src ~]#cd nginx-1.8.0
添加www用戶,其中-M參數表示不添加用戶家目錄,-s參數表示指定shell類型
[[email protected] ~]#useradd www -M -s /sbin/nologin
[[email protected] ~]#vim auto/cc/gcc
將這句註釋掉取消Debug編譯模式 大概在179行

#CFLAGS="$CFLAGS -g"

我們再配置下nginx編譯參數
[[email protected] ~]#./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[[email protected] ~]#make
[[email protected] ~]#make install clean
添加開機自啟動
[[email protected] ~]#vim /etc/rc.local
在這個文件裏面添加:/opt/nginx/sbin/nginx
[[email protected] ~]#/opt/nginx/sbin/nginx

----------------------------------順便說下:Centos7采用yum方式安裝nginx-----------------------------------
centos7系統庫中默認是沒有nginx的rpm包的,所以我們自己需要先更新下rpm依賴庫
1)使用yum安裝nginx需要包括Nginx的庫,安裝Nginx的庫
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2)使用下面命令安裝nginx
# yum install nginx

3)啟動Nginx
# service nginx start

# systemctl start nginx.service
---------------------------------------------------------------------------------------------------------

3)安裝PHP
由於PHP需要這些類庫的支撐
先下載PHP
[root@opd ~]#cd /opt/src/
[root@src ~]#wget http://cn2.php.net/distributions/php-5.6.10.tar.gz
[root@src ~]#tar -zxvf php-5.6.10.tar.gz
[root@src ~]#cd php-5.6.10
我們先配置下PHP的編譯參數
[[email protected] ~]#./configure --prefix=/opt/php --with-mysql --with-mysqli --with-iconv-dir --with-zlib --with-libxml-dir --enable-xml --with-curl --enable-fpm --enable-mbstring --with-gd --with-openssl --with-mhash --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-libdir=/usr/lib64 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64
[[email protected] ~]#make
[[email protected] ~]#make install clean
復制php.ini
[[email protected] ~]#cp php.ini-development /opt/php/lib/php.ini
[[email protected] ~]#cd /opt/php/etc/
[[email protected] ~]#cp php-fpm.conf.default php-fpm.conf //在php-fpm.conf文件中可以定義php的服務端口、進程啟動的用戶和組權限(最好和nginx服務啟動權限一直)等。
使用PHP-FPM管理腳本,在編譯包裏面已經配置好了,只需要復制到/etc/init.d/中即可
[[email protected] ~]#cd /opt/src/php-5.6.10/sapi/fpm/
[[email protected] ~]#cp init.d.php-fpm /etc/init.d/php-fpm
[[email protected] ~]#chmod +x /etc/init.d/php-fpm
啟動php-fpm
[[email protected] ~]#service php-fpm start or /etc/init.d/php-fpm restart
加入開機啟動策略
[[email protected] ~]#chkconfig --add php-fpm
[[email protected] ~]#chkconfig php-fpm on

---------------------------------------------------------------------------------------------------------

安裝mysql5.6.36

#!/bin/bash
#卸載系統自帶的Mysql
/bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
/bin/rm -f /etc/my.cnf
 
#安裝編譯代碼需要的包
/usr/bin/yum -y install make gcc-c++ cmake bison-devel ncurses-devel
 
#編譯安裝mysql5.6
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql -M -s /sbin/nologin
 
cd /usr/local/src
wget -c http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.36.tar.gz
/bin/tar -zxvf mysql-5.6.36.tar.gz
cd mysql-5.6.36/
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
 
#修改/usr/local/mysql權限
mkdir -p /data/mysql/data
/bin/chown -R mysql:mysql /usr/local/mysql
/bin/chown -R mysql:mysql /data/mysql/data
 
#執行初始化配置腳本,創建系統自帶的數據庫和表
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
 
#配置my.cnf
cat > /usr/local/mysql/my.cnf << EOF
[client]
port = 3306
socket = /usr/local/mysql/var/mysql.sock
 
[mysqld]
port = 3306
socket = /usr/local/mysql/var/mysql.sock
 
basedir = /usr/local/mysql/
datadir = /data/mysql/data
pid-file = /data/mysql/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
sync_binlog=1
log_bin = mysql-bin
 
skip-name-resolve
#skip-networking
back_log = 600
 
max_connections = 3000
max_connect_errors = 3000
##open_files_limit = 65535
table_open_cache = 512
max_allowed_packet = 16M
binlog_cache_size = 16M
max_heap_table_size = 16M
tmp_table_size = 256M
 
read_buffer_size = 1024M
read_rnd_buffer_size = 1024M
sort_buffer_size = 1024M
join_buffer_size = 1024M
key_buffer_size = 8192M
 
thread_cache_size = 8
 
query_cache_size = 512M
query_cache_limit = 1024M
 
ft_min_word_len = 4
 
binlog_format = mixed
expire_logs_days = 30
 
log_error = /data/mysql/data/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/data/mysql-slow.log
 
performance_schema = 0
explicit_defaults_for_timestamp
 
##lower_case_table_names = 1
 
skip-external-locking
 
default_storage_engine = InnoDB
##default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 1024M
innodb_write_io_threads = 1000
innodb_read_io_threads = 1000
innodb_thread_concurrency = 8
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 4M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
 
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
 
interactive_timeout = 28800
wait_timeout = 28800
 
[mysqldump]
quick
max_allowed_packet = 16M
 
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port = 3306
EOF
 
#啟動mysql服務
cd /usr/local/mysql
/bin/mkdir var
/bin/chown -R mysql.mysql var
cp support-files/mysql.server /etc/init.d/mysql
/sbin/chkconfig mysql on
service mysql start
 
#設置環境變量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
 
#設置mysql登陸密碼,初始密碼為123456
/bin/mkdir -p /var/lib/mysql
ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
mysql -e "SET PASSWORD = PASSWORD(‘123456‘);"
mysql -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION;"
mysql -p123456 -e "FLUSH PRIVILEGES;"

  

centos6.8下安裝部署LNMP(備註:nginx1.8.0+php5.6.10+mysql5.6.12)