sudo yum -y install net-tools wget vim epel-release psmisc telnet-server xinetd bind-utils sysstat ntpdate
sudo yum group install "Development Tools" "Development Libraries"
sudo yum -y install gcc make gcc-c++ openssl openssl-devel wget vim
sudo yum -y install ntpdate sysstat epel-release net-tools psmisc
sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel
#時間同步設置 */30 * * * * /usr/sbin/ntpdate us.pool.ntp.org |logger -t NTP #開啓firewalld firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --permanent --add-service=http
#設置容許某個ip或網段訪問某個端口或服務
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="192.168.0.8" port port="80" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="192.168.0.0/24" port port="80" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="192.168.0.0/24" service name="http" accept'
firewall-cmd --reload
1). NODEJS安裝(兩種方式:源碼安裝和nvm版本管理工具安裝,推薦1.2安裝方式)javascript
1.1)Node.JS(6.10.3):php
yum -y install gcc gcc-c++ openssl-devel ##確認服務器有node.js編譯及依賴相關軟件 yum -y install nodejs npm ##(EPEL-release安裝) wget https://nodejs.org/dist/v6.10.3/node-v6.10.3.tar.gz ##(如下步驟爲源碼安裝) sudo tar zxvf node-v6.10.3.tar.gz && cd node-v6.10.3 && sudo ./configure --prefix=/usr/local/node && sudo make && sudo make install vim /etc/profile [root@BobServerStation node-v0.10.24]# vim /etc/profile #set nodejs env export NODE_HOME=/usr/local/node export PATH=$NODE_HOME/bin:$PATH export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH [root@BobServerStation node-v0.10.24]# source /etc/profile ##重啓生效
1.2)nvm: nodejs版本管理css
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash ##nvm安裝
## 安裝完成後,會發現使用nvm install stable 安裝node速度很慢。使用國內鏡像快速安裝node: 把環境變量 NVM_NODEJS_ORG_MIRROR, 加入到 .bash_profile 文件中:
## nvm export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node
## nvm 使用參考https://github.com/creationix/nvm
# 設置 npm 淘寶鏡像
npm install -g pm2 --registry=https://registry.npm.taobao.org
1.3)Linux添加字體(點擊這裏)html
2).MongoDB(集羣方式參考MongoDB副本集原理、搭建、應用(5)):java
systemLog: quiet: false path: /data/mongodb/logs/mongom.log logAppend: false destination: file logRotate: rename processManagement: fork: true pidFilePath: /data/mongodb/dbm/mongod.pid net: bindIp: 127.0.0.1 port: 27017 maxIncomingConnections: 65536 wireObjectCheck: true ipv6: false storage: dbPath: /data/mongodb/dbm indexBuildRetry: true journal: enabled: true directoryPerDB: true engine: wiredTiger syncPeriodSecs: 60 wiredTiger: engineConfig: # cacheSizeGB: 8 journalCompressor: snappy directoryForIndexes: false collectionConfig: blockCompressor: snappy indexConfig: prefixCompression: true operationProfiling: slowOpThresholdMs: 100 mode: all security: #authorization: enabled #clusterAuthMode: keyFile #keyFile: /usr/local/mongodb/conf/keyfile javascriptEnabled: true setParameter: enableLocalhostAuthBypass: true authenticationMechanisms: SCRAM-SHA-1 replication: oplogSizeMB: 4096 #replSetName: ebim
sudo wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.8.tgz
sudo wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.4.tgz
sudo wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.9.tgz sudo tar zxvf mongodb-linux-x86_64-rhel70-3.4.4.tgz && sudo mv mongodb-linux-x86_64-rhel70-3.4.4 /usr/local/mongodb && sudo cd /usr/local/mongodb && sudo mkdir conf 建立啓動配置文件: mkdir -p /home/mongodb/data/dba mkdir -p /home/mongodb/logs vim conf/mongoa.conf #如下內容爲mongoa.conf配置文件內容 port=27017 dbpath=/home/mongodb/data/dba logpath=/home/mongodb/logs/mongoa.log journal=true logappend=true storageEngine=wiredTiger #auth=true fork=true nohttpinterface=true #relica set 配置 oplogSize=4096 #replSet=ebim #keyFile=/usr/local/mongodb/conf/replkeyfile 啓動mongodb服務: /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongoa.conf
2.1).配置MongoDB賬號:node
1 >use admin 2 switched to db admin 3 > db.createUser( 4 ... { 5 ... user: "root", 6 ... pwd: "password", 7 ... roles: [ 8 ... { role: "root", db: "admin" } #超級root賬號 9 ... ] 10 ... } 11 ... ) 12 >use ebimdb 13 switched to db ebimdb 14 > db.createUser( 15 ... { 16 ... user: "ebim", 17 ... pwd: "password", 18 ... roles: [ 19 ... { role: "readWrite", db: "ebimdb" } 20 ... ] 21 ... } 22 ... ) 23 24 添加keyfile認證文件,並配置權限 25 openssl rand -base64 741 > /usr/local/mongodb/conf/replkeyfile 26 chmod 600 /usr/local/mongodb/conf/replkeyfile
2.2) . 修改MongoDB配置文件(mongoa.conf): 去除auth,keyFile參數註釋.(副本集則須要將keyfile 認證文件copy到全部全部節點,並去除配置文件replSet參數註釋)linux
3 ) . EBIM服務端部署:nginx
修改全局安裝npm package權限(nvm安裝無需執行此步驟) sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} 安裝pm2 npm i pm2 -g 安裝ImageMagick,unoconv sudo yum install ImageMagick.x86_64 ImageMagick-devel.x86_64 unoconv libreoffice cjkuni-ukai-fonts.noarch cjkuni-uming-fonts.noarch texlive-cjk.noarch texlive-cjk-doc.noarch texlive-xecjk.noarch texlive-xecjk-doc.noarch
3.1).修改服務端配置,並執行初始化:c++
#修改配置文件參數 vim config/env.js vim config/services/production.js #服務端初始化 node bin/shell.js ./init.js #啓動服務 pm2 start pm2.ebim.config.js --env=production && pm2 start pm2.worker.config.js --env=production
4).Nginxgit
yum -y install nginx Nginx配置文件: user nginx nginx; worker_processes auto; error_log /var/log/nginx/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /run/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include /etc/nginx/mime.types; default_type application/octet-stream; charset utf-8; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 500m; #access_log logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; 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 256k; open_file_cache max=65535 inactive=20s; open_file_cache_min_uses 5; open_file_cache_valid 60s; proxy_redirect off; proxy_connect_timeout 60; proxy_read_timeout 120; proxy_send_timeout 20; proxy_buffer_size 32k; proxy_buffers 4 128k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; server_tokens off; upstream web_server { server 127.0.0.1:3010 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3011 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3012 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3013 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3014 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3015 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3016 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3017 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:3020 weight=1 max_fails=2 fail_timeout=30s; } server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/access.log main; location / { #root html; #index index.html index.htm; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://web_server; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { #root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; # } location /status { stub_status on; access_log off; } #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ # { # expires 30d; # } #location ~ .*\.(js|css)?$ # { # expires 12h; # } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} include vhost/*.conf; }
5).添加MongoDB EBIM服務爲開機啓動
#mongodb開機啓動 vim /usr/lib/systemd/system/mongod.service [Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] LimitCORE=infinity LimitNOFILE=65535 #LimitNPROC= #User=mongo #Group=mongo Type=forking Environment=MONGOFILE=/usr/local/mongodb344/conf/mongom.conf #EnvironmentFile=/usr/local/mongodb/conf/mongo.env PIDFile=/home/mongodb/data/dba/mongod.pid ExecStart=/usr/local/mongodb344/bin/mongod -f $MONGOFILE ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID Restart=on-failure RestartSec=42s PrivateTmp=true [Install] WantedBy=multi-user.target #EBIM開機啓動 chmod +x /etc/rc.d/rc.local ## ln -s /usr/local/node/bin/node /usr/bin/node vim /etc/rc.d/rc.local su - ebim -c "/usr/local/node/bin/pm2 start /home/ebim/xxx/pm2.ebim.config.js --env=production" su - ebim -c "/usr/local/node/bin/pm2 start /home/ebim/xxx/pm2.worker.config.js --env=production"
6).數據備份:
30 4 * * 3 /bin/sh /home/scripts/mongobak.sh #!/bin/bash FLODER="/home/mongobak" DATE=$(date '+%Y-%m-%d') if [ ! -d "$FLODER" ];then mkdir -p "$FLODER" fi cd /usr/local/mongodb ## ./bin/mongodump -o /home/mongobak/mongodb-$DATE
./bin/mongodump --port=27018 -u root -p xxx --oplog -o /home/mongobak/mongodb-$DATE
find /home/mongobak -mtime +10 |xargs rm -rf