摘要:因為這次上線的網(wǎng)站沒有什么并發(fā)量,方式要比的方式快而且消耗資源少,所以我還是采用方式。
上線前準(zhǔn)備 購買服務(wù)器,目前選擇的是阿里云服務(wù)器,選擇的是入門型1核1G實例
配置SSH連接目前沒什么活動,三年1400軟妹幣
服務(wù)器配置增加本機ssh連接配置,一般激活實例后,ssh的22端口是默認(rèn)開放的,可以直接通過root用戶進行登錄配置部署環(huán)境
登錄到服務(wù)器后,將自己的公鑰加入到 ~/.ssh/authorized_keys 配置文件中就可直接通過秘鑰進行登錄
上線流程 - 環(huán)境搭建 安裝Mysql5.5服務(wù)器系統(tǒng)版本:CentOS Linux release 7.4.1708 (Core)
內(nèi)存:1G
CPU:1核
硬盤:40G
因為服務(wù)器配置有點低,所以這邊選擇安裝比較低的mysql版本。從CentOS 7.0發(fā)布以來,yum源中開始使用mariadb來代替MySQL的安裝。即使你輸入的是yum install mysql , 顯示的也是mariadb的安裝內(nèi)容,因此,如果使用yum安裝MySQL的話,就需要去下載官方指定的yum源。
網(wǎng)址:?https://dev.mysql.com/downloads/repo/yum/。
先卸載mariadb,查看mariadb是否已經(jīng)安裝
[root@iZbp17dq2xryqoixibq5u1Z ~]# yum list installed | grep mariadb mariadb-libs.x86_64 1:5.5.56-2.el7 @anaconda
進行卸載
[root@iZbp17dq2xryqoixibq5u1Z ~]# yum -y remove mariadb* Loaded plugins: fastestmirror Resolving Dependencies ...... **省略過程** Removed: mariadb-libs.x86_64 1:5.5.56-2.el7 Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1 Complete!
獲取yum源和數(shù)據(jù)庫安裝(官方指南)
wget http://repo.mysql.com/yum/mysql-5.5-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm #MySQL5.5yum源
安裝yum源
rpm -ivh mysql-5.5-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm
安裝好yum源后,需要修改一下配置文件,文件路徑在 /etc/yum.repos.d/mysql-community.repo,要將5.5的enabled改為1,而5.6的enabled改為0
# Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community-dmr] name=MySQL 5.7 Community Server Development Milestone Release baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改后保存退出,開始安裝MySQL。在安裝之前,可以查看下是否已有MySQL可安裝文件
[root@iZbp17dq2xryqoixibq5u1Z ~]# yum repolist enabled | grep "mysql.*-community.*" mysql-connectors-community/x86_64 MySQL Connectors Community 49 mysql-tools-community/x86_64 MySQL Tools Community 61 mysql55-community/x86_64 MySQL 5.5 Community Server 449
安裝mysql
# 安裝client,devel,server yum install mysql-community-client mysql-community-devel mysql-community-server
安裝完畢后,可以查看下當(dāng)前mysql版本
[root@iZbp17dq2xryqoixibq5u1Z ~]# rpm -qi mysql-community-server Name : mysql-community-server Version : 5.5.60 Release : 2.el6 Architecture: x86_64 Install Date: 2018年05月05日 星期六 16:26:00 ......
啟動mysql
執(zhí)行 service mysqld start 啟動mysql
[root@iZbp17dq2xryqoixibq5u1Z ~]# service mysqld start Starting mysqld (via systemctl): [ OK ]
ok,mysql安裝完畢
常用命令:systemctl start mysqld #啟動mysqld
systemctl stop mysqld #停止mysqld
systemctl restart mysqld #重啟mysqld
systemctl enable mysqld #設(shè)置開機啟動
systemctl status mysqld #查看 MySQL Server 狀態(tài)
數(shù)據(jù)庫安全設(shè)置
設(shè)置mysql root賬戶密碼
# mysqladmin -u root password "new password"
重新登錄mysql報如下錯誤
ERROR 1045 (28000): Access denied for user "root"@"localhost" (using password: YES)
執(zhí)行如下命令進行解決
[root@iZbp17dq2xryqoixibq5u1Z ~]# systemctl stop mysqld **關(guān)閉mysql服務(wù)** [root@iZbp17dq2xryqoixibq5u1Z ~]# mysqld --user=root --skip-grant-tables & **關(guān)閉skip-grant-tables** [1] 32163 [root@iZbp17dq2xryqoixibq5u1Z ~]# 180505 16:57:08 [Note] mysqld (mysqld 5.5.60) starting as process 32163 ... 180505 16:57:08 [Note] Plugin "FEDERATED" is disabled. 180505 16:57:08 InnoDB: The InnoDB memory heap is disabled 180505 16:57:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins 180505 16:57:08 InnoDB: Compressed tables use zlib 1.2.3 180505 16:57:08 InnoDB: Using Linux native AIO 180505 16:57:08 InnoDB: Initializing buffer pool, size = 128.0M 180505 16:57:08 InnoDB: Completed initialization of buffer pool 180505 16:57:08 InnoDB: highest supported file format is Barracuda. 180505 16:57:08 InnoDB: Waiting for the background threads to start 180505 16:57:09 InnoDB: 5.5.60 started; log sequence number 1595675 180505 16:57:09 [Note] Server hostname (bind-address): "0.0.0.0"; port: 3306 180505 16:57:09 [Note] - "0.0.0.0" resolves to "0.0.0.0"; 180505 16:57:09 [Note] Server socket created on IP: "0.0.0.0". 180505 16:57:09 [Note] mysqld: ready for connections. Version: "5.5.60" socket: "/var/lib/mysql/mysql.sock" port: 3306 MySQL Community Server (GPL) mysql -u root mysql **空密碼登入** Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.5.60 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> UPDATE user SET authentication_string=PASSWORD("new password") where USER="root"; **重新設(shè)置root密碼** Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> FLUSH PRIVILEGES; **刷新設(shè)置** Query OK, 0 rows affected (0.00 sec) mysql> quit Bye安裝PHP環(huán)境
開始安裝PHP和PHP-FPM
首先安裝EPEL。EPEL即Extra Packages for Enterprise Linux的簡稱,是為企業(yè)級Linux提供的一組高質(zhì)量的額外軟件包
yum -y install epel-release
安裝PHP和PHP-FPM
yum -y install php php-fpm
查看PHP版本
[root@iZbp17dq2xryqoixibq5u1Z ~]# php -v PHP 5.4.16 (cli) (built: Mar 7 2018 13:34:47) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
這時發(fā)現(xiàn)PHP版本是5.4的,原因是yum默認(rèn)的epel-release源太低了,而我需要部署的網(wǎng)站是基于Laravel5.5開發(fā)的,環(huán)境要求:
PHP >= 7.0.0 需要重新安裝PHP7
PHP OpenSSL 擴展
PHP PDO 擴展
PHP Mbstring 擴展
PHP Tokenizer 擴展
PHP XML 擴展
刪除之前安裝的PHP版本
yum remove php* php-common
我們需要更換下rpm源,搜索epel-release源并刪除后進行更新
[root@iZbp17dq2xryqoixibq5u1Z ~]# rpm -qa | grep epel epel-release-7-11.noarch [root@iZbp17dq2xryqoixibq5u1Z ~]# rpm -e epel-release-7-11.noarch warning: /etc/yum.repos.d/epel.repo saved as /etc/yum.repos.d/epel.repo.rpmsave [root@iZbp17dq2xryqoixibq5u1Z ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm warning: /var/tmp/rpm-tmp.PHnPwl: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:epel-release-7-5 ################################# [100%] [root@iZbp17dq2xryqoixibq5u1Z ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm warning: /var/tmp/rpm-tmp.ohTozh: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:webtatic-release-7-3 ################################# [100%]
重新安裝PHP和一些相關(guān)擴展
yum install php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-pdo.x86_64
安裝PHP-FPM
yum install php72w-fpm
再次查看PHP版本
[root@iZbp17dq2xryqoixibq5u1Z ~]# php -v PHP 7.2.4 (cli) (built: Mar 30 2018 08:49:13) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
啟動PHP-FPM
systemctl start php-fpm systemctl enable php-fpm.service **開機自啟動**
常用命令:
systemctl start php-fpm # 啟動安裝Nginxsystemctl stop php-fpm # 停止
systemctl restart php-fpm # 重啟
systemctl enable php-fpm #開機自啟動
開始安裝Nginx
yum install nginx
安裝完畢后,啟動Nginx
systemctl start nginx systemctl enable nginx **系統(tǒng)啟動時自動啟動Nginx**
常用命令:
fuser -k 80/tcp # 殺死80端口網(wǎng)站部署 生成秘鑰nginx -s stop # 停止
nginx -s reopen # 重啟
nginx -s reload # 重新載入配置文件
ssh-keygen -t rsa
提示一直回車就行,將生成的秘鑰添加到項目托管的git庫網(wǎng)站上,因為我的網(wǎng)站是放在Coding上,我直接添加在了項目部署秘鑰
克隆項目通過 git clone 命令將項目拉取到服務(wù)器上,我這邊因為是Nginx,所以我拉取到 /var/www/ 目錄下,
安裝composer[root@iZbp17dq2xryqoixibq5u1Z project_fjylhjjsyxgs]# curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading... Composer (version 1.6.5) successfully installed to: /var/www/project_fjylhjjsyxgs/composer.phar Use it: php composer.phar
移動composer.phar文件到/usr/local/bin目錄下?,使命令全局可用,并更換Packagist中國全量鏡像
mv composer.phar /usr/local/bin/composer composer config -g repo.packagist composer https://packagist.phpcomposer.com
通過composer安裝項目依賴,但是出現(xiàn)了報錯
[root@iZbp17dq2xryqoixibq5u1Z project_fjylhjjsyxgs]# composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for phar-io/manifest 1.0.1 -> satisfiable by phar-io/manifest[1.0.1]. - phar-io/manifest 1.0.1 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 2 - Installation request for phpunit/php-code-coverage 5.3.0 -> satisfiable by phpunit/php-code-coverage[5.3.0]. - phpunit/php-code-coverage 5.3.0 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 3 - Installation request for phpunit/phpunit 6.5.7 -> satisfiable by phpunit/phpunit[6.5.7]. - phpunit/phpunit 6.5.7 requires ext-dom * -> the requested PHP extension dom is missing from your system. Problem 4 - Installation request for theseer/tokenizer 1.1.0 -> satisfiable by theseer/tokenizer[1.1.0]. - theseer/tokenizer 1.1.0 requires ext-dom * -> the requested PHP extension dom is missing from your system. To enable extensions, verify that they are enabled in your .ini files: - /etc/php.ini - /etc/php.d/bz2.ini - /etc/php.d/calendar.ini - /etc/php.d/ctype.ini - /etc/php.d/curl.ini - /etc/php.d/exif.ini - /etc/php.d/fileinfo.ini - /etc/php.d/ftp.ini - /etc/php.d/gd.ini - /etc/php.d/gettext.ini - /etc/php.d/gmp.ini - /etc/php.d/iconv.ini - /etc/php.d/json.ini - /etc/php.d/ldap.ini - /etc/php.d/mbstring.ini - /etc/php.d/pdo.ini - /etc/php.d/pdo_sqlite.ini - /etc/php.d/phar.ini - /etc/php.d/shmop.ini - /etc/php.d/simplexml.ini - /etc/php.d/sockets.ini - /etc/php.d/sqlite3.ini - /etc/php.d/tokenizer.ini - /etc/php.d/xml.ini - /etc/php.d/zip.ini You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Google后發(fā)現(xiàn),php-xml擴展有以上需要的相關(guān)軟件包
yum install php72w-xml.x86_64
重新執(zhí)行composer install命令,依賴下載成功
設(shè)置Nginx配置文件我本機homestead中的Nginx是通過 /etc/nginx/sites-available 目錄設(shè)置對應(yīng)多域名的nginx配置文件,但是不知道服務(wù)器上安裝的Nginx,卻沒有這個目錄,所以查看了下Nginx.conf文件,發(fā)現(xiàn)http模塊中有如下一條配置
本機homestead中Nginx.conf ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; 服務(wù)器上安裝的Nginx.conf # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf;
那好吧,我估計sites-available也是軟連接的conf.d或者sites-enabled目錄吧,所以我就直接將官方手冊中Nginx配置復(fù)制了一份到/etc/nginx/conf.d/域名.conf,修改了一些配置
server { listen 80; server_name 域名或公網(wǎng)IP; root 項目地址指向到public目錄; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; **這里有個坑下面講** fastcgi_index index.php; include fastcgi_params; } location ~ /.(?!well-known).* { deny all; } }
配置完畢,保存退出,通過域名訪問,發(fā)現(xiàn)報502錯誤,查看下Nginx的錯誤日志,發(fā)現(xiàn)報如下錯誤
2018/05/06 20:17:37 [crit] 5898#0: *66 connect() to unix:/var/run/php/php7.2-fpm.sock failed (2: No such file or directory) while connecting to upstream,
簡單的講下,php-fpm.sock文件就是讓Nginx和PHP-FPM的進程間進行通信的文件,具體的含義,這邊就不做詳細(xì)介紹了。進這個目錄查看下是否存在這個目錄或文件,發(fā)現(xiàn)兩個問題:
目錄錯誤,不是/var/run/php,而是/var/run/php-fpm
php7.2-fpm.sock這個文件未生成
未生成原因:php5.3之后的版本,php-fpm.conf里的listen的默認(rèn)配置是127.0.0.1:9000,也就是tcp的方式,不會生成php-fpm.sock。
因為這次上線的網(wǎng)站沒有什么并發(fā)量,unix socket方式要比tcp的方式快而且消耗資源少,所以我還是采用unix socket方式。定位到問題后,修改下 /etc/php-fpm.d/www.conf,也就是php-fpm的配置文件,關(guān)閉原來的listen方式,然后重啟下php-fpm
;listen = 127.0.0.1:9000 listen = /var/run/php-fpm/php7.2-fpm.sock
這個時候,由于職業(yè)習(xí)慣,想把Nginx也重啟下,然后就又碰到了一個問題
[root@iZbp17dq2xryqoixibq5u1Z project_fjylhjjsyxgs]# nginx -s stop [root@iZbp17dq2xryqoixibq5u1Z project_fjylhjjsyxgs]# nginx -s reload nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
這應(yīng)該是因為把Nginx進程殺死后pid丟失了,下一次再開啟nginx -s reload時無法啟動。再次面向Google編程,發(fā)現(xiàn)還有挺多人碰到這個問題,所以解決方法馬上就能搜索到了,執(zhí)行如下命令
nginx -c /etc/nginx/nginx.conf nginx -s reload
ok,接著Navicat遠程連接到服務(wù)器數(shù)據(jù)庫,source下數(shù)據(jù)庫完畢。現(xiàn)看起來應(yīng)該是可以跑起網(wǎng)站來了。再次訪問域名,發(fā)現(xiàn)還是502,再次查看Nginx日志,報如下錯誤:
2018/05/06 20:37:00 [crit] 6078#0: *1 connect() to unix:/var/run/php-fpm/php7.2-fpm.sock failed (13: Permission denied) while connecting to upstream,
和上面報錯看起來差不多,但是這次主要問題出在跑Nginx的用戶是Nginx,而php-fpm.sock這個文件,監(jiān)聽的Nginx用戶沒有該權(quán)限,導(dǎo)致Nginx無法訪問php-fpm.sock這個文件,自然監(jiān)聽就失去了效果,再次修改php-fpm配置文件和重啟下php-fpm
; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. Many ; BSD-derived systems allow connections regardless of permissions. ; Default Values: user and group are set as the running user ; mode is set to 0660 listen.owner = nginx listen.group = nginx listen.mode = 0660
重新訪問下域名,發(fā)現(xiàn)訪問任何路由都是白屏,這次狀態(tài)碼都是200了,但是沒有任何輸出,再次面向Google編程……發(fā)現(xiàn)問題:
由于nginx與php-fpm之間的一個小bug,會導(dǎo)致這樣的現(xiàn)象: 網(wǎng)站中的靜態(tài)頁面?.html 都能正常訪問,而?.php 文件雖然會返回200狀態(tài)碼, 但實際輸出給瀏覽器的頁面內(nèi)容卻是空白。 簡而言之,原因是nginx無法正確的將 *.php 文件的地址傳遞給php-fpm去解析, 相當(dāng)于php-fpm接受到了請求,但這請求卻指向一個不存在的文件,于是返回空結(jié)果。 為了解決這個問題,需要改動nginx默認(rèn)的fastcgiparams配置文件
在 /etc/nginx/fastcgi_params 文件的最后增加兩行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name;
再再再次訪問域名,終于正常顯示了,但是頁面上又出現(xiàn)了新的錯誤:
could not find driver(select * from users where deleted = 0)
任何有sql查詢的頁面都報如上錯誤,這個錯誤多半是因為pdo_mysql未打開或者未安裝此模塊造成,執(zhí)行 php -m 發(fā)現(xiàn)還真沒裝,安裝php72w-mysql又遇到一個坑
yum install php72w-mysql
報如下錯誤,說缺少libmysqlclient.so.18依賴
...... error: package: php72w-mysql requires: libmysqlclient.so.18(libmysqlclient_18)(64bit) Available: 1:mariadb-libs-5.5.52-1.el7.x86_64 (base) libmysqlclient.so.18(libmysqlclient_18)(64bit) ......
這就很奇怪了,查看用戶庫文件目錄內(nèi)libmysqlclient.so.18已經(jīng)存在
[root@iZbp17dq2xryqoixibq5u1Z ~]# ll /usr/lib64/mysql/libmysqlclient.so.18 libmysqlclient.so.18 libmysqlclient.so.18.1.0
這個坑花了一個小時,Google多次嘗試無果后,認(rèn)真思考下可能的原因,想了想可能是mysql版本的問題,修改下 /etc/yum.repos.d/mysql-community.repo 配置文件,將5.6的enabled設(shè)為1,5.5設(shè)為0,更新Mysql版本后,再次執(zhí)行 yum install php72w-mysql 安裝pdo_mysql模塊成功…...
至此,網(wǎng)站訪問終于成功!后續(xù)的部署優(yōu)化,另外開篇記錄。
原文博客地址
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/29674.html
摘要:因為這次上線的網(wǎng)站沒有什么并發(fā)量,方式要比的方式快而且消耗資源少,所以我還是采用方式。 上線前準(zhǔn)備 購買服務(wù)器,目前選擇的是阿里云服務(wù)器,選擇的是入門型1核1G實例 目前沒什么活動,三年1400軟妹幣 配置SSH連接 增加本機ssh連接配置,一般激活實例后,ssh的22端口是默認(rèn)開放的,可以直接通過root用戶進行登錄配置部署環(huán)境 登錄到服務(wù)器后,將自己的公鑰加入到 ~/.ssh/a...
摘要:由于初版需求及開發(fā)工作都沒有參與,在接手項目后過了遍前端結(jié)構(gòu)發(fā)現(xiàn)所有交互及組件都是現(xiàn)擼,并未使用市面上已有的優(yōu)秀前端框架從我個人角度理解上出發(fā),后續(xù)需求變更中當(dāng)需要實現(xiàn)某些常用組件樣式或交互時,基本上都需要現(xiàn)擼或者尋找合適的組件。 2016悄無聲息的過去了,再過不久便是農(nóng)歷新年 這幾天相對清閑梳理了一下去年所做的工作,希望在新的一年能發(fā)展的更好 今年一共研發(fā)或升級了五款產(chǎn)品:合伙人、奪...
閱讀 3427·2021-09-26 09:46
閱讀 2782·2021-09-13 10:23
閱讀 3510·2021-09-07 10:24
閱讀 2388·2019-08-29 13:20
閱讀 2919·2019-08-28 17:57
閱讀 3072·2019-08-26 13:27
閱讀 1175·2019-08-26 12:09
閱讀 505·2019-08-26 10:27