码迷,mamicode.com
首页 > 系统相关 > 详细

Linux云自动化运维第十六课

时间:2017-04-20 21:34:35      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:nmcli   name   pos   .exe   分享   技术   rhel   cti   his   

第八单元 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.示例:

[root@httpdesktop ~]# 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.

[root@httpdesktop ~]# yum install mariadb-server.x86_64 -y

[root@httpdesktop ~]# systemctl start mariadb

[root@httpdesktop ~]# 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

[root@httpdesktop ~]# netstat -antlpe | grep mysql

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

[root@httpdesktop ~]# vim /etc/my.cnf

#skip-networking=1

[root@httpdesktop ~]# systemctl restart mariadb.service

[root@httpdesktop ~]# netstat -antlpe | grep mysql

[root@httpdesktop ~]# 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

[root@httpdesktop ~]# 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!

[root@httpdesktop ~]# mysql

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

[root@httpdesktop ~]# 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

[root@httpdesktop ~]#

 

 

二、数据库基本操作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:[root@httpdesktop ~]# 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

[root@httpdesktop ~]#

[root@httpdesktop ~]# 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

[root@httpdesktop ~]#

 

三、用户和访问权限

 

1.创建用户

CREATE USER wxh@localhost identified by ‘westos‘;

CREATE USER lee@‘%‘ identified by ‘redhat‘;

2.用户授权

GRANT INSERT,UPDATE,DELETE,SELECT on mariadb.* to wxh@localhost;

GRANT SELECT on mariadb.* lee@‘%‘;

3.重载授权表

FLUSH PRIVILEGES;

4.查看用户授权

SHOW GRANTS FOR wxh@localhost;

5.撤销用户权限

REVOKE DELETE,UPDATE,INSERT on mariadb.* from wxh@localhost;

6.删除用户

DROP USER wxh@localhost;

7.示例:

[root@localhost ~]# 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 student@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SHOW GRANT FOR student@localhosy;

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 student@localhosy‘ at line 1

MariaDB [(none)]> SHOW GRANTS FOR student@localhost;

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

| Grants for student@localhost                                |

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

| 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 student@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SHOW GRANTS FOR student@localhost;

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

| Grants for student@localhost                        |

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

| 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 student@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SHOW GRANTS FOR student@localhost;

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

| Grants for student@localhost                |

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

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

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

1 row in set (0.00 sec)

 

MariaDB [(none)]> DROP USER student@localhost;

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 westos@localhost;

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

[root@localhost ~]#

[root@localhost ~]# 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

[root@localhost ~]#

 

 

四、备份与恢复

 

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.示例:

[root@localhost ~]# mysqldump -uroot -predhat --all-databases^C

[root@localhost ~]# mysqldump -uroot -predhat --all-databases --no-data^C

[root@localhost ~]# mysqldump -uroot -predhat westos^C

[root@localhost ~]# mysqldump -uroot -predhat westos>/mnt/westos.sql

[root@localhost ~]# mysql -uroot -predhat westos -e "SHOW DATABASES;"

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| westos             |

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

[root@localhost ~]# mysql -uroot -predhat westos -e "DROP DATABASE westos;"

[root@localhost ~]# mysql -uroot -predhat -e "SHOW DATABASES;"

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

[root@localhost ~]# mysqladmin -uroot -predhat create westos

[root@localhost ~]# mysql -uroot -predhat -e "SHOW DATABASES;"

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| westos             |

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

[root@localhost ~]# mysql -uroot -predhat -e "SHOW TABLES FROM westos;"

[root@localhost ~]# mysql -uroot -predhat westos</mnt/westos.sql

[root@localhost ~]# mysql -uroot -predhat -e "SHOW TABLES FROM westos;"

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

| Tables_in_westos |

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

| linux            |

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

[root@localhost ~]# mysql -uroot -predhat -e "SELECT * FROM westos.linux;"

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

| username | age  | password |

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

| user1    | 25   | 123      |

| user2    | 10   | 123      |

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

[root@localhost ~]# mysqladmin -u root -predhat password lee

[root@localhost ~]# 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

[root@localhost ~]# systemctl stop mariadb

[root@localhost ~]# mysqld_safe --skip-grant-tables &

[1] 4407

[root@localhost ~]# 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

 

[root@localhost ~]# 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

[root@localhost ~]# 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

[root@localhost ~]# kill -9 4407

[root@localhost ~]# kill -9 4562

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

[root@localhost ~]# ps aux | grep mysql

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

[root@localhost ~]# systemctl restart mariadb

[root@localhost ~]# 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

[root@localhost ~]# mysql

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

[root@localhost ~]#  

 

五、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.

[student@desktopX ~]$ lab mariadb grade

 

2.部署论坛

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# ls

mysqladmin

[root@localhost 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

[root@localhost html]# ls

Discuz_X3.2_SC_UTF8.zip  mysqladmin

[root@localhost html]# unzip Discuz_X3.2_SC_UTF8.zip

[root@localhost html]# ls

Discuz_X3.2_SC_UTF8.zip  mysqladmin  readme  upload  utility

[root@localhost html]# cd readme/

[root@localhost readme]# ls

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

[root@localhost readme]# less readme.txt

[root@localhost readme]#

[root@localhost readme]# cd ..

[root@localhost html]# chmod 777 upload -R

[root@localhost html]# geten

getenforce  getent      

[root@localhost html]# geten

getenforce  getent      

[root@localhost html]# getenforce

Enforcing

[root@localhost html]# setenforce 0

[root@localhost html]# getenforce

Permissive

[root@localhost 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.示例:

[root@localhost html]# cd /etc/sysconfig/

[root@localhost sysconfig]# cd network-scripts/

[root@localhost 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

[root@localhost network-scripts]# vim ifcfg-eth0

[root@localhost network-scripts]# cat ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

IPV6_AUTOCONF=no

IPV6INIT=yes

IPV6ADDR=2017::42

[root@localhost network-scripts]# cd /root/Desktop/

[root@localhost Desktop]# systemctl restart network

[root@localhost 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

 

Linux云自动化运维第十六课

标签:nmcli   name   pos   .exe   分享   技术   rhel   cti   his   

原文地址:http://www.cnblogs.com/Virgo-sept/p/6740423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!