Linux云自动化运维第十六课

第八单元 Mariadb数据库

一、Mariadb安装

1.安装mariadb和mariadb-client组件:

# yum groupinstall -y mariadb mariadb-client

2.启动mariadb服务:

# systemctl start mariadb ; systemctl enable mariadb

3.校验mariadb的监听端口:

# ss -antlp |grep mysql

LISTEN 0 50 *:3306 *:* users:(("mysqld",3345,13))

4.编辑/etc/my.cnf文件,在[mysqld]中加入以下参数:

skip-networking=1

# systemctl restart mariadb

# ss -antlp |grep mysql

此时只允许通过套接字文件进行本地连接,阻断所有来自网络的tcp/ip连接。

5.使用mysql_secure_installation工具进行数据库安全设置,根据提示完成操作:

# mysql_secure_installation

6.登录数据库:

# mysql -u root -p

Enter password: redhat

MariaDB [(none)]> show databases;

+--------------------+

| Database

|

+--------------------+

| information_schema |

| mysql

|

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> quit

7.示例:

[[email protected] ~]# yum search mariadb

Loaded plugins: langpacks

============================= N/S matched: mariadb =============================

mariadb-bench.x86_64 : MariaDB benchmark scripts and data

mariadb-devel.i686 : Files for development of MariaDB/MySQL applications

mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications

mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients

mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients

mariadb-server.x86_64 : The MariaDB server and related files

mariadb.x86_64 : A community developed branch of MySQL

mariadb-test.x86_64 : The test suite distributed with MariaD

Name and summary matches only, use "search all" for everything.

[[email protected] ~]# yum install mariadb-server.x86_64 -y

[[email protected] ~]# systemctl start mariadb

[[email protected] ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [(none)]> USE mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mysql]> SHOW TABLES;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| servers                   |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

24 rows in set (0.00 sec)

MariaDB [mysql]> select Host from user;

+-------------------------+

| Host                    |

+-------------------------+

| 127.0.0.1               |

| ::1                     |

| httpdesktop.example.com |

| httpdesktop.example.com |

| localhost               |

| localhost               |

+-------------------------+

6 rows in set (0.00 sec)

MariaDB [mysql]> select Host,User,Password from user;

+-------------------------+------+----------+

| Host                    | User | Password |

+-------------------------+------+----------+

| localhost               | root |          |

| httpdesktop.example.com | root |          |

| 127.0.0.1               | root |          |

| ::1                     | root |          |

| localhost               |      |          |

| httpdesktop.example.com |      |          |

+-------------------------+------+----------+

6 rows in set (0.00 sec)

MariaDB [mysql]> quit

Bye

[[email protected] ~]# netstat -antlpe | grep mysql

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      27         171163     4563/mysqld

[[email protected] ~]# vim /etc/my.cnf

#skip-networking=1

[[email protected] ~]# systemctl restart mariadb.service

[[email protected] ~]# netstat -antlpe | grep mysql

