files:⽤来存放由copy模块或script模块调⽤的⽂件。 tasks:⾄少有⼀个main.yml⽂件,定义各tasks。 handlers:有⼀个main.yml⽂件,定义各handlers。 templates:⽤来存放jinjia2模板。 vars:有⼀个main.yml⽂件,定义变量。 meta:有⼀个main.yml⽂件,定义此⻆⾊的特殊设定及其依赖关系。
注意: 在每个⻆⾊的⽬录中分别创建files, tasks,handlers,templates,vars和meta⽬录,⽤不到的⽬录可以创建为空⽬录。
[root@kong ~]# cd /etc/ansible/roles [root@kong roles]# ls [root@kong roles]# mkdir nginx [root@kong roles]# ls nginx [root@kong roles]# cd nginx [root@kong nginx]# mkdir files [root@kong nginx]# mkdir tasks [root@kong nginx]# mkdir handlers [root@kong nginx]# mkdir templates [root@kong nginx]# mkdir vars [root@kong nginx]# mkdir meta [root@kong nginx]# tree . ├── files ├── handlers ├── meta ├── tasks ├── templates └── vars [root@kong nginx]# touch handlers/mian.yml [root@kong nginx]# touch tasks/mian.yml [root@kong nginx]# touch vars/mian.yml [root@kong nginx]# tree . ├── files ├── handlers │ └── mian.yml ├── meta │ └── mian.yml ├── tasks │ └── mian.yml ├── templates └── vars └── mian.yml
[root@1 roles]# vim /etc/ansible/playbook/test002.yml --- - hosts: s remote_user: root roles: - httpd - mysql [root@1 roles]# cd [root@1 ~]# vim /etc/ansible/roles/mysql/tasks/main.yml --- - name: 卸载mysql yum: name=mysql state=absent - name: 安装mysql yum: name=mysql state=present [root@1 ~]# vim /etc/ansible/roles/httpd/tasks/main.yml --- - name: 卸载httpd yum: name=httpd state=absent - name: 安装httpd yum: name=httpd state=present - name: 启动httpd service: name=httpd state=started enabled=yes [root@1 ~]# ansible-playbook /etc/ansible/playbook/test002.yml
# 主从配置 [root@mysql57 ~]# firewall-cmd --permanent --add-port=3306/tcp success [root@mysql57 ~]# firewall-cmd --reload success [root@mysql57 ~]# firewall-cmd --list-ports 3306/tcp 96 yum -y install lrzsz 66 tar -zxf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 67 cp -r mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql 68 mkdir /usr/local/mysql/mysql-files 69 useradd -r -s /sbin/nologin mysql 70 chown mysql:mysql /usr/local/mysql/mysql-files/ 71 chmod 750 /usr/local/mysql/mysql-files/ 72 rm -rf /etc/my.cnf # 主配置 73 /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql 74 /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data 76 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql57 77 service mysql57 start 79 sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile 80 source /etc/profile vim /usr/local/mysql/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock activate_all_roles_on_login=on port=3306 log-error=/usr/local/mysql/data/db01-master.err log-bin=/usr/local/mysql/data/binlog server-id=10 character_set_server=utf8mb4 service mysql57 restart 81 mysql -p'zc0fLfoM%SDP' mysql> alter user 'root'@'localhost' identified by '123'; Query OK, 0 rows affected (0.15 sec) //修改root密码 mysql> create user 'slave0'@'%' identified by '123'; Query OK, 0 rows affected (0.03 sec) //创建slave用户 mysql> grant replication slave on *.* to 'slave0'@'%'; Query OK, 0 rows affected (0.02 sec) //授予replication slave权限 mysql> flush privileges; //重新加载权限表 Query OK, 0 rows affected (0.00 sec) mysql> flush tables with read lock; //刷新所有表并施加一个全局读锁 Query OK, 0 rows affected (0.01 sec) mysql> show master status; //查看主服务器当前二进制日志的状态信息 +---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +---------------+----------+--------------+------------------+-------------------+ | binlog.000003 | 1178 | | | | +---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) rm -rf /usr/local/mysql/data/auto.cnf rsync -av /usr/local/mysql/data [email protected]:/usr/local/mysql/ rsync -av /usr/local/mysql/data [email protected]:/usr/local/mysql/ # 从配置 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql57 service mysql57 start sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile source /etc/profile vim /usr/local/mysql/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/mysql.sock activate_all_roles_on_login=on port=3310 log-error=/usr/local/mysql/data/db01-slave.err relay-log=/usr/local/mysql/data/relaylog server-id=11 character_set_server=utf8mb4 service mysql57 restart mysql -p'123' mysql> change master to -> master_host='10.0.0.57', -> master_user='slave0', -> master_password='123', -> master_port=3306, -> master_log_file='binlog.000003', -> master_log_pos=1178; Query OK, 0 rows affected, 9 warnings (0.02 sec) mysql> start slave; Query OK, 0 rows affected, 1 warning (0.03 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for source to send event Master_Host: 10.0.0.57 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000003 Read_Master_Log_Pos: 1178 Relay_Log_File: relaylog.000002 Relay_Log_Pos: 323 Relay_Master_Log_File: binlog.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes
[root@mysql57 ~]# mysql -p'123' mysql> create database if not exists eleme charset utf8mb4; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | eleme | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec)
mysql> create table eleme.t_user( -> id int not null primary key, -> name varchar(32) not null, -> username varchar(32) not null, -> password varchar(32) not null, -> remark varchar(32) not null -> ); Query OK, 0 rows affected (0.01 sec) mysql> desc eleme.t_user; +----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(32) | NO | | NULL | | | username | varchar(32) | NO | | NULL | | | password | varchar(32) | NO | | NULL | | | remark | varchar(32) | NO | | NULL | | +----------+--------------+------+-----+---------+-------+ 5 rows in set (0.02 sec)
mysql> insert into eleme.t_user values(1,'超级管理员','admin','admin','超级管理员'),(2,'普通用户','guest','guest','普通用户'); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from eleme.t_user; +----+-----------------+----------+----------+-----------------+ | id | name | username | password | remark | +----+-----------------+----------+----------+-----------------+ | 1 | 超级管理员 | admin | admin | 超级管理员 | | 2 | 普通用户 | guest | guest | 普通用户 | +----+-----------------+----------+----------+-----------------+ 2 rows in set (0.00 sec)
[root@mycat ~]# systemctl stop firewalld [root@mycat ~]# systemctl disable firewalld [root@mycat ~]# ls anaconda-ks.cfg Mycat-server-1.6.5-release-20180122220033-linux.tar.gz jdk-8u192-linux-x64.tar.gz v [root@mycat ~]# tar -xf jdk-8u192-linux-x64.tar.gz [root@mycat ~]# tar -xf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz [root@mycat ~]# cp -r jdk1.8.0_192/ /usr/local/jdk [root@mycat ~]# cp -r mycat/ /usr/local/ [root@mycat ~]# ls /usr/local/jdk/ bin lib src.zip COPYRIGHT LICENSE THIRDPARTYLICENSEREADME-JAVAFX.txt include man THIRDPARTYLICENSEREADME.txt javafx-src.zip README.html jre release [root@mycat ~]# sed -i '$aexport JAVA_HOME=/usr/local/jdk' /etc/profile [root@mycat ~]# source /etc/profile [root@mycat ~]# $JAVA_HOME -bash: /usr/local/jdk: 是一个目录 [root@mycat ~]# sed -i '$aexport PATH=$PATH:$JAVA_HOME/bin' /etc/profile [root@mycat ~]# source /etc/profile [root@mycat ~]# $PATH -bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk/bin: 没有那个文件或目录 [root@mycat ~]# javac -version javac 1.8.0_192 [root@mycat ~]# ls /usr/local/mycat/ bin catlet conf lib logs version.txt [root@mycat ~]# ll /usr/local/mycat/ 总用量 12 drwxr-xr-x. 2 root root 190 8月 15 15:19 bin drwxr-xr-x. 2 root root 6 8月 15 15:19 catlet drwxr-xr-x. 4 root root 4096 8月 15 15:19 conf drwxr-xr-x. 2 root root 4096 8月 15 15:19 lib drwxr-xr-x. 2 root root 6 8月 15 15:19 logs -rwxr-xr-x. 1 root root 219 8月 15 15:19 version.txt [root@mycat ~]# ls /usr/local/mycat/bin/mycat [root@mycat ~]# vim /usr/local/mycat/conf/server.xml[root@mycat ~]# vim /usr/local/mycat/conf/schema.xml li eleme
[root@mycat ~]# /usr/local/mycat/bin/mycat start Starting Mycat-server... [root@mycat ~]# netstat -lnput | grep 8066 tcp6 0 0 :::8066 :::* LISTEN 1336/java