Local environment Mac server Aliyun Ubuntu 14 X64
Configure the cloud server environment
SSH link
SSH root @ IP addressCopy the code
Disk management
fdisk -l
Copy the code
View hard disk usage
df -h
Copy the code
Control + d \\ exit SSHCopy the code
= = = = = = = = = = = = = = = = = = = = = = = = = =
Create a user with lower rights
adduser manager
Copy the code
Upgrade permissions
gpasswd -a manager sudo
sudo visudo
Copy the code
= = = = = = = = = = = = = = = = = = = = = = =
Configuring SSH Public Key (Configured)
Starting the SSH Proxy
eval "$(ssh-agent -s)"
Copy the code
Adding an SSH Agent
ssh-add ~/.ssh/id_rsa
Copy the code
(Server authorization file. SSH directory)
vi authorized_keys
~/.ssh$ chmod 600 authorized_keys
~/.ssh$ sudo service ssh restart
Copy the code
= = = = = = = = = = = = = = = = = = = = = = =
Firewall Configuration
sudo iptables -F
sudo vi /etc/iptables.up.rules
Copy the code
Firewall profile
*filter
#allow all connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#allow out traffic
-A OUTPUT -j ACCEPT
#allow http https
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT
#allow ssh port login
-A INPUT -p tcp -m state --state NEW --dport 29999 -j ACCEPT
#ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
#log denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied:" --log-level 7
#reject all other inbound
#-A INPUT -j REJECT
#-A FORWORD -j REJECT
#drop incoming sensitive connections
-A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set
-A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 150 -j DROP
COMMIT
Copy the code
sudo iptables-restore < /etc/iptables.up.rules
Copy the code
Check whether the firewall is enabled
sudo ufw status
->Status: inactive
sudo ufw enable
Copy the code
Firewall startup shell script configuration
sudo vi /etc/network/if-up.d/iptables
Copy the code
#! /bin/sh
iptables-restore /etc/iptables.up.rules
Copy the code
Grant script execution permission
sudo chmod +x /etc/network/if-up.d/iptables
Copy the code
= = = = = = = = = = = = = = = = = = = = = = =
Upgrading the Local Tool Package
sudo apt-get update
Copy the code
Install the necessary dependencies
sudo apt-get install git vim openssl build-essential libssh-dev wget curl git
Copy the code
Install the NVM
The curl - o - https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash wget -- qO https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bashCopy the code
List nodeJS versions
nvm ls
Copy the code
Install nodejs8.1.2
NVM install v8.1.2Copy the code
use
NVM use v8.1.2Copy the code
Set to the default
nvm aliasThe default v8.1.2Copy the code
Configuration of NPM source
npm --registry=https://registry.npm.taobao.org install -g npm
Copy the code
Example Add the number of system files to be monitored
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Copy the code
Install CNPM
npm --registry=https://registry.npm.taobao.org install -g cnpm
Copy the code
Configuring firewall ports (whitelist port 3006)
sudo vi /etc/iptables.up.rules
Copy the code
Copy the website code in the configuration file and change port 3000 to 3006
reload
sudo iptables-restore </etc/iptables.up.rules
Copy the code
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Copy the About code example from the Node website
vi server.js
Copy the code
Start the service
node server
Copy the code
Disabling the Firewall
sudo ufw stop
Copy the code
Close the nginx
sudo service nginx stop
Copy the code
Start the service
node server
Copy the code
Start another terminal
Curl http://127.0.0.1:3006 - "Hello WorldCopy the code
Install YARN using Homebrew
brew install yarn
Copy the code
Server Installation
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Copy the code
sudo apt-get update && sudo apt-get install yarn
Copy the code
Set the YARN installation source to Taobao
yarn config set registry https://registry.npm.taobao.org
Copy the code
Vue -cli pM2 webpack gulp grunt-cli
npm install vue-cli pm2 webpack gulp grunt-cli -g
Copy the code
Pm2 is used to automatically maintain the server process
pm2 start server.js
Copy the code
access
The curl http://127.0.0.1:3006Copy the code
Check the service
pm2 list
pm2 show server
Copy the code
The end of the
pm2 stop server
Copy the code
Viewing Log Content
pm2 logs
Copy the code
Restart the service
pm2 restart server
Copy the code
Install the vue – cli
npm i vue-cli -g
Copy the code
= = = = = = = = = = = = = = =
Node -v ->8.1.2 NPM -v ->5.0.3 pm2 -v 2.5.0 YARN --varsion 0.24.6 vUE -v 2.8.2 BREw-v 1.2.2Copy the code
Nginx configuration
= = = = = = = = = = = = = = = = = = = = = = = = = = = =
Apache has been installed on the Ali Cloud server
Stop apache
sudo service apache2 stop
Copy the code
delete
update-rc.d -f apache2 remove
Copy the code
delete
sudo apt-get remove apache2
Copy the code
Update associated table
sudo apt-get update
Copy the code
Install nginx
sudo apt-get install nginx
nginx -v
Copy the code
View the configuration of the deployed project
cd /etc/nginx/conf.d
ls
Copy the code
Restart after the configuration
sudo service nginx restart
Copy the code
If the error
sudo nginx -t
Copy the code
Wx-123mai-vip-3006. conf upstream wx{server 127.0.0.1:3006; } server { listen 80; server_name wx.123mai.vip; location / { proxy_set_header X-Real-Ip$remote_addr;
proxy_set_header X-Farward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true; proxy_pass http://wx; proxy_redirect off; }}Copy the code
Installing the MongoDB Database
= = = = = = = = = = = = = = = = = = = =
Ubuntu install MongoDB 14.04 x64
1 Public key import
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Copy the code
2 create a list (Aliyunyuan)
echo "Deb [arch = amd64] https://mirrors.aliyun.com/mongodb/apt/ubuntu trusty/mongo - 3.6 - / - org multiverse." "| sudo tee/etc/apt/sources list. D/mongo - org - 3.6. The listCopy the code
echo "Deb [arch = amd64] https://repo.mongodb.org/apt/ubuntu trusty/mongo - 3.6 - / - org multiverse." "| sudo tee/etc/apt/sources list. D/mongo - org - 3.6. The listCopy the code
3 Update the local package
sudo apt-get update
Copy the code
4. Install the household bucket
sudo apt-get install -y mongodb-org
Copy the code
Open the service
sudo service mongod start/stop/restart
Copy the code
Check whether the startup is successful
cat /var/log/mongodb/mongod.log Check whether logs are generatedCopy the code
If installation fails
cd /etc/apt/sources.list.d
ls
vi mongo*****
Copy the code
Modifying the Source Address
View mongodb ports and security configurations
sudo vi /etc/mongod.conf
->
net:
port: 27017
bindIp: 127.0.0.1
Copy the code
Enable firewall configurations and add whitelists
sudo vi /etc/iptables.up.rules
Copy the code
-A OUTPUT -j ACCEPT
#allow http https
-A INPUT -p tcp --dport 443 -j ACCEPT
-A IMPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 8081 -j ACCEPT
#allow ssh port login
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
#ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
#mongodb connect
-A INPUT -s 127.0.0.1 -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -d 127.0.0.1 -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
Copy the code
Use the git
= = = = = = = = = = = = = = = = = = = = = = =
New Project
Git Global Settings
git config --global user.name "Prove"
git config --global user.email "[email protected]"
Copy the code
Creating a Git repository
mkdir vxfirst
cd vxfirst
touch README.md
git commit -m "first commit"
git remote add orgin [email protected]:luo-xin/vxfirst.git
git push -u orgin master
Copy the code
Existing projects
cd existing_git_repo
git remote add origin [email protected]:luo-xin/wx.git
git push -u origin master
Copy the code
Git public and private key configuration
ssh-keygen -t rsa -b 4096 -C '[email protected]'Press Enter repeatedly to set the public key without passwordCopy the code
Enabling the SSH Proxy
eval "$(ssh-agent -s)"
Copy the code
Code cloud configuration public key
cd~/. SSH cat id_rsa.pub Prints the contents to the console, copies the contents to the public key configuration page of the code cloud, and saves the contentsCopy the code
Test whether you have pull permission
git clone [email protected]:luo-xin/vxfirst.git
Copy the code
Configuration pm2
= = = = = = = = = = = = = = = = = = =
Local pull project code
Deploy the project to the WWW directory to set permissions
cd ~/www
mkdir wx
sudo chmod 777 vxfirst
Copy the code
Git local Commit
Git diff Add all current changes to the next commit: git add Additional information Commit git commit -m'Modify information'Git add.(file name) // Add the file to the local repository. 3"first commit"Git remote add origin Git push -u origin master git push -u origin master git push -u origin masterCopy the code
Initialization for the first time
pm2 deploy ecosystem.json production setup
Copy the code
release
pm2 deploy ecosystem.json production
Copy the code
ecosystem.json
{
"apps": [{"name": "IceAndFire"."script": "start.js"."env": {
"COMMON_VARIABLE": "true"
},
"env_production": {
"NODE_ENV": "production"}}]."deploy": {
"production": {
"user": "Your server login name"."host": ["Your server IP"]."port": "Your server login port defaults to 22"."ref": "origin/master"."repo": "Your Git repository address"."path": "/www/icefire/production"."ssh_options": "StrictHostKeyChecking=no"."post-deploy": "yarn install && npm run build && pm2 startOrRestart ecosystem.json --env production"."env": {
"NODE_ENV": "production"}},"plus": {
"user": "Your server login name"."host": ["Your server IP"]."port": "Your server login port defaults to 22"."ref": "origin/master"."repo": "Your Git repository address"."ssh_options": "StrictHostKeyChecking=no"."post-deploy": "yarn install && pm2 startOrRestart ecosystem.json --env production"."env": {
"NODE_ENV": "production"}}}}Copy the code