//购服务器
https://help.aliyun.com/document_detail/59075.html?spm=a2c4g.11186623.6.547.1lX205
//配置应用
//远程连接
//搭建环境
//项目部署
安装系统
/***镜像部署lunix***/
https://help.aliyun.com/document_detail/25427.html?spm=a2c4g.11186623.6.802.StMaaC
/***手动部署lunix****/
远程连接
/********通过ssh远程连接到Linux操作系统(账密登陆)*********/
//配置文件:/etc/ssh/sshd_config
//运行命令:sudo vi /etc/ssh/sshd_config
//修改内容:PasswordAuthentication yes
PasswordAuthentication yes #允账密登
//重启服务
sudo service sshd reload
# 或者:sudo /bin/systemctl reload sshd.service
//重置账密(安全起见)
# sudo passwd you_user_name
sudo passwd admin
//远程登录
ssh -p 22 root@39.108.163.73
ssh -p 22 admin@39.108.163.73
/********通过ssh远程连接到Linux操作系统(密钥登陆)*********/
//方案1
//配置文件
//远程登录
//切换用户
sudo su root
//编辑文件
sudo vi /etc/ssh/sshd_config
//注:配置内容如下
HostKey /etc/ssh/ssh_host_rsa_key
RSAAuthentication yes #RSA认证
PubkeyAuthentication yes #公钥认证
AuthorizedKeysFile .ssh/authorized_keys #文件存放
PasswordAuthentication yes #允账密登
https://www.cnblogs.com/panda2046/p/5933498.html
//重启服务
sudo service sshd restart
//创建密钥
//ssh-keygen
# ssh-keygen -t ecdsa -C "web-server-aliyun hualei03042013@163.com" -f /c/Users/home/.ssh/web-server-aliyun3
ssh-keygen -t rsa -b 2048 -f /c/Users/home/.ssh/web-server-aliyun-v1.0.0 -C "web-server-aliyun-hualei03042013@163.com"
-b:指定密钥长度;
-e:读取openssh的私钥或者公钥文件;
-C:添加注释;
-f:指定用来保存密钥的文件名;
-i:读取未加密的ssh-v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥;
-l:显示公钥文件的指纹数据;
-N:提供一个新密语;
-P:提供(旧)密语;
-q:静默模式;
-t:指定要创建的密钥类型。
//查看公钥
# cat /c/Users/home/.ssh/web-server-aliyun3.pub
cat /c/Users/home/.ssh/web-server-aliyun-v1.0.0.pub
//上传公钥
# 方式1:
#ssh-copy-id -i ~/.ssh/web-server-aliyun3.pub root@39.108.163.73
ssh-copy-id -i ~/.ssh/web-server-aliyun-v1.0.0.pub root@39.108.163.73
# 方式2:
scp -r ~/.ssh/web-server-aliyun3.pub root@39.108.163.73:~/ .ssh/authorized_key
//修改权限
# chmod 400 ~/.ssh/web-server-aliyun3
chmod 400 ~/.ssh/web-server-aliyun-v1.0.0
//连服务器
# ssh -i ~/.ssh/web-server-aliyun3 root@39.108.163.73(不推荐以root用户登录)
ssh -i ~/.ssh/web-server-aliyun-v1.0.0 admin@39.108.163.73
//遇到问题
问题:sh: .ssh/authorized_keys: Permission denied
情景:以admin用户上传公钥失败,ssh-copy-id -i ~/.ssh/web-server-aliyun-v1.0.0.pub admin@39.108.163.73。
原因: ~/.ssh的权限属于root用户(sudo ls -al ~)
解决:
方式1以root用户登录:ssh -i ~/.ssh/web-server-aliyun-v1.0.0 root@39.108.163.73;
方式2修改权限属于admin: sudo chown -R admin:admin ~/.ssh。
//方案2:(web界面操作)
//配置文件
https://www.cnblogs.com/panda2046/p/5933498.html
//重启服务
sudo service sshd restart
//生成密钥
//下载私钥
//修改权限
chmod 400 ~/.ssh/web-server-aliyun3.pem
//连服务器
# ssh -i ~/.ssh/web-server-aliyun3.pem root@39.108.163.73
# ssh -i ~/.ssh/web-server-aliyun3.pem admin@39.108.163.73
ssh -i ~/.ssh/my-aliyun-v1.0.0.pem admin@39.108.163.73
//遇到问题
//The fingerprint for the ECDSA key sent by the remote host is。。。
rm ~/.ssh/known_hosts
//或者打开它,删除对应的私钥。使用密钥登录过后,又改了密钥时出现。
/********通过ssh远程连接到Linux操作系统(免密登陆)*********/
# 修改配置
# 在密钥登录的基础上,关闭密码登录
PasswordAuthentication no
# 重启服务
sudo service sshd reload
# 本地登录
ssh -i ~/.ssh/my-aliyun-v1.0.0.pem admin@39.108.163.73
# 遇到问题
问题:root@39.108.163.73: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
解决:尚未
# 参考文献:https://blog.csdn.net/yanzhibo/article/details/75804619
/********通过桌面远程连接到Linux操作系统*********/
//steps-01:
WIN键+R键,输入mstsc,回车
//steps-02:
地址:39.108.163.73
用户:admin
密码:xxxxxxxx(保密)
(win连linux此法连不通?需要win连win?)
/*********通过密码登陆远程服务器*************/
//远程连接
//切换用户
sudo su root
//配置文件
vi /etc/ssh/sshd_config
i
PasswordAuthentication yes #允账密登
esc
:wq
//重启服务
sudo service sshd reload
# 实际:sudo /bin/systemctl reload sshd.service
//重置账密
sudo passwd admin
//远程登陆
# ssh -p 22 root@39.108.163.73(不推荐)
ssh -p 22 admin@39.108.163.73
//输入密码
//退出登陆
输入“~”与“Ctrl-Z”组合。
//备注:你输入“~”你不会立即在屏幕上看到,当你按下<Control-Z>并且按回车之后才一起显示。
//或者:
exit
搭建环境
/******Nginx 手动安装配置********/
//系统平台:CentOS release 6.6 (Final) 64位。
//step-01:安装依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
//step-02:安装 PCRE(让 Nginx 支持 Rewrite 功能。)
//下安装包
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
//解压缩包
tar zxvf pcre-8.35.tar.gz
//编译安装
./configure
make && make install
//查看版本
pcre-config --version
//step-03:安装
//下安装包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
//节压缩包
tar zxvf nginx-1.6.2.tar.gz
//进入目录
cd nginx-1.6.2
//配置
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
//编译
make
//安装
make install
//查看版本
/usr/local/webserver/nginx/sbin/nginx -v
//step-04:配置
//添加群组
/usr/sbin/groupadd www
//添加用户
/usr/sbin/useradd -g www www
//查看配置
cat /usr/local/webserver/nginx/conf/nginx.conf
//编辑配置
//检验配置
/usr/local/webserver/nginx/sbin/nginx -t
//启服务器
/usr/local/webserver/nginx/sbin/nginx
//访问站点
//其他命令
/usr/local/webserver/nginx/sbin/nginx -s reload # 重载配置
/usr/local/webserver/nginx/sbin/nginx -s reopen # 重新启动
/usr/local/webserver/nginx/sbin/nginx -s stop # 立即停止
/usr/local/webserver/nginx/sbin/nginx -s quit # 平滑停止
//以上为默认的安装目录
//以下为宝塔的安装目录
nginx-1.12源码目录:/www/server/nginx/src
nginx-1.12安装目录:/www/server/nginx
nginx-1.12编译参数:/www/server/php/54/src/config.nice
nginx-1.12配置文件:/www/server/nginx/conf
nginx-1.12进程查看:ps -ef | grep nginx
/******MySQL 手动安装配置********/
//操作系统:CentOS release 6.6 (Final) 64位。
//step-01:安装依赖
yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel
//step-02:装编译器
// 下安装包
wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz
// 解安装包
tar zxvf cmake-3.1.1.tar.gz
// 进入目录
cd cmake-3.1.1
// 编译安装
./bootstrap
make && make install
//step-03:安装
// 下安装包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz
// 解安装包
tar zxvf mysql-5.6.15.tar.gz
// 进入目录
cd mysql-5.6.15
// 编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_INNODB_MEMCACHED=1 -DWITH_DEBUG=OFF -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DMYSQL_TCP_PORT=3306
make && make install
// 查看版本
/usr/local/webserver/mysql/bin/mysql --version
//step-04:配置
// 添加群组
/usr/sbin/groupadd mysql
// 添加用户
/usr/sbin/useradd -g mysql mysql
// 赋予权限
mkdir -p /usr/local/webserver/mysql/binlog /www/data_mysql
chown mysql.mysql /usr/local/webserver/mysql/binlog/ /www/data_mysql/
// 配置文件
// 库初始化
/usr/local/webserver/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
// 开机启动
cd /usr/local/webserver/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
// 启服务器
service mysqld start
// 看其状态
service mysql status
// 连服务器
/usr/local/webserver/mysql/bin/mysql -u root -p
// 改用户密
mysql
SET PASSWORD FOR '用户名'@'主机' = PASSWORD(‘密码');
// 其他命令
启动:service mysqld start
停止:service mysqld stop
重启:service mysqld restart
重载配置:service mysqld reload
/******php 手动安装配置********/
//下源码包
//解源码包
//配置
./configure --prefix=/www/server/php/54
//编译
make
//安装
make install
php-5.4源码目录:/www/server/php/54/src
php-5.4安装目录:/www/server/php/54/bin
php-5.4编译参数:/www/server/php/54/src/config.nice
php-5.4配置文件:/www/server/php/54/etc
php-5.4类库目录:/www/server/php/54/lib
php-5.4安装目录:whereis php
php-fpm配置编辑:vim /www/server/php/54/etc/php-fpm.conf
php-fpm启动程序:/www/server/php/54/sbin/php-fpm
php-fpm端口查看:ps -ef|grep php-fpm
php-fpm开机启动:vi /etc/rc.local
php-fpm立刻关闭:kill -INT `cat /www/server/php/54/var/run/php-fpm.pid`
php-fpm平滑关闭:kill -QUIT `cat /www/server/php/54/var/run/php-fpm.pid`
php-fpm平滑重启:kill -USR2 `cat /www/server/php/54/var/run/php-fpm.pid`
php-fpm其慢日志:/www/server/php/54/var/log/slow.log
pear安装目录:/www/server/php/54/bin
pear配置文件:/www/server/php/54/etc
pear下载某包:pear download packagename
pear安装某包:pear install packagename
pear更新某包:pear upgrade packagename
pear删除某包:pear uninstall packagename
/******php 与nginx使用socket方式通信********/
//step-01:修改nginx.conf
# 原:fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi-54.sock;【#unxi domain socket形式】
//step-02:修改php-fpm.conf
# 原:listen = 127.0.0.1:9000
listen = /tmp/php-cgi-54.sock
//step-03:重启nginx 、php-fpm
/www/server/nginx/sbin/nginx -s reload
kill -USR2 `cat /www/server/php/54/var/run/php-fpm.pid`
//step-04:查看:
ps -ef|grep php-fpm
ps -ef|grep nginx
/******pm2 nodejs npm nvm mongoose 手动安装配置********/
//登服务器
ssh 用户名@公网IP
//下安装包
$ wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz
//解安装包
$ tar xvf node-v6.9.5-linux-x64.tar.xz
//创软链接,使node和npm命令全局有效
ln −s /root/node−v6.9.5−linux−x64/bin/node /usr/local/bin/node
ln -s /root/node-v6.9.5-linux-x64/bin/npm /usr/local/bin/npm
//查看版本
node −v
npm -v
//注:软件默认安装在/root/node-v6.9.5-linux-x64/目录下,若想安装在其他目录,如/opt/node/:
mkdir −p /opt/node/
//移动文件
mv /root/node-v6.9.5-linux-x64/* /opt/node/
//删除文件
rm −f /usr/local/bin/node && rm -f /usr/local/bin/npm
//创软链接
ln −s /opt/node/bin/node/usr/local/bin/node &&ln -s /opt/node/bin/npm
//安装nvm
yum install git
git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout git describe --abbrev=0 --tags
echo “. ~/.nvm/nvm.sh” >> /etc/profile
source /etc/profile
//列出Node.js的所有版本
nvm ls
//安装多个Node.js版本
nvm install v6.9.5
nvm install v7.4.0
//查看已装Node.js版本
nvm ls
//切换其他Node.js版本
nvm use v7.4.0
/***手动部署:安装mongodb**/
//切换目录
cd /usr/local
//下压缩包
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.5.tgz
//解压缩包
tar zxvf mongodb-linux-x86_64-3.4.5.tgz
//重新命名
mv mongodb-linux-x86_64-3.4.5 mongodb
//创建目录
mkdir /var/mongodb
mkdir /var/mongodb/data
mkdir /var/mongodb/logs
//设开机启
//编辑文件
vim /etc/rc.d/rc.local
//输入模式
i
//粘贴内容
/opt/mongodb/bin/mongod --dbpath=/var/mongodb/data --logpath /var/mongodb/logs/log.log -fork
//退出编辑
esc
//保存关闭
:wq
//手动启动
/opt/mongodb/bin/mongod --dbpath=/var/mongodb/data --logpath /var/mongodb/logs/log.log -fork
//以上使用目录:
软件安装位置:/usr/local/mongodb
数据存放位置:/var/mongodb/data
日志存放位置:/var/mongodb/logs
/****安装pm2*****/
//全局安装
npm install pm2 -g
//查看版本
pm2 -v
//设环变量
//打开文件
vim /etc/profile
//输入模式
i
//添加内容
PATH=$PATH:/opt/node/lib/node_modules/pm2/bin
//退出编辑
esc
//保存关闭
:wq
//让其生效
source /etc/profile
//部署运行
//控制台进入存放代码的目录,和本地操作类似,如,本地使用node /bin/www 启动项目,这里换成pm2 start /bin/www。
宝塔安装目录
git安装目录:/usr/bin/git /usr/share/man/man1/git.1.gz
nvm安装目录:
/********部署测试********/
//创建文件
touch server.js
//编辑文件
vim server.js
//输入模式
i
//粘贴内容
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
//命令模式
esc
//保存退出
:wq
//运行脚本
node server.js
//后台运行:node server.js &
//查看端口
netstat -tpln
//放行端口
//阿里云ECS云服务器:登录ECS管理控制台,并在安全组中 添加安全组规则 放行端口(如本示例中为TCP 3000端口)。
//阿里云SAS云服务器:登陆轻量应用服务器控制台,在防火墙处放行。
//浏览查看
//在本地机器的浏览器中输入 http://实例公网IP地址:端口号 访问项目。
/********lunix上一键部署LNMP环境***********/
https://help.aliyun.com/document_detail/53077.html?spm=a2c4g.11186623.6.801.AprgD0
/********lunix上手动部署LNMP环境***********/
https://help.aliyun.com/document_detail/50700.html?spm=a2c4g.11186623.6.803.UW8nOM
//查看系统
cat /etc/redhat-release
//关闭SELINUX
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
//放行端口
/**安装nginx**/
//添加运行nginx服务进程的用户
//安装依赖
yum groupinstall "Development tools"
yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
//下源码包
wget http://nginx.org/download/nginx-1.10.2.tar.gz
//解压
tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
//配置
cd /usr/local/src/nginx-1.10.2
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
//编译安装
make && make install
//
mkdir -pv /var/tmp/nginx/client
//添加系统启动脚本
# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
//赋予脚本执行权限
chmod +x /etc/init.d/nginx
//添加至服务管理列表,设置开机自启
chkconfig --add nginx
chkconfig nginx on
//启动服务
service nginx start
/***安装mysql**/
环境搭建-手动搭建2
//步骤一:准备编译环境
# 查看系统版本
cat /etc/redhat-release
# 重启服务后永久生效。
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
# 关闭防火墙
setenforce 0
//步骤二:安装nginx
# 添加运行nginx服务进程的群组
groupadd -r nginx
# 添加运行nginx服务进程的用户
useradd -r -g nginx nginx
# 下载源码包解压编译
# 下源码包
wget http://nginx.org/download/nginx-1.10.2.tar.gz
# 解压缩包
tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
# 下编译包
yum groupinstall "Development tools"
yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
# 切换目录
cd /usr/local/src/nginx-1.10.2
# 执行配置
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
# 编译安装
make && make install
# 添加SysV启动脚本
# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
# 赋予脚本执行权限。
chmod +x /etc/init.d/nginx
# 添加至服务管理列表,设置开机自启。
chkconfig --add nginx
chkconfig nginx on
# 启动服务。
service nginx start
启动报错:
解决:
cd /var/tmp/
mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
# 浏览器访问可看到默认欢迎页面。
步骤三:安装mysql
#1.准备编译环境。
yum groupinstall "Server Platform Development" "Development tools" -y
yum install cmake -y
install ncurses-devel -y
#2.准备mysql数据存放目录。
mkdir /mnt/data
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql
id mysql
#3、更改数据目录属主属组。
chown -R mysql:mysql /mnt/data
# 下源码包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz
# 解压缩包
tar xvf mysql-5.6.24.tar.gz -C /usr/local/src
# 切换目录
cd /usr/local/src/mysql-5.6.24
# 配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
# 配置出错:
问题:Could NOT find Curses
解决:
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
./configure -prefix=/usr/local -with-shared-without-debug
make && make install
或者rm CMakeCache.txt && yum install ncurses-devel -y
# 编译安装
make && make install
# 修改安装目录的属组为mysql。
chown -R mysql:mysql /usr/local/mysql/
# 初始化数据库
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/mnt/data/
mv /etc/my.cnf /etc/my.cnf.backup
# 拷贝配置文件和启动脚本。
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
# 设置开机自动启动。
chkconfig --add mysqld
chkconfig mysqld on
# 修改配置文件中的安装路径及数据目录存放路径。
echo -e "basedir = /usr/local/mysql\ndatadir = /mnt/data\n" >> /etc/my.cnf
# 设置PATH环境变量。
echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
# 启动服务。
service mysqld start
mysql -h 127.0.0.1
步骤四:安装php-fpm
# 1.安装依赖
yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel
# 2、解压官网下载的源码包,编译安装。
//下源码包
wget http://cn2.php.net/distributions/php-5.6.36.tar.bz2
//解压缩包
tar xvf php-5.6.36.tar.bz2 -C /usr/local/src
//切换目录
cd /usr/local/src/php-5.6.36
//执行配置
./configure --prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-openssl \
-enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-bz2 \
--disable-fileinfo
//编译安装
make && make install
问题:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1 时
解决:--disable-fileinfo
# 3、添加php和php-fpm配置文件。
cp /usr/local/src/php-5.6.36/php.ini-production /etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf
# 4、添加php-fpm启动脚本。
cp /usr/local/src/php-5.6.36/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
# 5、添加php-fpm至服务列表并设置开机自启。
chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on
# 6、启动服务。
service php-fpm start
# 7、添加nginx对fastcgi的支持,首先备份默认的配置文件。
//备份配置
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//编辑文件
vim /etc/nginx/nginx.conf
//输入模式
i
//输入内容:
location / {
root /usr/local/nginx/html;
index index.php index.html index.htm;
}
//取消注释:
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
//退出保存
esc
:wq
//重载配置
service nginx reload
//测试页面
vim /usr/local/nginx/html/index.php
i
<?php
$conn=mysql_connect('127.0.0.1','root','');
if ($conn){
echo "LNMP platform connect to mysql is successful!";
}else{
echo "LNMP platform connect to mysql is failed!";
}
phpinfo();
?>
esc
:wq
# 8、php与nginx使用socket方式通信
//step-01:修改nginx.conf
# 原:fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi-56.sock;【#unxi domain socket形式】
//step-02:修改php-fpm.conf
# 原:listen = 127.0.0.1:9000
listen = /tmp/php-cgi-56.sock
//step-03:重启nginx 、php-fpm
/www/server/nginx/sbin/nginx -s reload
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
//?(很多教程使用路径/tmp,而路径/dev/shm是个tmpfs,速度比磁盘快得多)
应用程序安装信息:
nginx-1.12安装目录:/usr/local/nginx/nginx
nginx-1.12配置文件:/usr/local/nginx/nginx.conf
NVM-0.33.1安装目录:/root/nvm
Node.js 4.8.4安装目录:/root/nvm/versions/node/v4.8.4
PM2 2.5.11安装目录:/root/nvm/versions/node/v4.8.4/bin/pm2
MongoDB 3.0.6安装目录:/usr/local/mongodb/
MongoDB 3.0.6存放数据:/var/mongodb/data
MongoDB 3.0.6日志目录:/var/mongodb/logs
## nvm的使用
安装稳定版本: #nvm install stable
安装指定版本: #nvm install 5.4
查看当前 node 版本(默认为最后一次安装版本):
#nvm current
切换 node 版本:
# nvm use 7
显示所有安装的版本:
# nvm ls
## npm的使用
升级 npm:
#npm install npm –g
使用 npm 安装 nodejs 模块:
#npm install (-g)
[注]使用-g 是全局安装。
查看所安装的模块:
#npm ls
更新模块:
#npm update
搜索模块:
#npm search
## pm2的使用
启动:
pm2 start app.js –watch
重启:
pm2 restart app.js
停止:
pm2 list
pm2 stop app_name|app_id
//停止所有应用:pm2 stop all
查看进行状态:
pm2 list
查看某个进程信息:
pm2 describe app_id
## MongoDB数据迁移
(1)导出数据
SHAPE \* MERGEFORMAT
#mongodump –d dbname –p passwd –o dbdireactory
-h: mongodb 所在服务器地址
-d: 需要备份的数据库名称,例如:test_data
-o: 备份的数据存放的位置,例如:/disk1/bak
-u: 用户名称,使用权限验证的 mongodb 服务,需要指明导出账号
-p:用户密码,使用权限验证的 mongodb 服务,需要指明导出账号密码
(2)导入数据
SHAPE \* MERGEFORMAT
#mongorestore -d dbname -dorectoryperdb dbdireactory
-h: mongodb 所在服务器地址
-d: 需要恢复备份的数据库名称
-directoryperdb: 备份数据所在位置,例如:/disk1/bak
-drop: 加上这个参数的时候,会在恢复数据之前删除当前数据;
(3)修复数据
①在启动 Mongo 时加上--repair 参数
②在 Mongo shell 中进行修复
>use db1
>db.repairDataBase()
项目部署
//方案1:
1.- 将本地代码托管到github
2.- 在服务器中将代码clone下来
scp [参数] <源地址(用户名@IP地址或主机名)>:<文件路径> <目的地址(用户名 @IP 地址或主机
github (前提是项目是开源)
//scp用法参考:http://www.runoob.com/linux/linux-comm-scp.html
//方案2:https://blog.csdn.net/chenlinIT/article/details/73343793
//https://help.aliyun.com/document_detail/50775.html
## 好文:https://blog.csdn.net/kkkkkxiaofei/article/details/76173202
其他
##宝塔代理
一个站点一个ip;不熟悉其时,代理先通过界面设计。
一个代理一个虚拟主机:/www/server/panel/vhost/rewrite/ymc-home.top.conf;
一个站点的配置文件:/www/server/panel/vhost/nginx
一个站点的地址重写:/www/server/panel/vhost/rewrite
一个站点的内部实现:/www/server/panel/vhost/apache
使用的apache
/*********nginx的端口监听地址修改**********/
//远程连接
//查看进程
netstat -an | grep 80
//查找配置
find / -name nginx.conf
//修改配制
//打开文件
vim /etc/nginx/nginx.conf
//输入模式
i
//修改内容
server {
listen 实例公网IP地址:80;
server_name localhost;
}
//退出输入
esc
//保存退出
:wq
//重启服务
/*********nginx的代理转发**********/
# 一级域名
server {
listen 443 ssl;
server_name www.yourdomain.com; #修改为需要的一级域名即可
access_log logs/ssl.access.log;
error_log logs/ssl.error.log crit;
include ssl_params;
location / {
index index.html index.htm index.php;
index proxy_set_header Host $host;
index proxy_set_header X-Real-IP $remote_addr;
index proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_cluster; #后端服务器,具体配置upstream部分即可
}
}
# 二级域名
# 内网转发
location /location名称/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/服务名/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 三方接口
location /unionpay/ {
proxy_set_header Host gateway.银联.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://gateway.银联.com/;
}
# 协议转换
server {
listen 80;
server_name api.yourdomain.com;
location / {
rewrite ^/(.*) https://api.yourdomain.com/$1 permanent ;
break;
}
error_page 497 https://$host:$server_port$request_uri;
}
server {
listen 443 ssl;
server_name api.yourdomain.com;
access_log logs/ssl.api_access.log;
error_log logs/ssl.api_error.log crit;
include ssl_params;
location / {
proxy_pass http://tomcat_servers/$2;
proxy_set_header Host $host:443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /v1.0/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_servers/v1.0/;
proxy_cookie_path /v1.0/ /;
proxy_redirect off;
}
}
# 后缀转发
location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1;
}
# 参数转发
# ws支持
location /drsws/ {
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
/*********nginx的负载均衡**********/
//几种方式
//常规配置
upstream www_server_pools {
server 172.16.1.16:80 ;
server 172.16.1.17:80 ;
}
server {
listen 80;
server_name www_server_pools;
location / {
access_log logs/access.log main;
proxy_pass http://www_server_pools;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect default;
proxy_buffer_size 512k;
proxy_buffers 6 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
client_max_body_size 100m;
}
}
# 动静分离
upstream static_pools {
server 192.168.1.189:80 ;
}
upstream upload_pools {
server 192.168.1.190:80 ;
}
upstream default_pools {
server 192.168.1.188:80 ;
}
server {
listen 80;
server_name www_server_pool;
location /static/ {
proxy_pass http://static_pools;
include proxy.conf;
}
location /upload/ {
proxy_pass http://upload_pools;
include proxy.conf;
}
location / {
proxy_pass http://default_pools;
include proxy.conf;
}
}
# 设备区分
upstream static_pools {
server 192.168.1.189:80 ;
}
upstream upload_pools {
server 192.168.1.190:80 ;
}
upstream default_pools {
server 192.168.1.188:80 ;
}
server {
listen 80;
server_name www_server_pool;
location / {
# IE浏览器
if ($http_user_agent ~* "MSIE")
{
proxy_pass http://static_pools;
}
# 谷歌浏览器
if ($http_user_agent ~* "Chrome")
{
proxy_pass http://upload_pools;
}
# 安卓
# 苹果
# 默认
proxy_pass http://default_pools;
include proxy.conf;
}
}
# 文件区分
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
proxy_pass http://default_pools;
include proxy.conf;
if ($request_uri ~* ".*\.(php|php5)$")
{
proxy_pass http://static_pools;
}
if ($request_uri ~* ".*\.(jps|jps*|do|do*)$")
{
proxy_pass http://static_pools;
}
# 健康检查
# 版本切换
//参考:http://blog.51cto.com/13178102/2063271
# 使用示例
# 版本切换-php
server
{
listen 80;
server_name 127.0.0.2;
allow 127.0.0.1;
index phpinfo.php index.html index.php;
root /www/server/phpinfo;
location /52 {
include enable-php-52.conf;
}
location /53 {
include enable-php-53.conf;
}
location /54 {
include enable-php-54.conf;
}
location /55 {
include enable-php-55.conf;
}
location /56 {
include enable-php-56.conf;
}
location /70 {
include enable-php-70.conf;
}
location /71 {
include enable-php-71.conf;
}
}
# 状态切换-phpfpm
server {
listen 80;
server_name 127.0.0.1;
allow 127.0.0.1;
location /nginx_status {
stub_status on;
access_log off;
}
location /phpfpm_52_status {
fastcgi_pass unix:/tmp/php-cgi-52.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_53_status {
fastcgi_pass unix:/tmp/php-cgi-53.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_54_status {
fastcgi_pass unix:/tmp/php-cgi-54.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_55_status {
fastcgi_pass unix:/tmp/php-cgi-55.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_56_status {
fastcgi_pass unix:/tmp/php-cgi-56.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_70_status {
fastcgi_pass unix:/tmp/php-cgi-70.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_71_status {
fastcgi_pass unix:/tmp/php-cgi-71.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
location /phpfpm_72_status {
fastcgi_pass unix:/tmp/php-cgi-72.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
}
//搭建站点
前端服务器:http://39.108.163.73:3000/
后端服务器:http://39.108.163.73:2222/
静资服务器:http://39.108.163.73:80
//接口请求
//页面请求
server
{
listen 80;
server_name ymc-home.top;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/ymc-home.top;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
error_page 404 /404.html;
error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-54.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/ymc-home.top.conf;
#REWRITE-END
# 静资服务器
location ^~ /static/
{
root /www/wwwroot/ymc-home.top/static;
}
location ^~ /fe-server/
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://39.108.163.73:3000/;
}
# 接口转发
location ^~ /api/
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1;
}
#
access_log /www/wwwlogs/ymc-home.top.log;
}
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/www/wwwroot/ymc-home.top"
ServerName 36dc2fd9.ymc-home.top
ServerAlias ymc-home.top
errorDocument 404 /404.html
ErrorLog "/www/wwwlogs/ymc-home.top-error_log"
CustomLog "/www/wwwlogs/ymc-home.top-access_log" combined
#PROXY-START
<IfModule mod_proxy.c>
ProxyRequests Off
SSLProxyEngine on
ProxyPass ^~ /api/ http://127.0.0.1/api/
ProxyPassReverse ^~ /api/ http://127.0.0.1/api/
</IfModule>
<IfModule mod_proxy.c>
ProxyRequests Off
SSLProxyEngine on
ProxyPass ^~ /fe-server/ http://39.108.163.73:3000/
ProxyPassReverse ^~ /fe-server/ http://39.108.163.73:3000/
</IfModule>
#PROXY-END
#PHP
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-cgi-54.sock|fcgi://localhost"
</FilesMatch>
#PATH
<Directory "/www/wwwroot/ymc-home.top">
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.html index.php index.htm default.php default.htm default.html
</Directory>
</VirtualHost>
mysql数据库服务器地址:127.0.0.1:3306
mysql数据库服务器账号:root
mysql数据库服务器密码:9AC0cde7cc14
ssh服务器地址:39.108.163.73:22
ssh服务器账号:root
ssh服务器密码:
ssh服务器密钥:
php服务器地址:127.0.0.1:3306
php服务器站点:/home/www/htdocs
问题收集
问题:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
解决:
https://www.cnblogs.com/xubing-613/p/6844564.html
https://www.cnblogs.com/panda2046/p/5933498.html
备注:修改配制 之后,sudo service sshd restart
问题:IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY
解决:rm -rf ~/.ssh/known_hosts
问题:
Warning: Permanently added '39.108.163.73' (ECDSA) to the list of known hosts.
问题:node本地服务启动报Error: listen EADDRINUSE
解决:ps | grep node,然后kill 端口