Linux commonly used server operation and maintenance commands

The blogger implements the spirit of open source. This blog is reproduced from multiple articles, but the original link cannot be included in the copyright link, and there is no profit. If there is infringement, please contact and delete in time

 

One: ps command to view the process command

-a, view all

-u, display in user (user) format

-x, display background process operating parameters

-ef, display all information of the process in full format, including the parent process Pid, ​​creator, creation time, and process number. and many more

In general projects, we first need to query a process and delete it with the following command

ps -a | grep tomcat or

ps -ef |grep tomcat or other

Query the helloworld related process, we use the kill command to operate the process number to delete the process, kill -9 5089
 

Two: database operation
yum -y install mysql-community-server

(The above command may report that there is no such resource, just find the corresponding mysql resource link.)

The yum installation will overwrite the previous mariadb, which can be said to be very convenient for those who don’t want a pass configuration

First start MySQL

[root@localhost ~]# systemctl start  mysqld.service

View MySQL running status

[root@localhost ~]# systemctl status mysqld.service

If active appears, the startup is successful 

First check the MySQL related directory
root@ubuntu14:~# whereis mysql
mysql: 
/usr/bin/mysql---- mysql running path 
/etc/mysql 
/usr/lib/mysql---- mysql installation path under linux
/usr/bin/X11/mysql 
/usr/share/mysql
/usr/share/man/man1/mysql.1.gz
There is another one:
var/lib/mysql --------mysql database data file Storage path

Determine the running path, execute the import and export mysql database commands
1. Export the database with the mysqldump command
(note: first cd to the mysql running path, and then execute the command):
1. Export data and table structure:
mysqldump -u username -p password database name> database name .sql
mysqldump-uroot--p dbname> dbname .sql
after knockout round will be prompted for a password
2, only export the table structure
mysqldump -u username -p password -d database name> database name. sql
mysqldump -uroot -p -d dbname> dbname .sql

2. Import the database
1. First create a blank database
mysql>create database dbname;
2. Import the database
Method 1:
(1) Select the database
mysql>use dbname;
(2) Set the database encoding
mysql>set names utf8;
(3) Import data (Note the path of the sql file)
mysql>source /home/xxxx/dbname .sql;
Method two:
mysql -u username -p password database name <database name.sql 

Three: Redis common Linux configuration process

installation:

1. Get redis resources

  wget http://download.redis.io/releases/redis-4.0.8.tar.gz

2. Unzip

  tar xzvf redis-4.0.8.tar.gz

3. Installation

  cd redis-4.0.8

  make

  cd src

  make install PREFIX=/usr/local/redis

4. Move the configuration file to the installation directory

  cd ../

  mkdir /usr/local/redis/etc

  mv redis.conf /usr/local/redis/etc

 5. Configure redis to start in the background

  vi /usr/local/redis/etc/redis.conf // Change daemonize no  to daemonize yes

6. Add redis to boot

  vi /etc/rc.local //Add content to it: /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (meaning that the command to start redis is called at boot)

7. Open redis

  /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 

Common commands  

  redis-server /usr/local/redis/etc/redis.conf //Start redis

  pkill redis //stop redis

  Uninstall redis:

    rm -rf /usr/local/redis //Delete the installation directory

    rm -rf /usr/bin/redis-* //Delete all redis related command scripts

    rm -rf /root/download/redis-4.0.4 //Delete the redis unzipped folder

8- Start redis:

Two ways:

redis-server &

 

加上`&`号使redis以后台程序方式运行

or

redis-server

9-Detect whether the background process exists

ps -ef |grep redis

10- Check if port 6379 is listening

netstat -lntp | grep 6379

Sometimes it will report an exception

Reason: Redis has been started

Solution: Turn off Redis and restart

  1. redis-cli shutdown

  2. redis-server

Then you can see Redis running happily.

Use the redis-cliclient to detect whether the connection is normal

  1. redis-cli

  2. 127.0.0.1:6379> keys *

  3. (empty list or set)

  4. 127.0.0.1:6379> set key "hello world"

  5. OK

  6. 127.0.0.1:6379> get key

  7. "hello world"

Stop redis:

Use client

redis-cli shutdown

Because Redis can handle the SIGTERM signal properly, it is also possible to directly kill -9

kill -9 PID

 

#Start redis server
$ src/redis-server
 
 
#Start redis client
$ src/redis-cli

Four. Unzip and install MYSQL5.7

For developers, the installation of Mysql database is a problem we will inevitably face. Its installation process is not complicated, and there are many installation tutorials on the Internet, but for novices, there are various forms of installation The tutorial has brought the novices the difficulty of which way to choose to install, and in many cases, the installation failed according to the tutorial, and various errors occurred during the installation process.

This document explains that the installation version is mysql-5.7.24. For versions after 5.7.24, this document is not applicable. The main reason is that the directory location and structure of the mysql configuration file of the later version have changed. This instruction may appear The configuration file cannot be found or the configuration does not take effect.

During the installation process, ensure that the file path is consistent, otherwise it may cause unpredictable results. It is recommended to use the commands in the text directly.

One preparation before installation

1. Check whether mysql has been installed and execute the command

 

[root@localhost /]# rpm -qa | grep mysql

From the execution results, we can see that we have installed mysql-libs-5.1.73-5.el6_6.x86_64 , execute the delete command

 

[root@localhost /]# rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64

Execute the query command again to see if it is deleted

 

[root@localhost /]# rpm -qa | grep mysql

2. Query all folders corresponding to Mysql

 

[root@localhost /]# whereis mysql
mysql: /usr/bin/mysql /usr/include/mysql
[root@localhost lib]# find / -name mysql
/data/mysql
/data/mysql/mysql

Delete related directories or files

 

[root@localhost /]#  rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql 

Verify that the deletion is complete

 

[root@localhost /]# whereis mysql
mysql:
[root@localhost /]# find / -name mysql
[root@localhost /]# 

3. Check whether the mysql user group and user exist, if not, create

 

[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd |grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
[root@localhost /]# 

4. Download the Mysql installation package for Linux from the official website

Download command:

 

[root@localhost /]#  wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

You can also go directly to the mysql official website to select other versions to download.

Two install Mysql

1. Find the Mysql installation package in the directory where the wget command is executed or your upload directory: mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
execute the decompression command:

 

[root@localhost /]#  tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost /]# ls
mysql-5.7.24-linux-glibc2.12-x86_64
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

After the decompression is complete, you can see that there is an additional decompressed file in the current directory. Move the file to /usr/local/ and modify the folder name to mysql .

If mysql already exists under /usr/local/ , please modify the existing mysql file to another name, otherwise the subsequent steps may not be performed correctly.

The execution command is as follows:

 

[root@localhost /]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/
[root@localhost /]# cd /usr/local/
[root@localhost /]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

If there is no mysql folder under /usr/local/ , you can directly execute the following command to achieve the above effect.

 

[root@localhost /]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

2. Create a data directory under the /usr/local/mysql directory

 

[root@localhost /]# mkdir /usr/local/mysql/data

3. Change the user groups and users, and permissions of all directories and folders in the mysql directory

 

[root@localhost /]# chown -R mysql:mysql /usr/local/mysql
[root@localhost /]# chmod -R 755 /usr/local/mysql

4. Compile, install and initialize mysql, be sure to remember the password at the end of the initial output log (temporary password of the database administrator)

 

[root@localhost /]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

Supplementary note:

In step 4, an error may occur:

When this problem occurs, first check whether the link library file is installed and use the command to check

 

[root@localhost bin]# rpm -qa|grep libaio   
[root@localhost bin]# 

After running the command, it is found that there is no such link library file in the system

 

[root@localhost bin]#  yum install  libaio-devel.x86_64

After the installation is successful, continue to run the initialization command of the database, the following error may occur at this time:

After executing the following command:

 

[root@localhost bin]#  yum -y install numactl

After the execution is correct, re-execute the 4th step initialization command, and then proceed to the 5th step again!


5. After running the initialization command successfully, the output log is as follows:

Record the string after root@localhost: at the end of the log . This string is the temporary login password of the MySQL administrator.

6. Edit the configuration file my.cnf and add the configuration as follows

 

[root@localhost bin]#  vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

7, start the mysql server

 

[root@localhost /]# /usr/local/mysql/support-files/mysql.server start

The following results are displayed, indicating that the database is successfully installed

If the following message appears

 

Starting MySQL... ERROR! The server quit without updating PID file

Check whether there are mysql and mysqld services, if they exist, terminate the process, and then execute the start command again

 

#查询服务
ps -ef|grep mysql
ps -ef|grep mysqld

#结束进程
kill -9 PID

#启动服务
 /usr/local/mysql/support-files/mysql.server start

8. Add a soft connection and restart the mysql service

 

[root@localhost /]#  ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
[root@localhost /]#  ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost /]#  service mysql restart

9. Log in to mysql and change the password (the password is the temporary password generated in step 5)

 

[root@localhost /]#  mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('yourpass');

10. Open remote connection

 

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

11. Set automatic startup

 

1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list



Author: Happy flea
link: https: //www.jianshu.com/p/276d59cbc529
Source: Jane books
are copyrighted by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

Guess you like

Origin blog.csdn.net/ClearLoveQ/article/details/105579644