[[email protected] ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

Bye

[[email protected] ~]# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we‘ll need the current

password for the root user.  If you‘ve just installed MariaDB, and

you haven‘t set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from ‘localhost‘.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

... Success!

By default, MariaDB comes with a database named ‘test‘ that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

[[email protected] ~]# mysql

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

[[email protected] ~]# mysql -uroot -predhat

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 12

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

Bye

[[email protected] ~]#

二、数据库基本操作SQL

SHOW DATABASES;

CREATE DATABASE database_name;

USE database_name;

SHOW tables;

CREATE TABLE table_name (name VARCHAR(20), sex CHAR(1));

DESCRIBE table_name;

INSERT INTO table_name VALUES (‘wxh‘,‘M‘);

SELECT * FROM table_name;

UPDATE table_name SET attribute=value WHERE attribute > value;

DELETE FROM table_name WHERE attribute = value;

DROP TABLE table_name;

DROP DATABASE database_name;

eg:[[email protected] ~]# mysql -uroot -predhat

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 13

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> CREATE DATABASE westos;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| westos             |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [(none)]> use westos;

Database changed

MariaDB [westos]> show tables;

Empty set (0.00 sec)

MariaDB [westos]> create table linux (

-> username varchar(50) not null,

-> password varchar(50) not null );

Query OK, 0 rows affected (0.08 sec)

MariaDB [westos]> show tables;

+------------------+

| Tables_in_westos |

+------------------+

| linux            |

+------------------+

1 row in set (0.00 sec)

MariaDB [westos]> insert into linux values (‘user1‘,‘passwd1‘);

Query OK, 1 row affected (0.06 sec)

MariaDB [westos]> insert into linux values (‘user2‘,‘passwd2‘);

Query OK, 1 row affected (0.03 sec)

MariaDB [westos]> select * from linux;

+----------+----------+

| username | password |

+----------+----------+

| user1    | passwd1  |

| user2    | passwd2  |

+----------+----------+

2 rows in set (0.00 sec)

MariaDB [westos]> quit

Bye

[[email protected] ~]#

[[email protected] ~]# mysql -uroot -predhat

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 14

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| westos             |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [(none)]> use westos

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [westos]> show tables;

+------------------+

| Tables_in_westos |

+------------------+

| linux            |

+------------------+

1 row in set (0.00 sec)

MariaDB [westos]> select * from linux;

+----------+----------+

| username | password |

+----------+----------+

| user1    | passwd1  |

| user2    | passwd2  |

+----------+----------+

2 rows in set (0.00 sec)

MariaDB [westos]> delete from linux where username=‘user1‘;

Query OK, 1 row affected (0.05 sec)

MariaDB [westos]> select * from linux;

+----------+----------+

| username | password |

+----------+----------+

| user2    | passwd2  |

+----------+----------+

1 row in set (0.00 sec)

MariaDB [westos]> delete from linux where username=‘user2‘;

Query OK, 1 row affected (0.52 sec)

MariaDB [westos]> select * from linux;

Empty set (0.00 sec)

MariaDB [westos]> drop table linux;

Query OK, 0 rows affected (0.04 sec)

MariaDB [westos]> show tables;

Empty set (0.00 sec)

MariaDB [westos]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| westos             |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [westos]> drop database westos ;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> quit

Bye

[[email protected] ~]#

三、用户和访问权限

1.创建用户

CREATE USER [email protected] identified by ‘westos‘;

CREATE USER [email protected]‘%‘ identified by ‘redhat‘;

2.用户授权

GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to [email protected];

GRANT SELECT on mariadb.* [email protected]‘%‘;

3.重载授权表

FLUSH PRIVILEGES;

4.查看用户授权

SHOW GRANTS FOR [email protected];

5.撤销用户权限

REVOKE DELETE,UPDATE,INSERT on mariadb.* from [email protected];

6.删除用户

DROP USER [email protected];

7.示例:

[[email protected] ~]# mysql -u root -predhat

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 17

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> GRANT INSERT ON westos.*  to [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANT FOR [email protected];

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘GRANT FOR [email protected]‘ at line 1

MariaDB [(none)]> SHOW GRANTS FOR [email protected];

+-------------------------------------------------------------+

| Grants for [email protected]                                |

+-------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘student‘@‘localhost‘                 |

| GRANT SELECT, INSERT ON `westos`.* TO ‘student‘@‘localhost‘ |

+-------------------------------------------------------------+

2 rows in set (0.00 sec)

MariaDB [(none)]> REVOKE INSERT on westos.* FROM [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANTS FOR [email protected];

+-----------------------------------------------------+

| Grants for [email protected]                        |

+-----------------------------------------------------+

| GRANT USAGE ON *.* TO ‘student‘@‘localhost‘         |

| GRANT SELECT ON `westos`.* TO ‘student‘@‘localhost‘ |

+-----------------------------------------------------+

2 rows in set (0.00 sec)

MariaDB [(none)]> REVOKE SELECT on westos.* FROM [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANTS FOR [email protected];

+---------------------------------------------+

| Grants for [email protected]                |

+---------------------------------------------+

| GRANT USAGE ON *.* TO ‘student‘@‘localhost‘ |

+---------------------------------------------+

1 row in set (0.00 sec)

MariaDB [(none)]> DROP USER [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT USER FROM mysql.user

-> ;

+--------+

| USER   |

+--------+

| root   |

| root   |

| root   |

| westos |

+--------+

4 rows in set (0.00 sec)

MariaDB [(none)]> DROP USER [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT USER FROM mysql.user;

+------+

| USER |

+------+

| root |

| root |

| root |

+------+

3 rows in set (0.00 sec)

MariaDB [(none)]> quit

Bye

[[email protected] ~]#

[[email protected] ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE westos

-> ;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES

-> ;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

| westos             |

+--------------------+

5 rows in set (0.00 sec)

MariaDB [(none)]> USE westos;

Database changed

MariaDB [westos]> CREATE TABLE linux(

-> username varchar(40) not null,

-> password varchar(40) not null );

Query OK, 0 rows affected (0.38 sec)

MariaDB [westos]> DESC linux;

+----------+-------------+------+-----+---------+-------+

| Field    | Type        | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| username | varchar(40) | NO   |     | NULL    |       |

| password | varchar(40) | NO   |     | NULL    |       |

+----------+-------------+------+-----+---------+-------+

2 rows in set (0.00 sec)

MariaDB [westos]> ALTER TABLE linux DROP age;

ERROR 1091 (42000): Can‘t DROP ‘age‘; check that column/key exists

MariaDB [westos]> ALTER TABLE linux ADD age VARCHAR(5);

Query OK, 0 rows affected (0.13 sec)

Records: 0  Duplicates: 0  Warnings: 0

MariaDB [westos]> DESC linux;

+----------+-------------+------+-----+---------+-------+

| Field    | Type        | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| username | varchar(40) | NO   |     | NULL    |       |

| password | varchar(40) | NO   |     | NULL    |       |

| age      | varchar(5)  | YES  |     | NULL    |       |

+----------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

MariaDB [westos]> ALTER TABLE linux DROP age;

Query OK, 0 rows affected (0.24 sec)

Records: 0  Duplicates: 0  Warnings: 0

MariaDB [westos]> DESC linux;

+----------+-------------+------+-----+---------+-------+

| Field    | Type        | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| username | varchar(40) | NO   |     | NULL    |       |

| password | varchar(40) | NO   |     | NULL    |       |

+----------+-------------+------+-----+---------+-------+

2 rows in set (0.00 sec)

MariaDB [westos]> ALTER TABLE linux ADD age VARCHAR(5) AFTER username;

Query OK, 0 rows affected (0.12 sec)

Records: 0  Duplicates: 0  Warnings: 0

MariaDB [westos]> DESC linux;

+----------+-------------+------+-----+---------+-------+

| Field    | Type        | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| username | varchar(40) | NO   |     | NULL    |       |

| age      | varchar(5)  | YES  |     | NULL    |       |

| password | varchar(40) | NO   |     | NULL    |       |

+----------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

MariaDB [westos]> INSERT INTO linux VALUES (‘user1‘,‘20‘,‘123‘);

Query OK, 1 row affected (0.32 sec)

MariaDB [westos]> INSERT INTO linux VALUES (‘user2‘,‘10‘,‘123‘);

Query OK, 1 row affected (0.04 sec)

MariaDB [westos]> SELECT * FROM linux;

+----------+------+----------+

| username | age  | password |

+----------+------+----------+

| user1    | 20   | 123      |

| user2    | 10   | 123      |

+----------+------+----------+

2 rows in set (0.00 sec)

MariaDB [westos]> UPDATE linux set age=‘25‘ WHERE username=‘user1‘;

Query OK, 1 row affected (0.29 sec)

Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [westos]> SELECT * FROM linux;

+----------+------+----------+

| username | age  | password |

+----------+------+----------+

| user1    | 25   | 123      |

| user2    | 10   | 123      |

+----------+------+----------+

2 rows in set (0.00 sec)

MariaDB [(none)]> quit

Bye

[[email protected] ~]#

四、备份与恢复

1.备份

# mysqldump -uroot -predhat westos > westos.dump

# mysqldump -uroot -predhat --all-databases > backup.dump

# mysqldump -uroot -predhat --no-data westos > westos.dump

2.恢复

# mysqladmin -uroot -predhat create db2

# mysql -uroot -predhat db2 < westos.dump

3.忘了数据库密码怎么办?

# mysqld_safe --skip-grant-tables &

4.示例:

[[email protected] ~]# mysqldump -uroot -predhat --all-databases^C

[[email protected] ~]# mysqldump -uroot -predhat --all-databases --no-data^C

[[email protected] ~]# mysqldump -uroot -predhat westos^C

[[email protected] ~]# mysqldump -uroot -predhat westos>/mnt/westos.sql

[[email protected] ~]# mysql -uroot -predhat westos -e "SHOW DATABASES;"

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| westos             |

+--------------------+

[[email protected] ~]# mysql -uroot -predhat westos -e "DROP DATABASE westos;"

[[email protected] ~]# mysql -uroot -predhat -e "SHOW DATABASES;"

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

[[email protected] ~]# mysqladmin -uroot -predhat create westos

[[email protected] ~]# mysql -uroot -predhat -e "SHOW DATABASES;"

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| westos             |

+--------------------+

[[email protected] ~]# mysql -uroot -predhat -e "SHOW TABLES FROM westos;"

[[email protected] ~]# mysql -uroot -predhat westos</mnt/westos.sql

[[email protected] ~]# mysql -uroot -predhat -e "SHOW TABLES FROM westos;"

+------------------+

| Tables_in_westos |

+------------------+

| linux            |

+------------------+

[[email protected] ~]# mysql -uroot -predhat -e "SELECT * FROM westos.linux;"

+----------+------+----------+

| username | age  | password |

+----------+------+----------+

| user1    | 25   | 123      |

| user2    | 10   | 123      |

+----------+------+----------+

[[email protected] ~]# mysqladmin -u root -predhat password lee

[[email protected] ~]# mysql -u root -plee

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 20

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

Bye

[[email protected] ~]# systemctl stop mariadb

[[email protected] ~]# mysqld_safe --skip-grant-tables &

[1] 4407

[[email protected] ~]# 170418 22:09:50 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log‘.

170418 22:09:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[[email protected] ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 1

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> SELECT User,Password FROM mysql.user;

+------+-------------------------------------------+

| User | Password                                  |

+------+-------------------------------------------+

| root | *9BB439A3A652A9DAD3718215F77A7AA06108A267 |

| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

+------+-------------------------------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> UPDATE mysql.user set Password=‘redhat‘ WHERE User=‘root‘;

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [(none)]> SELECT User,Password FROM mysql.user;

+------+----------+

| User | Password |

+------+----------+

| root | redhat   |

| root | redhat   |

| root | redhat   |

+------+----------+

3 rows in set (0.00 sec)

MariaDB [(none)]> UPDATE mysql.user set Password=password (‘redhat‘) WHERE User=‘root‘;

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [(none)]> SELECT User,Password FROM mysql.user;+------+-------------------------------------------+

| User | Password                                  |

+------+-------------------------------------------+

| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

| root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |

+------+-------------------------------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> quit

Bye

[[email protected] ~]# ps aux | grep mysql

root      4407  0.0  0.0 113248  1564 pts/1    S    22:09   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables

mysql     4562  0.0  4.7 859060 90436 pts/1    Sl   22:09   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

root      4645  0.0  0.0 112640   944 pts/1    S+   22:14   0:00 grep --color=auto mysql

[[email protected] ~]# kill -9 4407

[[email protected] ~]# kill -9 4562

[1]+  Killed                  mysqld_safe --skip-grant-tables

[[email protected] ~]# ps aux | grep mysql

root      4655  0.0  0.0 112640   944 pts/1    R+   22:15   0:00 grep --color=auto mysql

[[email protected] ~]# systemctl restart mariadb

[[email protected] ~]# mysql -uroot -predhat

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

Bye

[[email protected] ~]# mysql

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

[[email protected] ~]#

五、Lab

1.在serverX和desktopX上执行脚本:# lab mariadb setup

install mariadb database groups.

start and enable the mariadb service.

stop and disable the firewall.

create the legacy database.

restore the database backup (/home/student/mariadb.dump).

create users according to the ticket.

insert the new manufacturers.

from your desktopX system,validate your work.

[[email protected] ~]$ lab mariadb grade

2.部署论坛

[[email protected] ~]# cd /var/www/html/

[[email protected] html]# ls

mysqladmin

[[email protected] html]# lftp 172.25.254.250

lftp 172.25.254.250:~> cd pub/

lftp 172.25.254.250:/pub> ls

-rw-r--r--    1 0        0        12486177 Aug 25  2016 Discuz_X3.2_SC_UTF8.zip

drwxr-xr-x    7 0        0              73 Jun 24  2016 Enterprise

-rwxr-xr-x    1 1000     1000     103486240 Apr 28  2015 Student_2.7.13058.exe

drwxr-xr-x   10 0        0             105 Jun 12  2016 doc

drwxr-xr-x   13 1000     1000         4096 Mar 12 01:01 docs

drwxr-xr-x    3 1000     1000         4096 Dec 01 07:54 exam

-rwxr-xr-x    1 0        0           18928 Sep 17  2016 foundation-config-7.0-1.r26059.x86_64.rpm

-rwxr-xr-x    1 0        0            1053 Nov 03 07:46 hostset

-rw-r--r--    1 0        0            1079 Sep 22  2016 hostset.sh

drwxr-xr-x    2 0        0            4096 Mar 19 00:59 iso

drwxr-xr-x    2 0        0              53 Oct 31  2015 linuxmedia

drwxr-xr-x    3 0        0              18 Mar 01  2016 media

drwxr-xr-x    2 0        0              22 Apr 26  2016 python

drwxr-xr-x    2 0        0              38 Nov 26  2015 rhel6

drwxr-xr-x    2 0        0               6 Sep 24  2015 rhel6.5

drwxr-xr-x    2 0        0               6 Nov 19  2015 rhel7.0

drwxr-xr-x    2 0        0               6 Jan 27  2016 rhel7.1

drwxr-xr-x    2 0        0               6 Jul 25  2016 rhel7.2

drwxr-xr-x    2 0        0            4096 Nov 13 01:44 shellexample

drwxr-xr-x    4 0        0            4096 Apr 22  2016 software

-rw-r--r--    1 0        0             397 Aug 25  2016 webapp.wsgi

-rwxr-xr-x    1 0        0             117 Sep 24  2015 x11vnc

-rw-r--r--    1 0        0              85 Sep 13  2016 yum.repo

-rw-r--r--    1 0        0             252 Nov 17 09:15 部署论坛

lftp 172.25.254.250:/pub> get Discuz_X3.2_SC_UTF8.zip

12486177 bytes transferred

lftp 172.25.254.250:/pub> quit

[[email protected] html]# ls

Discuz_X3.2_SC_UTF8.zip  mysqladmin

[[email protected] html]# unzip Discuz_X3.2_SC_UTF8.zip

[[email protected] html]# ls

Discuz_X3.2_SC_UTF8.zip  mysqladmin  readme  upload  utility

[[email protected] html]# cd readme/

[[email protected] readme]# ls

changelog.txt  convert.txt  license.txt  readme.txt  upgrade.txt

[[email protected] readme]# less readme.txt

[[email protected] readme]#

[[email protected] readme]# cd ..

[[email protected] html]# chmod 777 upload -R

[[email protected] html]# geten

getenforce  getent

[[email protected] html]# geten

getenforce  getent

[[email protected] html]# getenforce

Enforcing

[[email protected] html]# setenforce 0

[[email protected] html]# getenforce

Permissive

[[email protected] html]# readme.txt

第一单元  IPv6 网络的管理

一、IPv6 简介

1.Internet Protocol Version 6

2.IPv6 是 IETF (和互联网工程任务组)设计的用与替代现行版本 IP 协议的下一代 IP 协议。

3.IPv6 采用 128 位 2 进制数码表示

二、IPv6 示意图

三、IPv6 表示方式

1.为方便操作, ipv6 被换算成 8x16 进制的一串数字

– 2000:0000:0000:0000:0000:0000:0000:0001

– 2000:0:0:0:0:0:0:1

2.任意位数的 0 可以用 :: 来表示

– 2000:0000:0000:0000:0000:0000:0000:0001

– 2000::1

四、检测 IPv6 网络的工具

1.ping6 2001:db8:0:1::1

2.tracepath6 2001:db8:0:2::451

3.netstat -46n

– n 不作解析

– t tcp 协议

– u udp 协议

– L 状态位 listen 的端口

– a 所有端口

– p 显示进程

五、IPv6 的命令设定

#nmcli connection add con-name eth0 ifname eth0 type ethernet ip6 2014::1 gw6 2014::5

– ip addr show

– ip -6 route

六、IPv6 的文件设定

1.vim /etc/sysconfig/network-scripts/ifcfg-eth0

– IPV6_AUTOCONF=no

– IPV6INIT=yes

– IPV6ADDR=2014::1/64

– IPV6_DEFAULTGW=2014::5

2.示例:

[[email protected] html]# cd /etc/sysconfig/

[[email protected] sysconfig]# cd network-scripts/

[[email protected] network-scripts]# ls

ifcfg-desktop  ifdown-ppp       ifup-eth     ifup-sit

ifcfg-lo       ifdown-routes    ifup-ippp    ifup-Team

ifdown         ifdown-sit       ifup-ipv6    ifup-TeamPort

ifdown-bnep    ifdown-Team      ifup-isdn    ifup-tunnel

ifdown-eth     ifdown-TeamPort  ifup-plip    ifup-wireless

ifdown-ippp    ifdown-tunnel    ifup-plusb   init.ipv6-global

ifdown-ipv6    ifup             ifup-post    network-functions

ifdown-isdn    ifup-aliases     ifup-ppp     network-functions-ipv6

ifdown-post    ifup-bnep        ifup-routes

[[email protected] network-scripts]# vim ifcfg-eth0

[[email protected] network-scripts]# cat ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

IPV6_AUTOCONF=no

IPV6INIT=yes

IPV6ADDR=2017::42

[[email protected] network-scripts]# cd /root/Desktop/

[[email protected] Desktop]# systemctl restart network

[[email protected] Desktop]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet6 2017::42  prefixlen 64  scopeid 0x0<global>

inet6 fe80::5054:ff:fe00:2a0a  prefixlen 64  scopeid 0x20<link>

ether 52:54:00:00:2a:0a  txqueuelen 1000  (Ethernet)

RX packets 33402  bytes 291865260 (278.3 MiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 25440  bytes 2963215 (2.8 MiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

inet 127.0.0.1  netmask 255.0.0.0

inet6 ::1  prefixlen 128  scopeid 0x10<host>

loop  txqueuelen 0  (Local Loopback)

RX packets 7209  bytes 3822950 (3.6 MiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 7209  bytes 3822950 (3.6 MiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

七、参数对比

1.ipv6.method manual <-->IPV6_AUTOCONF=no

2.ipv6.method auto<-->IPV6_AUTOCONF=yes

3.ipv6.method dhcp<-->IPV6_AUTOCONF=no DHCPV6C=yes

4.ipv6.addresses<-->IPV6ADDR=

5.ipv6.dns<-->DNS0=

6.ipv6.ignore-auto-dns <-->IPV6_PEERDNS=no – ipv6.ignore-auto-dns ture

时间: 2024-05-24 10:34:21

Linux云自动化运维第十六课的相关文章

Linux云自动化运维第十九课

第十一单元 Bash Scripts 一.Bash脚本基础 1.BASH = GNU Bourne-Again Shell,BASH是GNU组织开发和推广的一个项目. 2.Bash脚本类似批处理,简单来讲就是把许多的指令集合在一起,并提供循环.条件.判断等重要功能,语法简单实用,用以编写程序,大大简化管理员的操作,并可以完成图形工具所无法实现的功能. 3.如何创建新shell脚本? 1)创建包含bash命令的文本文件.文件的第一行应为: #!/bin/bash 2)使文件可执行(使用chmod

Linux云自动化运维第十四课

第三单元 高速缓存 DNS 一.DNS 总揽 1.权威名称服务器:存储并提供某区域 ( 整个 DNS 域或 DNS 域的一部分 ) 的实际数据.权威名称服务器的类型包括 1)Master : 包含原始区域数据.有时称作 " 主要 " 名称服务器 2)Slave : 备份服务器 , 通过区域传送从 Master 服务器获得的区域数据的副本.有时称作 " 次要 " 名称服务器 2.非权威 / 递归名称服务器:客户端通过其查找来自权威名称服务器的数据.递归名称服务器的类型

Linux云自动化运维第二十课

第五单元 iSCSI远程块存储 一.iSCSI概念 iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令.iSCSI限定名称用于确定发起端和目 标,并采用iqn.yyyy-mm.{reverse domain}:label的格式.默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文. 1.iSCSI发起端:需要访问原始SAN存储的客户端. 2.iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或"目标门

Linux云自动化运维第四课

Linux云自动化运维第四课 一.vim 1.vim光标移动 1)在命令模式下 :数字  ###移动到指定的行 G  ###文件最后一行 gg  ###文件第一行 2)在插入模式下 i  ###光标所在位置插入 I  ###光标所在行行首 a  ###光标所在字符的下一个位置 A  ###光标所在行行尾 o  ###光标所在行下一行 O  ###光标所在行上一行 s  ###删除光标所在字符插入 S  ###删除光标所在行插入 2.vim的退出模式 :q  ###当用vim打开文件但没有对字符作

Linux云自动化运维第二十一课

第二单元 高级网络配置 一.网络桥接 网络桥接用网络桥实现共享上网主机和客户机除了利用软件外,还可以用系统自带的网络桥建立连接用双网卡的机器做主机 二.网络桥接的配置 1.vim /etc/sysconfig/network-scripts/ifcfg-eth0 - BRIDGE=br0 2.vim /etc/sysconfig/network-scripts/ifcfg-br0 – TYPE=Bridge 3.示例: [[email protected] Desktop]# vim /etc/

Linux云自动化运维第九课

第一单元 自动安装RED HAT ENTERPRISE LINUX 一.Kickstart 概述 1.使用kickstart,系统管理员可以创建一个包含安装期间所有常见问题的答案的文件,以自动安装Red Hat Enterprise Linux 2.Kickstart类似于Oracle solaris中的Jumpstart或Microsoft Windows的无人值守安装 二.Kickstart制作工具安装 1.软件包 #system-config-kickstart 2.安装 #yum ins

linux云自动化运维基础知识14(设备挂载)

####1.设备访问####1.设备识别/dev/xdxn        ##硬盘设备/dev/sda1/dev/cdrom        ##光驱/dev/mapper/*        ##虚拟设备 2.设备的使用##<设备的发现>##fdisk -l        ##查看真实存在的设备cat /proc/partitions    ##系统能够识别的设备blkid            ##系统能够挂载使用的设备iddf            ##查看设备被系统使用的情况 ##<

linux云自动化运维基础知识7(进程)

####1.进程定义####进程就是cpu未完成的工作 ####2.ps命令####ps    a    ##关于当前环境的所有进程    x| -A    ##所有进程    f    ##显示进程从属关系    e    ##显示进程调用环境工具的详细信息    l    ##长列表显示进程的详细信息    u    ##显示进程的用户信息    -a    ##显示shell前台运行命令的进程,但不保函shell本身    ps ax -o %cpu,%mem,user,group,com

Linux云自动化运维第二课

一.Linux系统结构 1.Linux是一个倒树结构.Linux中所有的东西都是文件.这些文件都在系统的顶级目录中"/","/"是根目录."/"目录以下为二级目录,这些目录都是系统装机时系统自动建立的. 2.二级目录的作用: /bin ###二进制可执行文件,也就是系统命令.eg:删除/bin中的date文件,命令行输入date,会显示bash:date:command not found... /sbin ###系统管理命令存放位置 /boot