Reprint: https://blog.csdn.net/qq_23329167/article/details/83856430
Linux common commands
1, Basic command
1.1 shutdown and restart
Shut down shutdown -h now Turn it off immediately shutdown -h 5 5 Shutdown in minutes poweroff Turn it off immediately restart shutdown -r now Restart now shutdown -r 5 5 Restart in minutes reboot Restart now
1.2 help command
--help command shutdown --help: ifconfig --help: View network card information man Command (instruction manual) man shutdown be careful: man shutdown After opening the command manual, use the key q sign out
2, Directory operation command
2.1 directory switching cd
Command: cd catalogue cd / Switch to the root directory cd /usr Switch to under the root directory usr catalogue cd ../ Switch to the previous directory or cd .. cd ~ Switch to home catalogue cd - Switch to the last accessed directory
2.2 directory view ls [-al]
Command: ls [-al] ls View all directories and files in the current directory ls -a View all directories and files in the current directory (including hidden files) ls -l or ll List view all directories and files under the current directory (list view, display more information) ls /dir View all directories and files in the specified directory, such as: ls /usr
2.3 directory operation [add, delete, modify, query]
2.3.1 create directory [add] mkdir
Command: mkdir catalogue mkdir aaa Create a file named aaa Directory of mkdir /usr/aaa Create a file named aaa Directory of
2.3.2 delete directory or file [delete] rm
Command: rm [-rf] catalogue Delete file: rm file Delete files in the current directory rm -f file Delete files in the current directory (don't ask) Delete directory: rm -r aaa Recursively delete files under the current directory aaa catalogue rm -rf aaa Recursively delete files under the current directory aaa Directory (no inquiry) Delete all: rm -rf * Delete all directories and files in the current directory rm -rf /* [Suicide order! Use with caution! Use with caution! Use with caution!] Delete all files in the root directory be careful: rm You can not only delete directories, but also delete other files or compressed packages. In order to facilitate everyone's memory, you can use them directly regardless of deleting any directories or files rm -rf catalogue/file/Compressed package
2.3.3 directory modification [modification] mv and cp
1, Rename directory Command: mv Current directory new directory For example: mv aaa bbb Will directory aaa Change to bbb be careful: mv You can not only rename directories, but also rename compressed files 2, Cut directory Command: mv Directory name the new location of the directory Example: will/usr/tmp Directory aaa Cut directory to /usr Under the directory mv /usr/tmp/aaa /usr be careful: mv Syntax can cut not only directories, but also files and compressed packages 3, Copy directory Command: cp -r Directory name the destination of the directory copy -r Represents recursion Example: will/usr/tmp Directory aaa Copy to directory /usr Under the directory cp /usr/tmp/aaa /usr be careful: cp The command can not only copy directories, but also copy files, compressed packages, etc. when copying files and compressed packages, it is not necessary Write with-r recursion
2.3.4 search directory [search] find
Command: find Directory parameter file name Example: find /usr/tmp -name 'a*' lookup/usr/tmp All in the directory a Directory or file at the beginning
3, File operation command
3.1 document operation [add, delete, modify, check]
3.1.1 create a new file [add] touch
Command: touch file name Example: create a directory named aa.txt Documents touch aa.txt
3.1.2 delete file [delete] rm
Command: rm -rf file name
3.1.3 modify the document [change] vi or vim
[vi Three modes of editor] Basically vi It can be divided into three states: command mode( command mode),Insert mode( Insert mode)And bottom line mode( last line mode),The functions of each mode are distinguished as follows: 1) Command line mode command mode) Control the movement of the screen cursor, the deletion of characters, words or lines, search, move, copy a certain section and enter Insert mode Down, or to last line mode. Common commands in command line mode: [1]Control cursor movement:↑,↓,j [2]Delete current row: dd [3]Find:/character [4]Enter edit mode: i o a [5]Enter bottom line mode:: 2) Edit mode( Insert mode) Only in Insert mode To enter text, press「ESC」Key to return to command line mode. Common commands in edit mode: [1]ESC Exit editing mode to command line mode; 3) Bottom row mode( last line mode) Save or exit the file vi,You can also set the editing environment, such as looking for strings, listing line numbers, etc. Common commands in bottom line mode: [1]Exit editing: :q [2]Forced exit: :q! [3]Save and exit: :wq Open file Command: vi file name Example: open the in the current directory aa.txt file vi aa.txt perhaps vim aa.txt Note: use vi After the editor opens the file, it cannot be edited because it is in command mode. Click the keyboard i/a/o Enter edit mode. Edit file use vi After the editor opens the file, click the key: i ,a perhaps o You can enter the editing mode. i:Start insertion before the character of the cursor a:Insert after the character of the cursor o:Insert a new line below the line where the cursor is located Save or cancel editing Save file: Step 1: ESC Enter command line mode Step 2:: Enter bottom line mode Step 3: wq Save and exit editing Cancel editing: Step 1: ESC Enter command line mode Step 2:: Enter bottom line mode Step 3: q! Undo this modification and exit editing
3.1.4 document viewing [ check ]
File view command: cat/more/less/tailcat: Look at the last screen example: Using cat see/etc/sudo.conf File, only the last screen can be displayed cat sudo.confmore: Example of percentage display: Using more see/etc/sudo.conf File, can display percentage, enter can go to the next line, space can go to the next page, q You can exit the view more sudo.confless: Page flipping example: Using less see/etc/sudo.conf File, you can use the PgUp and PgDn Upward And page down, q End view less sudo.conftail: Specify the number of rows or dynamic view example: use tail -10 see/etc/sudo.conf The last 10 lines of the file, Ctrl+C end tail -10 sudo.conf
3.2 permission modification
rwx: r Represents readable, w Represents writable, x Represents that the file is an executable if rwx Any position becomes-Represents an unreadable or writable or executable file. Example: give aaa.txt Change file permissions to executable file permissions, aaa.txt File permissions are-rw-------first place:-It means documents, d The first paragraph (3 digits) of the folder represents the permissions of the owner. The second paragraph (3 digits) represents the group of the owner. The third paragraph (last 3 digits) represents the permissions of other users 421 421 421 rw- --- ---Command: chmod +x aaa.txt Or use the 8421 method to order: chmod 100 aaa.txt
4, Compressed file operation
4.1 packaging and compression
Windows The extension of the compressed file .zip/.rarlinux Packaged files in: aa.tar linux Compressed files in: bb.gz linux Files packaged and compressed in:.tar.gzLinux Packaged files in are generally.tar At the end, the compressed command is generally.gz At the end. In general, packaging and compression are carried out together, and the suffix of the packaged and compressed file is generally.tar.gz. Command: tar -zcvf Packed compressed file name the file to be packed, where: z: call gzip Compress command c: Packed File v: Display running process f: Specify file name example: package and compress/usr/tmp The compressed package of all files under the specified name is xxx.tartar -zcvf ab.tar aa.txt bb.txt Or: tar -zcvf ab.tar *
4.2 decompression
Command: tar [-zxvf] Compressed file Of which: x: Representative decompression example:/usr/tmp Lower ab.tar Unzip to the current directory example: unzip/usr/tmp Lower ab.tar Extract to the root directory/usr lower tar -xvf ab.tar -C /usr------C Represents the location of the specified decompression
5, Find command
5.1 grep
grep Command is a powerful text search tool. Use examples: ps -ef | grep sshd Find specified ssh Service process ps -ef | grep sshd | grep -v grep Find the specified service process and exclude gerp body ps -ef | grep sshd -c Find the number of specified processes
5.2 find
find Command searches the directory structure for files and performs the specified actions on the search results. find By default, the current directory and its subdirectories are searched, and no results are filtered (that is, all files are returned), and they are all displayed on the screen. Usage example: find . -name "*.log" -ls Find in the current directory to.log The end of the file and display details. find /root/ -perm 600 lookup/root/File with permission of 600 under directory find . -type f -name "*.log" Find the current directory to.log Ordinary file at the end find . -type d | sort Find and sort all current directories find . -size +100M Find current directory greater than 100 M Documents
5.3 locate
locate So that users can quickly search a path. By default, it is automatically updated once a day, so it is used locate The command cannot find the latest changed file. To avoid this situation, you can use locate Before, use updatedb Command to manually update the database. If there is no query data in the database, it will be reported locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory This error! updatedb Yes! yum -y install mlocate If it's a compact version CentOS The system needs to be installed locate command Usage example: updatedb locate /etc/sh search etc All in the directory sh File at the beginning locate pwd Find and pwd All relevant documents
5.4 whereis
whereis Command is to locate the location of executable files, source code files and help files in the file system. The properties of these files should belong to the original code, binary files, or help files. Usage example: whereis ls Will and ls Find out all the relevant documents
5.5 which
which The function of the command is to PATH Variable to search the location of a system command and return the first search result. Usage example: which pwd lookup pwd Command path which java lookup path in java Path of
6, su, sudo
6.1 su
su Used for switching between users. However, the user remains logged in before switching. If it is root Switching to ordinary or virtual users does not require a password. On the contrary, password authentication is required for ordinary users to switch to any other user. su test:Switch to test User, but the path is still/root catalogue su - test : Switch to test User, the path becomes/home/test su : Switch to root User, but the path is still the original path su - : Switch to root User, and the path is/rootsu Insufficient: if a user needs to use root Permission, you must root Tell this user the password. Users before exiting and returning: exit
6.2 sudo
sudo Is for all who want to use root Designed by ordinary users with permissions. It can give ordinary users temporary use root Right of access. Just enter the password of your account. get into sudo Profile command: vi /etc/sudoer perhaps visudo Case: allow hadoop User to root To execute various application commands as an identity, you need to enter hadoop User's password. hadoop ALL=(ALL) ALL Case: Only allowed hadoop User to root Identity execution ls ,cat Command, and do not enter a password when executing. In the configuration file: hadoop ALL=NOPASSWD: /bin/ls, /bin/cat #
7, System services
service iptables status --see iptables Status of the service service iptables start --open iptables service service iptables stop --stop it iptables service service iptables restart --restart iptables service chkconfig iptables off --close iptables Service startup chkconfig iptables on --open iptables Service startup
8, Network management
8.1 host name configuration
[root@node1 ~]# vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=node1
8.2 IP address configuration
[root@node1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
8.3 domain name mapping
/etc/hosts The file is used to do when accessing through the host name ip For address resolution. Therefore, if you want to access a host name, you need to match the host name with its corresponding host name ip Address. [root@node1 ~]# vi /etc/hosts #### Add 192.168.52.201 node1 192.168.52.202 node2 192.168.52.203 node3 at the end
9, Scheduled task instruction crontab configuration
crontab yes Unix and Linux Instructions for setting scheduled tasks. adopt crontab Command, which can be used at fixed intervals,Execute specified system instructions or shell script. The unit of time interval can be any combination of minutes, hours, days, months, weeks and above. crontab Installation: yum install crontabs Service operation instructions: service crond start ## Start service service crond stop ## Shut down service service crond restart ## Restart service ##
9.1 command format
crontab [-u user] file crontab [-u user] [ -e | -l | -r ] Parameter Description: -u user: Used to set a user's crontab service file: file Is the name of the command file,Indicates that it will file As crontab And load the task list file crontab. -e: Edit a user's crontab File content. If no user is specified, it means that the current user's name is edited crontab Documents. -l: Displays the of a user crontab File content. If no user is specified, the current user's name will be displayed crontab File content. -r: Delete scheduled task configuration from/var/spool/cron Delete a user's from the directory crontab File. If no user is specified, the current user's will be deleted by default crontab Documents. Command example: crontab file [-u user] ## Replace the current crontab with the specified file crontab -l [-u user] ## Lists the current crontab of the user crontab -e [-u user] ## Edit the user's current crontab ##
9.2 configuration description and examples
Command:* * * * * command Explanation: the first column of time-sharing day month week command indicates minute 1~59 Per minute*perhaps */1 express Column 2 represents hour 0~23(0 (indicates 0 points) column 3 indicates date 1~31 Column 4 represents month 1~12 Column 5 identification number week 0~6(0 Indicates the command configuration instance to be run in column 6 of Sunday): First open the file where the scheduled task is located: crontab -e Every minute date command */1 * * * * date >> /root/date.txt 21 every night:30 restart apache. 30 21 * * * service httpd restart 4 on the 1st, 10th and 22nd of each month : 45 restart apache. 45 4 1,10,22 * * service httpd restart Every Saturday and Sunday : 10 restart apache. 10 1 * * 6,0 service httpd restart 18 per day : 00 To 23 : 00 Restart every 30 minutes between apache. 0,30 18-23 * * * service httpd restart Restart every hour between 11 p.m. and 7 a.m apache * 23-7/1 * * * service httpd restart
10, Other commands
10.1 view current directory: pwd
Command: pwd View current directory path
10.2 viewing process: ps -ef
Command: ps -ef View all running processes
10.3 ending process: kill
Command: kill pid perhaps kill -9 pid(Force kill process) pid:Process number
10.4 network communication command:
ifconfig: View network card information Command: ifconfig or ifconfig | more ping: Check the connection with a machine Command: ping ip netstat -an: View current system port Command: netstat -an Search for the specified port Command: netstat -an | grep 8080
10.5 configuring the network
Command: setup
10.6 network restart
Command: service network restart
10.7 switching users
Command: su - user name
10.8 turn off the firewall
Command: chkconfig iptables off Or: iptables -L; iptables -F; service iptables stop##
10.9 modify file permissions
Command: chmod 777
10.10 screen clearing
Command: ctrl + l
10.11 shortcut keys in VI mode
esc after:Save and exit shortcut: shift+z+z The cursor jumps to the last line. Shortcut key: shift+g Delete a row: dd Copy a line: y+y Paste copied content: p
11, Linux project deployment
11.1 installation jdk1 eight
Uninstall first open-jdkjava -versionrpm -qa | grep javarpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64 Start installation: mkdir /usr/local/src/javarz upload jdk tar package tar -zxvf jdk-8u181-linux-x64.tar.gzyum install glibc.i686 Configure environment variables: vi /etc/profile Add at the end line #set java environment JAVA_ HOME=/usr/local/src/jdk8/jdk1. 8.0_ 181 CLASSPATH=.:$ JAVA_ HOME/lib. tools. jar PATH=$JAVA_ HOME/bin:$PATH export JAVA_ Home classpath save exit source /etc/profile to make the changed configuration take effect immediately. Java version view the JDK version information. If 1.8 is displayed, it proves successful
11.2 install MySQL 5 six
11.2.1 upload mysql5 6 tar package
Create directory: mkdir /usr/local/src/mysql5.6 Upload: MySQL-5.6.34-1.rhel5.x86_64.rpm-bundle.tar To the directory above
11.2.2 installation
Step 1: unzip
Command: tar -xvf MySQL-5.6.34-1.rhel5.x86_64.rpm-bundle.tar
Step 2: check whether mysql has been installed
Command: rpm -qa | grep mysql If it is already installed, uninstall it, such as: rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
Step 3: install MySQL server
Command: rpm -ivh MySQL-server-5.6.34-1.rhel5.x86_64.rpm
Step 4: install MySQL client
Command: rpm -ivh MySQL-client-5.6.34-1.rhel5.x86_64.rpm
Step 5: check the running status of MySQL service
Command: service mysql status
Step 6: start MySQL service
Command: service mysql start
Step 7: log in to mysql with root account
There is a prompt when installing mysql server:
Note: this password is not secure. You need to change the initial password.
Login with password mysql account number: mysql -uroot -p modify root password: SET PASSWORD = PASSWORD('root');
11.2.3 automatic startup setting
Join system services: chkconfig --add mysql Auto start: chkconfig mysql on Query list: chkconfig Note: none of them are closed( off)There is no automatic start.
11.2.4 enable remote access
Sign in: mysql -uroot –proot Set up remote access (using root Password): grant all privileges on *.* to 'root' @'%' identified by 'root';flush privileges;sign out mysql,stay centos Open 3306 firewall in environment/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT/etc/rc.d/init.d/iptables save/etc/init.d/iptables status
11.3 installing tomcat deployment project
Preparatory work: will web Project success war Bag, renamed ROOT.war
11.3.1 create ucenter user
In general, publishing applications are not used root Users need to create an ordinary user to publish the program; establish ucenter User: useradd -d /ucenter ucenter Set password: passwd ucenter (password ucenter)Switch users: su - ucenter
11.3.2 installing Tomcat
tomcat As long as you unzip it, you can use it. 1. Create web catalogue mkdir /ucenter/web2,upload apache-tomcat-7.0.57.tar.gz3,Decompression: tar -xvf apache-tomcat-7.0.57.tar.gz4,Rename: mv apache-tomcat-7.0.57 itcast-usermanage5,start-up tomcat: cd itcast-usermanage/bin/ ./startup.sh perhaps sh startup.sh6,View log: tail -f ../logs/catalina.out7,View effect http://192.168.0.160:8080/ found inaccessible: 8. Firewall opens 8080 port / SBIN / iptables - I input - P TCP -- dport 8080 - J accept / etc / RC d/init. D / iptables save9. Installation succeeded
11.3.3 deploy user management project
1. Upload usermanage SQL and root War to / ucenter/web
2. Execute database script
cat user_manager.sql | mysql -uroot -p123456
3. Deploy web application
3.1 delete all files under webapps
cd /ucenter/web/usermanage/webapps rm -rf *
3.2 copy root War to webapps
cp /ucenter/web/ROOT.war .
3.3 restart tomcat
cd ../bin/ sh startup.sh && tail -f ../logs/catalina.out
3.4 start Browser Test
Note: the solution to the problem of Chinese garbled code in the deployment project under Centos environment
Today on a new computer CentOS Use on machine c3p0 Connection pool operation mysql There is a Chinese garbled code problem in the database, which is specifically manifested as: there is no Chinese garbled code problem during query, and there is Chinese garbled code when writing data. It is also the same when viewing the database character set on the machine UTF8,There should be no Chinese random code. Finally c3p0 In the configuration file jdbcUrl Add after:?useUnicode=true&characterEncoding=UTF8 Chinese won't be garbled.
[C3P0 configuration file]
<?xml version="1.0" encoding="UTF-8"?><c3p0-config> <default-config> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/user_manager_yun6?useUnicode=true&characterEncoding=UTF8 </property> <property name="user">root</property> <property name="password">root</property> <property name="acquireIncrement">2</property> <property name="initialPoolSize">5</property> <property name="minPoolSize">1</property> <property name="maxPoolSize">5</property> </default-config></c3p0-config>
11.4 using FastDFS under Linux
Relevant installation packages have been packaged on the cloud disk. Link: https://pan.baidu.com/s/13NDYYil4mgLhkb5CYsc2Ww Extraction code: 66tn
Single node FastDFS
The whole installation process is very complex and error prone. It is recommended to make multiple backups.
We are not going to install multiple virtual machines here, so we will install both tracker and storage together.
11.4.1 installation of gcc
GCC Used for C Language code to compile and run, using yum Command installation: yum -y install gcc The decompression command will be used later( unzip),So it can be used here yum hold unzip Install it, too yum install -y unzip zip
11.4.2 installing libevent
yum -y install libevent
11.4.3 installing libfastcommon master
Unzip the just uploaded libfastcommon-master.zipunzip libfastcommon-master.zip Enter the directory where the decompression is completed cd libfastcommon-master Compile and install:./make.sh ./make.sh install
11.4.4 installing fastdfs
tar -zxvf FastDFS_v5.08.tar.gzcd FastDFS./make.sh./make.sh install
If the installation is successful, you will see / etc / init D / see the provided script file below:
ll /etc/init.d/ | grep fdfs
fdfs_trackerd yes tracker Startup script fdfs_storaged yes storage Startup script
You can see the default configuration file template in the / etc/fdfs / Directory:
ll /etc/fdfs/
tarcker.conf.sample yes tracker Profile template for storage.conf.sample yes storage Profile template for client.conf.sample Is the profile template for the client
11.4.5 configure and start the tracker service
1)First copy the template file cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf2)Modify the copied configuration file: vim /etc/fdfs/tracker.conf
The revised contents are as follows:
base_path=/Project name/tracker # The root directory where logs and data are stored 3)New directory: mkdir -p /Project name/tracker Note: turn off the firewall: chkconfig iptables off 4)start and stopping service fdfs_trackerd start # Start FDFS_ Tracker service, stop using stop inspect FastDFS Tracker Server Start successfully: ps -ef | grep fdfs_trackerd set up tracker Service startup: chkconfig fdfs_trackerd on
11.4.6 configure and start the storage service
1)First copy the template file cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf 2)Modify the copied configuration file: vim /etc/fdfs/storage.conf The revised content is as follows: base_path=/Project name/storage # Data and log file storage root directory store_path0=/Project name/storage # First storage directory tracker_server=192.168.56.101:22122 # tracker server IP and port 3)New directory: mkdir -p /Project name/storage Note: turn off the firewall: chkconfig iptables off 4)start and stopping service fdfs_storaged start # Start FDFS_ Stored service, stop set up storage Service startup: chkconfig fdfs_storaged on ps -ef | grep fdfs
11.5 installing fastdfs nginx module
11.5.1 decompression
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz11.5.2 modify config1)get into src catalogue cd fastdfs-nginx-module/src/2)edit configvim config Use the following bottom line command::%s+/usr/local/+/usr/+g Put all/usr/local Replace with /usr,This is the correct directory:
11.5.3 configure nginx and FastDFS associated configuration files
Copy the configuration file in the fastdfs nginx module source code to the / etc/fdfs directory and modify it
cp /usr/local/Project name/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ vi /etc/fdfs/mod_fastdfs.conf
Modify the following configuration:
connect_timeout=10 # Timeout length of client access file connection (unit: seconds) tracker_server=192.168.56.101:22122 # tracker service IP And port url_have_group_name=true # Access link prefix plus group name store_path0=/leyou/storage # File storage path
Copy some configuration files of FastDFS to / etc/fdfs directory
cd /usr/local/Project name/FastDFS/conf/cp http.conf mime.types /etc/fdfs/
11.6 installing the plugin of Nginx
11.6.1 if nginx is not installed
1. nginx dependent installation Library
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. Unzip the installation package
tar -zxvf nginx-1.10.0.tar.gz
3. Configure the nginx installation package and specify fastdfs nginx model
cd nginx-1.10.0 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/leyou/fastdfs-nginx-module/src
Note: in execution/ When configuring nginx parameters, you need to compile the fastdfs nginx moudle source code as a module.
4. Compile and install
make && make install
11.6.2 if nginx has been installed
1, get into nginx catalog: cd /usr/local/Project name/nginx-1.10.0/2, to configure FastDFS modular./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/Project name/fastdfs-nginx-module/src Note: during this configuration, you need to add fastdfs-nginx-moudle Module 3. Compile. Be careful not to install this time( install)make4,replace nginx Binary file:Backup: mv /usr/bin/nginx /usr/bin/nginx-bak With newly compiled nginx The startup file replaces the original one: cp objs/nginx /usr/bin/
11.6.3 start nginx
Configure nginx integration fastdfs module
We need to modify the nginx configuration file in / opt / nginx / config / nginx In the conf file:
vim /opt/nginx/conf/nginx.conf
Replace the original server 80 {...} code in the file with the following code:
server { listen 80; server_name image.Project name.com; # Listen to the domain name with group, and submit it to FastDFS module for processing location ~ / group ([0-9]) / {ngx_FastDFS_module;} location / { root html; index index.html index.htm; } error_ page 500 502 503 504 /50x. html; location = /50x. html { root html; }}
Start nginx:
nginx # start-up nginx nginx -s stop # stop it nginx nginx -s reload # Reload configuration file
You can check whether nginx has been started successfully through ps -ef | grep nginx
11.6.4 setting nginx startup
Create a startup script:
vim /etc/init.d/nginx
Add the following:
#!/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/bin/nginx"prog=$(basename $nginx) NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -n "$user" ]; then if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done fi} start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs 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} 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 2esac
Modify file permissions and add them to the service list
# Modify permissions chmod 777 /etc/init.d/nginx # Add to service list chkconfig --add /etc/init.d/nginx
Set startup
chkconfig nginx on
11.7 installing Elasticsearch
Requires virtual machine jdk1 8 and above
11.7.1 create a new user leyou
For security reasons, elasticsearch is not allowed to run under the root account by default.
Create user:
useradd leyou
Set password:
passwd leyou
Switch users:
su - leyou
11.7.2 upload and unzip the installation package
We will upload the installation package to:/home/leyou Directory decompression: tar -zxvf elasticsearch-6.2.4.tar.gz We rename the directory: mv elasticsearch-6.3.0/ elasticsearch Enter to view the directory structure:
11.7.3 modify configuration
We enter the config Directory: cd config
There are two configuration files that need to be modified:
1,jvm.options
Elasticsearch is based on Lucene, and the underlying layer of Lucene is implemented in java, so we need to configure jvm parameters.
Edit JVM options:
vim jvm.options
The default configuration is as follows:
-Xms1g
-Xmx1g
Too much memory, let's turn it down:
-Xms512m
-Xmx512m
2,elasticsearch.yml
vim elasticsearch.yml
Modify the data and log directory:
path.data: /home/leyou/elasticsearch/data # Data directory location path.logs: /home/leyou/elasticsearch/logs # Log directory location
We modified the data and logs directories to point to the installation directory of elasticsearch. However, these two directories do not exist, so we need to create them.
Enter the root directory of elasticsearch and create:
mkdir datamkdir logs
Modify the bound ip:
network.host: 0.0.0.0 # bound to 0.0.0.0, allowing any ip to access
Only local access is allowed by default. After it is modified to 0.0.0.0, it can be accessed remotely
11.7.4 operation
get into elasticsearch/bin Directory, you can see the following executable file: then enter the command:./elasticsearch Or run in the background:./elasticsearch -d
11.7.5 error 1: kernel too low
Modify elasticsearch YML file, add the following configuration at the bottom: then restart
bootstrap.system_call_filter: false
11.7.6 error 2: insufficient file permissions
We use the leyou user instead of root, so the file permissions are insufficient.
First log in as root. Enter the exit command directly
Then modify the configuration file:
vim /etc/security/limits.conf
Add the following:
* soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096
11.7.7 error 3: insufficient number of threads
[1]: max number of threads [1024] for user [leyou] is too low, increase to at least [4096]
Continue to modify the configuration:
vim /etc/security/limits.d/90-nproc.conf
Modify the following:
- soft nproc 1024
Change to
- soft nproc 4096
11.7.8 error 4: process virtual memory
[3]: max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
vm.max_map_count: limit the number of VMA (virtual memory area) that a process can own. Continue to modify the configuration file:
vim /etc/sysctl.conf
Add the following:
vm.max_map_count=655360
Then execute the command:
sysctl -p
11.7.9 restart the terminal window
If the Xshell configuration is not correct, you must restart the Xshell.
11.8 installing RabbitMQ
cd /usr/local/myapp mkdir rabbitmq cd rabbitmq
11.8.1 installing Erlang
1. Online installation
yum install esl-erlang_17.3-1~centos~6_amd64.rpm yum install esl-erlang-compat-R14B-1.el6.noarch.rpm
2. Offline installation
Execute the commands in sequence:
1)rpm -ivh esl-erlang-17.3-1.x86_64.rpm --force --nodeps
2)rpm -ivh esl-erlang_17.3-1centos6_amd64.rpm --force --nodeps
3)rpm -ivh esl-erlang-compat-R14B-1.el6.noarch.rpm --force --nodeps
11.8.2 installing RabbitMQ
Installation:
rpm -ivh rabbitmq-server-3.4.1-1.noarch.rpm
11.8.3 setting configuration file
cp /usr/share/doc/rabbitmq-server-3.4.1/rabbitmq.config.example/etc/rabbitmq/rabbitmq.config
Enable user remote access
vi /etc/rabbitmq/rabbitmq.config
Be careful to remove the trailing comma.
11.8.4 start and stop
service rabbitmq-server start service rabbitmq-server stop service rabbitmq-server restart
11.8.5 open the web interface management tool
rabbitmq-plugins enable rabbitmq_management service rabbitmq-server restart
11.8.6 setting startup
chkconfig rabbitmq-server on
11.8.7 firewall opening 15672 port
/sbin/iptables -I INPUT -p tcp --dport 15672 -j ACCEPT /etc/rc.d/init.d/iptables save
11.9 redis installation and configuration
11.9.1 installation
decompression
tar -xvf redis-4.0.9.tar.gz
Compile and install
mv redis-4.0.9 redis cd redis make && make install
11.9.2 configuration
Modify redis. In the installation directory Conf file
vim redis.conf
Modify the following configuration:
#bind 127.0.0.1 # Comment this line of code and listen for all ip Address, accessible from the Internet protected-mode no # hold yes Change to no,Allow Internet access daemonize yes # Change no to yes and run in the background
11.9.3 start or stop
redis provides server commands and client commands:
redis-server The server command can include the following parameters: start start-up stop stop it redis-cli Client console, including parameters: -h xxx Specify the server address. The default value is 127.0.0.1 -p xxx Specify the server port. The default value is 6379
11.9.4 setting startup
- Enter a command to create a new file
vim /etc/init.d/redis
Enter the following:
#!/bin/sh # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pid CONF="/usr/local/leyou/redis/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $REDIS_CLI -p $REDISPORT SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac
Then save and exit
Note: the following information needs to be adjusted according to the installation directory:
EXEC=/usr/local/bin/redis-server # The address where the script is executed REDIS_CLI=/usr/local/bin/redis-cli # The address where the client executes the script PIDFILE=/var/run/redis.pid # Process id file address CONF="/usr/local/src/redis-3.0.2/redis.conf" #Profile address
2) Set permissions
chmod 755 /etc/init.d/redis
3) Start test
/etc/init.d/redis start
If the startup is successful, the following information will be prompted:
Starting Redis server...
Redis is running...
4) Set startup and self startup
chkconfig --add /etc/init.d/redis chkconfig redis on