Commit 699c3ff5 authored by 张伟坤's avatar 张伟坤
Browse files

迁移ydd-redis代码

No related merge requests found
Showing with 650 additions and 91 deletions
+650 -91
# terraform-redis
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.yun.shop/ydd-idp-idcos/terraform-redis.git
git branch -M master
git push -uf origin master
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.yun.shop/ydd-idp-idcos/terraform-redis/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
在多个云平台虚拟机安装redis(每朵云放一个目录)
\ No newline at end of file
version: 0.5
apply:
steps:
ansiblePlay:
before:
- ansible-galaxy install -r /cloudiac/workspace/code/alicloud-ecs-redis/ansible/requirements.yml
\ No newline at end of file
---
- name: install Redis
hosts: redis
remote_user: root
vars:
- redisDir: "{{install_path}}"
- clusterModel: "{{deploy_mode}}"
- servicePort: "{{service_port}}"
- redisVersion: "{{redis_version}}"
- slavePort: "{{slave_port}}"
- sentinelPort: "{{sentinel_port}}"
- softwareName: "{{software_name}} "
- userPassword: "{{user_password}}"
- softwarePath: "{{software_path}}"
- userName: "{{user_name}}"
- userGroup: "{{user_group}}"
- yumMirror: "{{yum_mirror}}"
- softwareServerIpPath: http://{{software_ip}}/{{softwarePath}}
roles:
- redis
- src: git+http://gitlab.idcos.com/iac-role/ansible-role-redis.git
name: redis
version: "master"
resource "random_string" "random_string" {
length = 8
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
}
//根据资源组名称查询资源组
data "alicloud_resource_manager_resource_groups" "rmrg" {
ids = [var.resource_group_id]
}
//根据资源组id查询vswitch
data "alicloud_vswitches" "vsws" {
vpc_id = var.vpc_id
vswitch_name = var.vswitch_name
}
data "alicloud_security_groups" "sgs" {
ids = [var.security_groups]
}
data "alicloud_ecs_key_pairs" "ekps" {
name_regex = var.key_name
}
module "instance" {
source = "git::http://gitlab.idcos.com/iac-module/terraform-alicloud-modules.git//modules/instance?ref=v0.2.2"
count = var.instance_number
zone_id = var.zone_id
instance_type = var.instance_type
hostname = var.hostname
instance_name = var.instance_name
image_id = var.image_id
vswitch_id = data.alicloud_vswitches.vsws.vswitches.0.id
security_groups = join("," , data.alicloud_security_groups.sgs.groups.*.id )
create_spot_instance = var.create_spot_instance
internet_bandwidth = var.internet_bandwidth
internet_charge_type = "PayByTraffic"
system_disk_size = 80
system_disk_category = "cloud_efficiency"
data_disks = var.data_disks
key_name = data.alicloud_ecs_key_pairs.ekps.key_pairs.0.id
tags = var.tags
resource_group_id = data.alicloud_resource_manager_resource_groups.rmrg.groups.0.id
}
// 为每个计算资源创建一个对应的 ansible_host 资源,
// 执行 ansible playbook 前会基于 ansible_host 资源自动生成 inventory 文件。
resource "ansible_host" "redis" {
count = var.instance_number
// 配置机器的 hostname,一般配置为计算资源的 public_ip (或 private_ip)
# inventory_hostname = module.vmware-tomcat.vm[count.index]
inventory_hostname = module.instance.*.instance.private_ip[count.index]
// 配置机器所属分组
groups = tolist([var.inventory])
vars = {
// 传给 ansible 的 vars,可在 playbook 文件中引用
# ansible_ssh_pass = var.ansible_ssh_pass
wait_connection_timeout = 600
redis_version = var.redis_version
deploy_mode =var.deploy_mode
service_port =var.service_port
slave_port =var.slave_port
sentinel_port =var.sentinel_port
install_path =var.install_path
software_name =var.software_name
software_ip =var.software_ip
software_path =var.software_path
user_password = random_string.random_string.result
user_name =var.user_name
user_group =var.user_group
yum_mirror =var.yum_mirror
}
}
output "instances" {
value = [
{
"home_url": format("http://%s:%s", module.instance.*.instance.private_ip[0], var.service_port),
"username": var.user_name,
"password": random_string.random_string.result,
"redis_version": var.redis_version,
"public_ip": module.instance.*.instance.public_ip,
"redis_service_port": var.service_port,
"redis_install_path": var.install_path,
"instance": module.instance
}
]
}
variable "instance_number" {
default = 1
}
variable "zone_id" {
default = "cn-beijing-c"
}
variable "instance_type" {
default = "ecs.t5-lc1m1.small"
}
variable "hostname" {
default = null
}
variable "instance_name" {
default = "ydd-redis"
}
variable "image_id" {
description = "镜像 id"
default = "centos_7_7_x64_20G_alibase_20200426.vhd"
}
variable "vpc_id" {}
variable "vswitch_name" {}
variable "security_groups" {
}
variable "create_spot_instance" {
default = false
}
variable "internet_bandwidth" {
default = 0
}
variable "data_disks" {
default = {
d0 = {
size = 30
}
d1 = {
size = 60
}
}
}
variable "key_name" {
}
variable "tags" {
type = map(string)
default = {
tagkey = "tagvalue"
}
}
variable "resource_group_id" {
}
variable "inventory" {
description = "主机组名称"
type = string
default = "redis"
}
#variable "ansible_ssh_pass" {
# description = "ansible ssh pass"
# type = string
#}
variable "deploy_mode" {
description = "部署模式"
type = string
default = "single"
}
variable "service_port" {
description = "服务端口"
type = number
default = 6379
}
variable "slave_port" {
description = "从节点端口"
type = number
default = 7001
}
variable "sentinel_port" {
description = "哨兵模式服务端口"
type = number
default = 16379
}
variable "install_path" {
description = "安装路径"
type = string
default = "/usr/local/redis"
}
variable "software_name" {
description = "介质包名称"
type = string
default = "redis-{{redis_version}}.tar.gz"
}
variable "software_ip" {
description = "介质服务器IP"
type = string
default = "10.10.0.252"
}
variable "software_path" {
description = "介质存放路径"
type = string
default = "soft/redis"
}
variable "user_name" {
description = "用户"
type = string
default = "rtpapp"
}
variable "user_group" {
description = "用户组"
type = string
default = "appgrp"
}
variable "yum_mirror" {
description = "镜像地址"
type = string
default = "https://mirrors.aliyun.com/centos/7/os/x86_64/"
}
variable "redis_version" {
description = "Redis版本"
type = string
default = "5.0.7"
}
terraform {
required_version = ">= 1.2.0"
required_providers {
ansible = {
source = "nbering/ansible"
version = "1.0.4"
}
alicloud = {
source = "aliyun/alicloud"
version = "1.163.0"
}
}
}
version: 0.5
apply:
steps:
ansiblePlay:
before:
- ansible-galaxy install -r /cloudiac/workspace/code/cloudoscas-instance-redis/ansible/requirements.yml
\ No newline at end of file
---
- name: 等待机器连接
hosts: redis
gather_facts: no
tasks:
- name: 等待连接
wait_for_connection:
sleep: 1
timeout: "{{ wait_connection_timeout }}"
- name: Setup facts
setup:
- name: 关闭firewall系统防火墙
service:
name: firewalld
state: stopped
enabled: no
when: ansible_distribution_major_version == "7"
- name: 临时关闭selinux
shell: setenforce 0
- name: 永久关闭selinux
lineinfile:
path: /etc/sysconfig/selinux
state: present
regexp: "^SELINUX="
line: "SELINUX=disabled"
- name: 清除Yum仓库
shell: rm -rf /etc/yum.repos.d/*
- name: install Redis
hosts: redis
remote_user: root
vars:
- redisDir: "{{install_path}}"
- clusterModel: "{{deploy_mode}}"
- servicePort: "{{service_port}}"
- redisVersion: "{{redis_version}}"
- slavePort: "{{slave_port}}"
- sentinelPort: "{{sentinel_port}}"
- softwareName: "{{software_name}} "
- userPassword: "{{user_password}}"
- softwarePath: "{{software_path}}"
- userName: "{{user_name}}"
- userGroup: "{{user_group}}"
- yumMirror: "{{yum_mirror}}"
- softwareServerIpPath: http://{{software_ip}}/{{softwarePath}}
roles:
- redis
- src: git+http://gitlab.idcos.com/iac-role/ansible-role-redis.git
name: redis
version: "master"
module "instance-redis" {
source = "git::http://gitlab.idcos.com/iac-module/terraform-cloudoscas-modules.git//modules/instance"
tmp_id = var.tmp_id
title = var.title
target_host_id = var.target_host_id
target_cluster_id = var.target_cluster_id
sys_name = var.sys_name
storage_src = var.storage_src
storage_dest = var.storage_dest
storage_pool = var.storage_pool
osinfo_login_account = var.osinfo_login_account
osinfo_login_password = var.osinfo_login_password
cpu_cores = var.cpu_cores
memory_size = var.memory_size
network_ip = var.network_ip
network_sys_mask = var.network_sys_mask
network_gateway = var.network_gateway
# size = var.disk_size
# target_bus = var.target_bus
# vm_disk_count = var.vm_disk_count
}
// 为每个计算资源创建一个对应的 ansible_host 资源,
// 执行 ansible playbook 前会基于 ansible_host 资源自动生成 inventory 文件。
resource "ansible_host" "redis" {
count = length(split("," , var.network_ip ))
// 配置机器的 hostname,一般配置为计算资源的 public_ip (或 private_ip)
# inventory_hostname = module.vmware-tomcat.vm[count.index]
inventory_hostname = element(split("," , var.network_ip ), count.index)
// 配置机器所属分组
groups = tolist([var.inventory])
vars = {
wait_connection_timeout = 600
ansible_user = var.osinfo_login_account
ansible_password = var.osinfo_login_password
redis_version = var.redis_version
deploy_mode =var.deploy_mode
service_port =var.service_port
slave_port =var.slave_port
sentinel_port =var.sentinel_port
install_path =var.install_path
software_name =var.software_name
software_ip =var.software_ip
software_path =var.software_path
user_password = var.user_password
user_name =var.user_name
user_group =var.user_group
yum_mirror =var.yum_mirror
}
}
\ No newline at end of file
#output "sys_name" {
# description = "主机名称"
# value = module.instance-tomcat.sys_name
#}
#
#output "network_ip" {
# description = "ip地址"
# value = module.instance-tomcat.network_ip
#}
output "instance" {
description = "主机"
value = module.instance-redis
}
\ No newline at end of file
variable "tmp_id" {
description = "模版id"
type = number
default = 113
}
variable "title" {
description = "部署虚拟机显示名称"
type = string
// default = "idc_test6"
}
variable "target_host_id" {
description = "目标主机id"
type = string
default = "4"
}
variable "target_cluster_id" {
description = "目标集群id"
type = number
default = 1
}
variable "sys_name" {
description = "主机名称"
type = string
default = "cvknode"
}
variable "storage_src" {
description = "源存储文件"
type = string
default = "Centos7-templates"
}
variable "storage_dest" {
description = "目的存储文件"
type = string
// default = "idc_test6"
}
variable "storage_pool" {
description = "目的存储池"
type = string
default = "isopool"
}
variable "osinfo_login_account" {
description = "虚拟机登陆账号"
type = string
}
variable "osinfo_login_password" {
description = "虚拟机登陆密码"
sensitive = true
type = string
}
variable "cpu_cores" {
description = "cpu 核心数"
type = number
default = 2
}
variable "memory_size" {
description = "内存大小(MB)"
type = number
default = 2048
}
variable "network_ip" {
description = "network ip"
type = string
}
variable "network_sys_mask" {
description = "network_sys_mask"
type = string
default = "255.255.0.0"
}
#variable "disk_size" {
# description = "分配存储容量"
# type = string
# default = "1028"
#}
#variable "target_bus" {
# description = "存储设备类型"
# type = string
# default = "virtio"
#}
#
#variable "vm_disk_count" {
# description = "每台虚机对应的挂载磁盘"
# type = map(any)
# default = {
# 1 = [1]
# }
#}
variable "inventory" {
description = "主机组名称"
type = string
default = "redis"
}
#variable "ansible_ssh_pass" {
# description = "ansible ssh pass"
# type = string
#}
variable "network_gateway" {
description = "gateway 默认网关"
type = string
default = "10.0.0.1"
}
variable "deploy_mode" {
description = "部署模式(single、cluster、sentinel)"
type = string
default = "single"
}
variable "service_port" {
description = "服务端口"
type = number
default = 6379
}
variable "slave_port" {
description = "从节点端口"
type = number
default = 7001
}
variable "sentinel_port" {
description = "哨兵模式服务端口"
type = number
default = 16379
}
variable "install_path" {
description = "安装路径"
type = string
default = "/usr/local/redis"
}
variable "software_name" {
description = "介质包名称"
type = string
default = "redis-{{redis_version}}.tar.gz"
}
variable "software_ip" {
description = "介质服务器IP"
type = string
default = "10.10.0.252"
}
variable "software_path" {
description = "介质存放路径"
type = string
default = "soft/redis"
}
variable "user_password" {
description = "用户密码(必填)"
sensitive = true
type = string
}
variable "user_name" {
description = "用户"
type = string
default = "rtpapp"
}
variable "user_group" {
description = "用户组"
type = string
default = "appgrp"
}
variable "yum_mirror" {
description = "本地镜像地址(必填)"
type = string
default = "http://10.10.0.252/centos/7.5/"
}
variable "redis_version" {
description = "Redis版本"
type = string
default = "5.0.7"
}
terraform {
required_providers {
cloudoscas = {
source = "store.cloudiac.org/idcos/cloudoscas"
version = "1.0.5"
}
ansible = {
source = "nbering/ansible"
version = "1.0.4"
}
}
}
version: 0.5
apply:
steps:
ansiblePlay:
before:
- ansible-galaxy install -r /cloudiac/workspace/code/tencentcloud-ecs-instance/ansible/requirements.yml
\ No newline at end of file
---
- name: install Redis
hosts: redis
remote_user: root
vars:
- redisDir: "{{install_path}}"
- clusterModel: "{{deploy_mode}}"
- servicePort: "{{service_port}}"
- redisVersion: "{{redis_version}}"
- slavePort: "{{slave_port}}"
- sentinelPort: "{{sentinel_port}}"
- softwareName: "{{software_name}} "
- userPassword: "{{user_password}}"
- softwarePath: "{{software_path}}"
- userName: "{{user_name}}"
- userGroup: "{{user_group}}"
- yumMirror: "{{yum_mirror}}"
- softwareServerIpPath: http://{{software_ip}}/{{softwarePath}}
roles:
- redis
- src: git+http://gitlab.idcos.com/iac-role/ansible-role-redis.git
name: redis
version: "master"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment