The commands needed to deploy the server, record them, and have a look if you need them:
1. A new server needs to check the server's memory, disk, number of cores, and network (I use these for the time being)
top: View the process, on this basis, press 1 to view: linux cores + memory
View disk: df -lh View directory size: du -lh
As for the network: ping tech.meituan.com, it would be stupid if you can't access the external network (excluding the internal network environment)
ifconfig: view the current ip address Also, some mounted disks are in the /dev/vdb directory and need to be formatted and mounted in the /data directory. Please refer to the previous blog post: http://study121007.iteye.com/blog/2297693 , It may also be used here: ln -s source directory target directory. Create a soft connection for /dev/vdb, to put it bluntly, create a shortcut method, when a modification is made in the source directory, the target directory will also be modified accordingly.
2. Install JDK (1.8)
Store the jdk compressed package in the /usr/local/ directory and decompress it. Sometimes you need to modify the file permissions in the jdk directory:
chmod -R 777 start*: batch modify file permissions starting with start (Because the permissions are not modified, the system will still use the default jdk version 1.7)
Then configure the environment variables ( /etc/profile )
export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH After exiting and saving, execute: source /etc/profile Compile the file to make the modification take effect
3. Unzip the file
tar compression: tar -zcvf file.tar.zip file Unzip the tar: tar -zxvf file.tar.zip Unzip the zip: unzip xxx.zip 解压war:jar -xvf xxx.war
4. Install Nginx (Nginx will be introduced in detail later)
It is installed online when you can access the external network, yum install nginx
On CentOS6, some may not be able to directly yum, you need to download the following resources:
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/ nginx-release-centos-6-0.el6.ngx.noarch.rpm
After installation, enter /etc/nginx/conf.d/default.conf to modify the configuration information (shown here briefly):
server { listen 80; server_name localhost; location /[This is the application name, if not written, it is the root directory of the current domain name] { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } ....... } (If the application name is search, when accessing www.xxx.com/search, the nginx port 80 is actually forwarded to 127.0.0.1:8080/search application, that is to say, the final jump path is proxy_pass + application name)
Manually installed environment variables can be configured by yourself: (The directory where yum is installed online is: /etc/nginx)
export NGINX_HOME=/usr/local/nginx (this is the directory when installing manually) export PATH=$NGINX_HOME/sbin:$PATH ulimit -HSn 65535 By the way, configure the maximum number of files that can be opened (By the way, there is a problem that I have encountered before. The front-end company that makes the website does not do caching, and the website traffic is very large, and a lot of calls are made to me. Our interface causes the "too many open files" error to be thrown all the time, and the log has been recorded all the time, resulting in the log folder size reaching 49G in a few days. Take up too much space and the whole app service dies. Solutions considered before: use ehcache for caching + nginx Cache, but the effect is not very good or there is a crash, and then it is useless. After that the solution is: let them add cache)
service nginx configtest: Check whether nginx is successfully configured. The new server generally does not support the service command, but systemctl
service nginx restart: restart nginx (this is the server that supports the service command), as for the unsupported ones, use the following:
Start: nginx
Restart: nginx -s reload
For other detailed commands, use nginx -h to view the help. There are more introductions, as follows
Sometimes the compilation environment is missing when installing nginx manually: yum install gcc gcc-c++ ncurses-devel perl
5. Install Jetty, some also install Tomcat, the methods are similar
Download the Jetty installation package, upload it to the server's own designated directory (such as: /opt), unzip it, and enter the bin directory.
Execute: ./jetty.sh start to start./jetty.sh stop to stop
6. Ports need to be opened when different applications or the same application is deployed on multiple machines
/etc/sysconfig/iptables (open ports: port 22 below) -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT (When there are multiple machines, if you access the application in machine B from machine A, because of the nginx proxy, don't forget to open port 80 of machine B)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -dport 6000:6500 -j ACCEPT (open a port) service iptables restart restart the firewall
Install iptables manually: yum install iptables-services
Modify the configuration: vi /etc/sysconfig/iptables
Restart: systemctl restart iptables.service
Set the boot to start automatically: systemctl enable iptables.service
7. Of course, the application must have a database, and mongodb is used here.
I will not go into details, refer to http://blog.csdn.net/yuwenruli/article/details/8529192
And database backup and restore, refer to http://y-zjx.iteye.com/blog/1310380
It should be noted that the logs directory must be created. Failure to create this directory will result in an unsuccessful database startup.
A new mongo database, set an administrator for it:
/bin/mongo localhost:8888 use admin db.createUser({user:'xxxxx',pwd:'yyyyy-=',roles:['root']}) Login to Mongo with username and password /bin/mongo -u xxxxx -p yyyyy --authenticationDatabase admin localhost:8888
8. View log files
tail -f -n200 /log/2016-05-12log.txt View the first 200 lines of the current log
9. Process related
View port: netstat -nltp View PID: ps -ef|grep jetty Kill the process: kill 218882
10. Time Issues < http://codingstandards.iteye.com/blog/1157513 >
date -R View time
11. Linux java performance monitoring
> jconsole (open the control panel, select the corresponding process to connect to it, similar to the task manager in windows) Some need to install this command by themselves. Also check the system version: cat /etc/issue
12、SCP
(1) Copy files from remote to local directory. If copying a folder, the parameter needs to be set to -r scp [parameters] [email protected]:/opt/app/jettys/robot/webapps/ss.tar.gz ./ (2) Upload the local file to the specified directory of the remote machine. Similarly, if you copy a folder, the parameter needs to be set to -r scp [parameters] ./ss.tar.gz [email protected]:/opt/app/jettys/robot/webapps
13. Find the file path according to the PID in linux
lsof -p PID lists the files opened by the specified process number. (1) Check the process information first: top (2) You can use sudo lsof -p PID directly in the docker parent container to view the file information corresponding to the process. You can also log in to the subcontainer, cd /proc/PID, enter the PID process folder, and ls -ail to view the corresponding information. (In addition, you can also view the process information in the container through docker top Name/ID in docker)
14. Find files
which looks at the location of the executable. whereis looks at the location of the file. locate works with the database to view the file location. find actually searches the hard disk for file names. Format: which executable file name, such as which java
(Attachment: Alibaba Cloud Open Source Mirror: http://mirrors.aliyun.com/ )
(this document will be updated all the time)
For more linux, you can read the series of articles of this great god: http://www.cnblogs.com/peida/tag/%E6%AF%8F%E6%97%A5%E4%B8%80linux%E5%91%BD %E4%BB%A4/