1. 程式人生 > >centos-6.5安裝部署LNMP環境

centos-6.5安裝部署LNMP環境

worker download $path format java medium dump ddr 下載源

系統信息:
1 2 3 4 [root@zww ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@zww ~]# uname -r 2.6.32-573.22.1.el6.x86_64
1.安裝nginx: 安裝依賴庫:yum -y install zlib zlib-devel openssl openssl-devel pcre-devel 官網下載源碼包 wget http://nginx.org/download/nginx-1.9.10.tar.gz 解壓: tar xf nginx-1.9.10.tar.gz 編譯安裝,這裏只安裝到/usr/local/nginx-1.9,其它選項可在源碼包目錄執行./configure --help查看
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-pcre && make && make install 出錯:./configure: error: SSL modules require the OpenSSL library.
明顯缺少openssl-devel 安裝:yum install -y openssl-devel 添加運行用戶和用戶組:
1 [root@zww ~]# useradd -M -s /sbin/nologin www
修改nginx配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 [root@zww ~]# vim /usr/local/nginx/conf/nginx.conf user www; worker_processes 2;
error_log /usr/local/nginx/logs/error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k;
large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; #fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; log_format ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; log_format access ‘- $remote_addr - - $time_local "$request" "$http_referer" "$http_user_agent" $body_bytes_sent $http_x_forwarded_for $request_length $status $request_time‘ ; include /usr/local/nginx/conf/vhosts/*.conf; }
啟動前先檢查nginx配置是否有錯:
1 2 [root@localhost nginx]# /usr/local/nginx/sbin/nginx -t ./sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
出錯:解決方法:添加軟鏈接:
ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
前面在一般的linux上可以解決此問題.
註: 在有的操作系統上面,安裝pcre後,安裝的位置為/usr/local/lib/*pcre*
在redhat 64位機器之上有這樣的情況.
在redhat 64位機器上, nginx可能讀取的pcre文件為/lib64/libpcre.so.1文件.
所以64位機器添加軟鏈接:
ln -s /usr/local/lib/libpcre.so.1 /lib64/
再次檢測:
1 2 3 [root@localhost nginx]# ./sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
啟動nginx:
/usr/local/nginx/sbin/nginx -s reload 出錯:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid" 解決: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //nginx -c 指定配置文件位置

設置開機自動啟動nginx:
echo /usr/local/nginx/sbin/nginx >> /etc/rc.d/rc.local
[root@zhiwenwei nginx]# netstat -tlunp|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26752/nginx 2.安裝mysql mysql版本5.5以上編譯安裝時需要用到軟件cmake,cmake特性是獨立於源碼編譯,編譯工作可以在另外一個目錄中而非源碼目錄中進行,好處是可以保證源碼目錄不受任何一次編譯的影響。估計以後的版本也會采用這種方式,所以特地記錄一下安裝步驟及過程,以供參考 安裝依賴軟件庫:yum -y install cmake bison ncurses-devel 創建用戶和用戶組與賦予數據存放目錄權限
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql 解壓mysql源碼包並進入源碼包目錄進行編譯安裝: wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17.tar.gz 解壓進行編譯安裝:tar xf mysql-5.7.17.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_DATADIR=/usr/local/mysql/data && make && make install 報錯:CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
解決:下載boost庫: boost庫官網:http://www.boost.org 下載boost庫並解壓 wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar xf boost_1_59_0.tar.gz 清除緩存並添加-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/opt/boost_1_59_0重新進行編譯安裝:
1 2 3 [root@zww mysql-5.7.17]#make clean [root@zww mysql-5.7.17]#rm -rf CMakeCache.txt [root@zww mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/opt/boost_1_59_0 && make && make install
如果報錯,請除緩存再使用以上命令
make clean
rm -rf CMakeCache.txt
在啟動MySQL服務時,會按照一定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索"$basedir/my.cnf,這裏復制源碼包下的配置文件到etc目錄下並改名為my.conf
cp support-files/my-medium.cnf /etc/my.cnf 或者自己編譯配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 vim /etc/my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock log-error=/data/log/mysql/error.log datadir=/data/mysql_data/ [safe_mysqld] err-log = /var/log/mysqld.log pid-file = /var/lib/mysql/mysqld.pid [mysqldump] quick max_allowed_packet = 16M
初始化數據庫 安裝完畢後必須要進行初始化配置。使用mysql_install_db腳本進行初始化,mysql5.7之前的版本的mysql_install_db是在mysql_basedir/script下的,mysql5.7版本在mysql安裝目錄下的bin目錄. 初始化:
1 [root@zww mysql-5.7.17]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
配置mysql服務腳本:
1 2 3 cp support-files/mysql.server /etc/init.d/mysql chmod 755 /etc/init.d/mysql chkconfig mysql on
或者:echo /usr/local/mysql/support-files/mysql.server start >> /etc/rc.d/rc.local
啟動數據庫:
service mysql start
設置mysql環境變量: export PATH=$PATH:/usr/local/mysql/bin

初始化密碼

mysql5.7會生成一個初始化密碼,而在之前的版本首次不需要登錄。

[root@zww mysql]# cat /root/.mysql_secret
# Password set for user ‘root@localhost‘ at 2017-02-07 16:17:37
+Bcr6_+TMv?w

設置密碼

1 2 3 [root@zww mysql]#mysqladmin -h localhost -uroot password ‘123456‘ -p‘+Bcr6_+TMv?w‘ mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
登錄mysql [root@zww ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

3.php安裝 我的另一篇文章有關於php的安裝記錄: http://www.cnblogs.com/wenwei-blog/p/6261637.html 作者:z寒江雪
出處:http://www.cnblogs.com/wenwei-blog/

centos-6.5安裝部署LNMP環境