cd ~/.ssh
rm known_hosts
sudo -i 切换root用户
ssh ubuntu@115.159.56.212
fdisk -l
df -h
subs .zshrc
alias ssh_bin="ssh ubuntu@115.159.56.212" 软链接
source .zshrc 重新载入
ssh_bin
adducer bin_manager ->该用户密码
Full Name: bin 个性信息
Room Number: 109
Work Number:
gpasswd -a bin_manager sudo 赋予权限
sudo visudo
#User privilege specification
root ALL=(ALL:ALL) ALL
bin_manager ALL=(ALL:ALL) ALL
control + X -> Y
service ssh restart
control + d
ssh bin_manager@115.159.56.212
pwd
cd ~
ll -a
ls -a
cd .ssh
id_rsa.pub 公钥
mv id_rsa.pub id_rsa_backup.pub
mv id_rsa id_rsa_backup 私钥
ssh-keygen -t rsa -b 4096 -C "binperson@163.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
ssh-keygen -t rsa 4096 -C "binperson@163.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
vi authorized_keys
shift + : -> :wq!
cat id_rsa.pub 复制本地 到 authorized_keys -> :wq!
chmod 600 authorized_keys
sudo service ssh restart
sudo vi /etc/ssh/sshd_config
Port 39999
UseDNS no
AllowUsers bin_manager
:wq!
sudo service ssh restart
ssh -p 39999 bin_manager@115.159.56.212
sudo vi /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
:wq!
sudo service ssh restart
sudo apt-get update && sudo apt-get upgrade
sudo iptables -F
sudo vi /etc/iptables.up.rules
*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 39999 -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
#drop imcoming 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
#reject all the other inbound
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
:wq!
sudo iptables-restore < /etc/iptables.up.rules
sudo ufw status
sudo ufw enable
sudo vi /etc/network/if-up.d/iptables
#!/bin/sh
iptables-restore /etc/iptables.up.rules
:wq!
sudo chmod + x /etc/network/if-up.d/iptables
sudo apt-get install fail2ban
sudo vi /etc/fail2ban/jail.conf
bantime = 3600
destemail = binperson@163.com
action = %(action_mw)s
:wq!
sudo service fail2ban status
node.js
sudo apt-get update
sudo apt-get instal vim openssl build-essential libssl-dev wget curl git
wgit nvm
nvm install v6.9.5
nvm use v6.9.5
nvm alias default v6.9.5
node -v
npm --registry=https://registry.npm.taotao.org install -g npm
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
npm --registry=https://registry.npm.taotao.org install -g cnpm
cnpm sync koa 同步一下koa
npm I pm2 web pack gulp grunt-cli -g
npm --registry=https://registry.npm.taotao.org install -g pm2
pm2 start app.js
pm2 list
pm2 show app
pm2 logs
sudo apache2 stop
update-rc.d -f apache2 remove
sudo apt-get remove apache2
sudo apt-get update
sudo apt-get install nginx
nginx -v
cd /etc/nginx/
cd conf.d
sudo vi binperson-com-cn-8081.conf
upstream binprson {
server 127.0.0.1:8081
}
server {
listen: 80;
server_name: localhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_xforwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://binperson;
proxy_redirect off;
}
}
cd ../
sudo vi nginx.conf
sudo nginx -t
cd conf.d
sudo vi binperson-com-cn-8081.conf
upstream binprson {
server 127.0.0.1:8081
}
server {
listen 80;
server_name http://115.159.56.212;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://binperson;
proxy_redirect off;
}
}
sudo nginx -s reload
headers -> Server: nginx/1.4.6 (Ubuntu) ->隐藏头信息 sudo vi nginx.conf
server_tokens off; ->打开
sudo service nginx reload
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo vi /etc/apt/apt.conf +#注释
cd /etc/apt/
cd sources.list.d
ls
sudo vi mongodb-org-xx.list
http://mirrors.aliyun.com/mongodb/apt/ubuntu
sudo apt-get update
sudo apt-get install -y mongodb-org
cat /var/log/mongodb/mongod.log
mongo
sudo vi /etc/iptables.up.rules
# 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
sudo iptables-restore < /etc/iptables.up.rules
mongo
sudo service mongod stop mongod stop/waiting
sudo service mongod start
sudo service mongod restart
sudo vi /etc/mongod.conf
port 19999
sudo vi /etc/iptables.up.rules
# mongodb connect
-A INPUT -s 127.0.0.1 -p tcp --destination-port 19999 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -d 127.0.0.1 -p tcp --source-port 19999 -m state --state ESTABLISHED -j ACCEPT
sudo iptables-restore < /etc/iptables.up.rules
mongo --port 19999
mkdir dbbackup
cd city
mongodump -h 127.0.0.1:27017 -d city -0 city-backup
tar zcvf city.tar.gz city-backup/
cd ~
scp -P 39999 ./city.tar.gz bin_manager@115.159.56.212:/home/bin_manager/dbbackup
cd dbbackup
tar xvf city-backup.tar.gz
cd ~
mongorestore --host 127.0.0.1:19999 -d city ./dbbackup/city-backup/city/
mongo --port 19999
单表
mongoexport -d moon -c users -q '{"name": {$ne:null}}' -o ./mooc-users.json
mongoimport --host 127.0.0.1:19999 -d mooc users ./mooc-users.json
mongo --host 127.0.0.1:19999 mooc --eval "db.dropDatabase()"
mongo --port 19999
use admin
db.createUser({user: 'binperson',pwd: '549346275',roles: [{role: 'userAdminAnyDatabase', db:'admin'}]});
db.auth('binperson', '549346275')
use mooc
db.createUser({user: 'bin', pwd: '549346275',roles: [{role: 'readWrite', db:'admin'}]})
db.createUser({user: 'bi', pwd: '54934627',roles: [{role: 'read', db:'admin'}]})
sudo vi /etc/mongod.conf
security:
authorization: 'enabled'
:wq!
sudo service mongod restart
use admin
db.auth('bin', '549346275')
show dbs
mongo 127.0.0.1:19999/mooc -u bin -p 549346275
show tables
db.users.find({})
mongodump -h 127.0.0.1:19999 -d mooc -u bin -p 549346275 -o mooc-old
tar mood-old.tar.gz mooc-old/
mongoexport -h 127.0.0.1:19999 -d mooc -u bin -p 549346275 -c users -q '{"name": {$ne: null}}' -o ./mooc-users-old.json
scp -p 39999 bin_manager@115.159.56.212:/home/bin_manager/db/mooc-old.tar.gz ./
scp -p 39999 bin_manager@115.159.56.212:/home/bin_manager/db/mooc-users-old.json ./
scp -p 39999 ./mooc-users-old.json bin_manager@115.159.56.212:/home/bin_manager/newdb/
scp -p 39999 ./mooc-old.tar.gz bin_manager@115.159.56.212:/home/bin_manager/newdb/
mongo --part 19999
use admin
db.auth('bin', '549346275')
use mooc-more
mkdir task
#!/bin/sh
backUpFolder = /home/bin_manager/backup/mooc
data_now=`data +%Y_%m_%d_%H%M`
backFileName=movie_$date_now
cd $backUpFolder
mkdir -p $backFile
mongodump -h 127.0.0.1:19999 -d mooc -u bin -p 549346275 -o $backFileName
tar zcvf $backFileName.tar.gz $backFileName
rm -rf $backFileName
:wq!
mkdir backup
cd backup/
mkdir mooc
cd mooc
sudo sh ./tasks.mooc.backup.sh
cd
crontab -e
13 00 * * * sh /home/bin_manager/tasks/mooc.backup.sh
vi upload.js
var qiniu = require("qiniu");
var parts = env.split('@');
var file = parts[1]+'.tar.gz'
var filePath = parts[0] + '/' + file
//需要填写你的 Access Key 和 Secret Key
qiniu.conf.ACCESS_KEY = 'Access_Key';
qiniu.conf.SECRET_KEY = 'Secret_Key';
//要上传的空间
bucket = 'moocdeploydb';
//上传到七牛后保存的文件名
key = file
//构建上传策略函数
function uptoken(bucket, key) {
var putPolicy = new qiniu.rs.PutPolicy(bucket+":"+key);
return putPolicy.token();
}
//生成上传 Token
token = uptoken(bucket, key);
//要上传文件的本地路径
filePath = './ruby-logo.png'
//构造上传函数
function uploadFile(uptoken, key, localFile) {
var extra = new qiniu.io.PutExtra();
qiniu.io.putFile(uptoken, key, localFile, extra, function(err, ret) {
if(!err) {
// 上传成功, 处理返回值
console.log(ret.hash, ret.key, ret.persistentId);
} else {
// 上传失败, 处理返回代码
console.log(err);
}
});
}
//调用uploadFile上传
uploadFile(token, key, filePath);