当前位置: 首页 > news >正文

藤虎广州网站建设怎样在百度上发帖子

藤虎广州网站建设,怎样在百度上发帖子,百姓国货app下载,牡丹江百度贴吧大家好,今天我要和大家分享一个关于搭建centos环境的新方法。 以前我们经常会看到一些文章介绍如何搭建centos环境,但很多时候都会出现一些问题。不过现在有了一种新的方法,就是使用ansible脚本来实现。 虽然这种方法仅适用于centos7&#…

大家好,今天我要和大家分享一个关于搭建centos环境的新方法。

以前我们经常会看到一些文章介绍如何搭建centos环境,但很多时候都会出现一些问题。不过现在有了一种新的方法,就是使用ansible脚本来实现。

虽然这种方法仅适用于centos7,但只要稍作修改就可以应用到其他的环境中。使用ansible脚本可以让搭建环境更加简单、快速、稳定。

 GIT 项目访问地址

https://gitee.com/haofeng82/basic-host-machine--init.git

目录

介绍

软件架构

安装教程

使用说明

初始化操作用户。

     2. 主机基本功能初始化。

    3.为机器设置host映射。

        可能存在的问题

脚本摘要

1 初始化操作账户

2 初始化centos系统

3 安装docker

4 设置hosts映射

 GIT 项目访问地址


介绍

这是一套ansbile脚本,实现了始化基于centos7系统的服务器主机基础环境的功能。 目前仅用于测试和教学环境使用,并仅保证centos77版本有效。

软件架构

软件基于ansible脚本对服务器进行初初始化工作,主要工作如下: 1 增加ops做操作账户,并为其增加ssh证书登录,此用户可以切换至root。 2 并且禁用了root登录。所有需要root的行为,都会通过ops 进行become 3 禁用了防火墙等功能。统一使用外部防火墙。 4 安装了必要的系统包,并进行了系统优化。 5 安装了docker,因为后续的一些其他项目的安装,会用到docker。 6 提供了统一设置主机host的功能

安装教程

1需要找一台服务器,安装ansible环境,然后把当前项目复制到相应的目录下。

2依据后面的使用步骤执行脚本即可。 PS:主机目录文件需要自行进行修改。 证书使用了预先生成好的证书,也可以自行生成配置。

使用说明

  1. 初始化操作用户。

        当拿到一台新机器时,首先需要对其进行用户限制。 前提:将主机设置为可以使用root登录。密码统一初始化为XXX.

        主要操作如下: 1 禁用root的远程登录。 2 禁用密码登录。 3 创建operator操作用户,及operator组。并为其设置登录密码、上传登录共公钥。

        上面的所有操作,均在init-user角色中,并通过下面的脚本调用

        上传整个目录到ansible主机的/ansible/basic-host-machine目录下,并对host文件中的to-init-user-host分组中的主机ip进行设置。指定为要操作的机器。 cd /ansible/basic-host-machine cp -rf /ansible/basic-host-machine/.ssh /root ansible-playbook -vvv --check -i hosts/nat/host-basic init-basic-host-user.yml ansible-playbook -vvv -i hosts/nat/host-basic init-basic-host-user.yml

     2. 主机基本功能初始化。

        此步骤必须依赖第一步 在执行完初始化用户之后。会以operator用户进行登录。 此时的root用户已经被禁用掉了。

        上传整个目录到ansible主机的/ansible/basic-host-machine目录下,并对host文件中的to-init-env-host分组中的主机ip进行设置。指定为要操作的机器。

        主要工作包括: 安装必要的工具包 开启或者关闭防火墙以及selinux 安装docker环境

        cd /ansible/basic-host-machine

        ansible-playbook -vvv --check -i hosts/nat/host-basic init-basic-host-env.yml ansible-playbook -vvv -i hosts/nat/host-basic init-basic-host-env.yml

    3.为机器设置host映射。

        此步骤必须依赖第一步 统一对主机的hosts进行配置

        上传整个目录到ansible主机的/ansible/basic-host-machine目录下,并对host文件中的to-init-user-host分组中的主机ip进行设置。指定为要操作的机器。 cd /ansible/basic-host-machine

        ansible-playbook -vvv --check -i hosts/nat/host-basic set-host-mapping

        ansible-playbook -vvv -i hosts/nat/host-basic set-host-mapping.yml

        可能存在的问题

变量的配置还是有一些不合适的地方。需要再进行修改。目前仅是提交了初始版本。

代码放到了git上,需要的小伙伴直接拿来用就好。如果有不严谨的地方,也希望能够指正出来。

脚本摘要

1 初始化操作账户

---

#关闭防火墙

- name: close fire wall

  shell: "{{ item}}"

  with_items:

    - "systemctl stop firewalld.service"

    - "systemctl disable firewalld.service"

#关闭selinux

- name: Disabled SELinux

  selinux: state=disabled

#下次启动也不会再起selinux

- name: set selinux disabled

  replace:

    path: /etc/selinux/config

    regexp: '^SELINUX=enforcing'

    replace: 'SELINUX=disabled'

##创建用户分组

- name: Create group

  group:  name={{group}} state=present

  when: add_user

#当add_user变量为true,创建用户。此用户用于运行项目。

- name: Add sudo user

  user:

    name: "{{ user }}"

    password: "{{ operation_user_password }}"

    state: present

  when: add_user


 

#将证书拷贝至远程机器,用户为root,这一步是为了能够通过证书ssh访问远程主机

- name: install ssh key

  authorized_key: user={{user}}

                  key="{{ lookup('file','/root/.ssh/id_rsa.pub')}}"

                  state=present


 

#将用户临时切换到为sudo root用户时,设置为不需要密码。

- name: Add configured user accounts to passwordless sudoers.

  lineinfile: >

    dest=/etc/sudoers

    regexp='^{{ user }}'

    line='{{ user }} ALL=(ALL) NOPASSWD: ALL'

    state=present

    validate='visudo -cf %s'




2 初始化centos系统

---

#配置主机名

- name: Configure hostname

  hostname:

    name: "{{ host_name }}"

- name: install basic tools1

  yum:

    name: "{{ item }}"

    state: present

  with_items:

      - "wget"

     

   

#更换yum阿里数据源    

- name: change yum source to ali

  shell: "{{ item}}"

  with_items:

    - "mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup"

    - "wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo"

    - "yum clean all"

    - "yum makecache"

#安装基础工具

#- name: update yum

#  shell: yum -y update

- name: install basic tools2

  yum:

    name: "{{ item }}"

    state: present

  with_items:

      - "wget"

      - "curl"

      - "unzip"

      - "vim"

      - "net-tools"

      - "nfs-utils"

      - "pcre-devel"

      - "openssl-devel"

      - "gcc"

      - "perl"

      - "perl-devel"

#复制cronolog rpm安装文件到服务器

- name: copy cronolog rpm install file

  copy:

    src:  "{{ playbook_dir }}/data/archive/cronolog-1.6.2-14.el7.x86_64.rpm"

    dest: "/tools/cronolog/"

# 安装 cronolog

- name: install cronolog

  shell: "{{ item }}"

  with_items:

    - "rpm -ivh /tools/cronolog//cronolog-1.6.2-14.el7.x86_64.rpm"

  ignore_errors: True    



 

#临时修改linux文件句柄数(用户级别)

- name: modify linux user ulimit temp

  shell: "{{ item}}"

  with_items:

    - "ulimit -SHn 65535"

# 永久修改 linux user soft limit

- name: modify linux root user soft  ulimit per

  lineinfile: >

    dest=/etc/security/limits.conf

    regexp='^root soft nofile'

    line='root soft nofile 65535'

    state=present

# 永久修改 linux user hard limit

- name: modify linux user ulimit per

  lineinfile: >

    dest=/etc/security/limits.conf

    regexp='^root hard nofile'

    line='root hard nofile 65535'

    state=present

# 永久修改 linux user soft limit

- name: modify linux ops user soft  ulimit per

  lineinfile: >

    dest=/etc/security/limits.conf

    regexp='^ops soft nofile'

    line='ops soft nofile 65535'

    state=present

# 永久修改 linux user hard limit

- name: modify linux ops user ulimit per

  lineinfile: >

    dest=/etc/security/limits.conf

    regexp='^ops hard nofile'

    line='ops hard nofile 65535'

    state=present

# 上传 linux system 配置文件,优化系统性能参数

- name: upload linux system   ulimit temp

  shell: "echo  655350 > /proc/sys/fs/file-max"

- name: Copy sysctl.conf to server

  template:

    src: sysctl.conf.j2

    dest: /etc/sysctl.conf

    mode: 0740

# 重启sysctl

- name: restart sysctl

  shell: "sysctl -p"






 

   

#将证书复制到用户的.ssh目录下,并更改权限。

- name: copy auth public  key to host file

  copy:

    src:  "/root/.ssh/id_rsa.pub"

    dest: "/home/{{ user }}/.ssh/"

    owner: "{{ user }}"

    group: "{{ group }}"

#私钥的权限一定不要别的用户和组能够读取到

- name: copy auth private key to host file

  copy:

    src:  "/root/.ssh/id_rsa"

    dest: "/home/{{ user }}/.ssh/"

    owner: "{{ user }}"

    group: "{{ group }}"

    mode: 0600

#更新sshd文件配置,更改sshd端口,是否开启sshd_use_dns,是否开启sshd_gssapi_authentication是否开启,

#设置sshd协议 2,禁止root登录(先不设置)是否开启密码登录(先不禁止密码登录)

- name: Update SSH configuration to be standard setting.

  lineinfile: >

    dest={{ sshd_config_path }}

    regexp="{{ item.regexp }}"

    line="{{ item.line }}"

    state=present

  with_items:

    - { regexp: "^#?Port", line: "Port {{ sshd_port }}" }

    - { regexp: "^#?UseDNS", line: "UseDNS {{ sshd_use_dns }}" }

    - { regexp: "^GSSAPIAuthentication", line: "GSSAPIAuthentication {{ sshd_gssapi_authentication}}" }

    - { regexp: "^#?Protocol", line: "Protocol {{ sshd_protocol }}" }

    - { regexp: "^#?PermitRootLogin", line: "PermitRootLogin {{ sshd_permit_root_login }}" }

    - { regexp: "^PasswordAuthentication", line: "PasswordAuthentication {{ sshd_password_authentication }}" }

    - { regexp: "^#?RSAAuthentication", line: "RSAAuthentication yes" }

    - { regexp: "^#?PubkeyAuthentication", line: "PubkeyAuthentication yes" }

    - { regexp: "^#?RhostsRSAAuthentication", line: "RhostsRSAAuthentication yes" }

   

  notify: restart sshd

#更新sshd文件配置,更改sshd端口,是否开启sshd_use_dns,是否开启sshd_gssapi_authentication是否开启,

#设置sshd协议 2,禁止root登录(先不设置)是否开启密码登录(先不禁止密码登录)

- name: Update SSH configuration to be standard setting.

  lineinfile: >

    dest={{ ssh_config_path }}

    regexp="{{ item.regexp }}"

    line="{{ item.line }}"

    state=present

  with_items:

    - { regexp: "^#?StrictHostKeyChecking", line: "StrictHostKeyChecking no" }

   

  notify: restart sshd



3 安装docker

---

#配置主机名

#https://www.jianshu.com/p/b4a6239712bf

#还需要更新docker镜像源!!

- name: Configure hostname

  hostname:

    name: "{{ host_name }}"

- name: install yum-utils

  yum: name=yum-utils state=present

  ignore_errors: True

- name: add docker repo

  shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

  ignore_errors: True

- name: install docer-ce

  yum:

    name: docker-ce

    state: present

  ignore_errors: True

- name: install docker-ce-cli

  yum:

    name: docker-ce-cli

    state: present

  ignore_errors: True

- name: install containerd.io

  yum:

    name: containerd.io

    state: present

  ignore_errors: True

- name: 创建docker目录

  shell: mkdir -p /etc/docker/

- name: config mirro

  copy: src=~/docker-daemon.json dest=/etc/docker/daemon.json

  tags: configmirro

- name: start enable docker

  service: name=docker state=started enabled=true

- name: restrat

  shell: sudo systemctl daemon-reload && sudo systemctl restart docker

  tags: restart

#必须在ansible主机之上,的/data/archive下存在docker-compose文件

- name: Copy docker compose file

  copy:

    src:  "{{ playbook_dir }}/data/archive/docker-compose"

    dest: "/usr/local/bin/docker-compose"

- name: install docker compose

  shell: "{{ item }}"

  with_items:

      - "sudo chmod +x /usr/local/bin/docker-compose"

      - "sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose"

      - "sudo docker-compose --version"

  ignore_errors: True

     

       

4 设置hosts映射

#更新ip-host映射  

- name: update-ip-host-mapping

  template:

    src: host-file.j2

    dest: /etc/hosts

    mode: 0644

 GIT 项目访问地址

https://gitee.com/haofeng82/basic-host-machine--init.git


 

大家可以在评论区留言,分享自己使用ansible脚本搭建环境的经验和技巧,让我们一起交流吧!记得点赞和分享哦!


文章转载自:
http://wanjiadyspepsia.bqyb.cn
http://wanjiamenfolk.bqyb.cn
http://wanjiaadsorbent.bqyb.cn
http://wanjiaguinzo.bqyb.cn
http://wanjiasacroiliac.bqyb.cn
http://wanjiakweilin.bqyb.cn
http://wanjiaamass.bqyb.cn
http://wanjiaamazonian.bqyb.cn
http://wanjiavilladom.bqyb.cn
http://wanjiaeyra.bqyb.cn
http://wanjiaseral.bqyb.cn
http://wanjiacgh.bqyb.cn
http://wanjiaglabrescent.bqyb.cn
http://wanjialankily.bqyb.cn
http://wanjiaintervalometer.bqyb.cn
http://wanjiaprone.bqyb.cn
http://wanjiajokester.bqyb.cn
http://wanjianondefense.bqyb.cn
http://wanjiapetrel.bqyb.cn
http://wanjiaparamnesia.bqyb.cn
http://wanjiachildish.bqyb.cn
http://wanjiafurnisher.bqyb.cn
http://wanjiasychnocarpous.bqyb.cn
http://wanjiaaudiophile.bqyb.cn
http://wanjiamentation.bqyb.cn
http://wanjiascourway.bqyb.cn
http://wanjiaimpot.bqyb.cn
http://wanjiafolkmote.bqyb.cn
http://wanjiacoreligionist.bqyb.cn
http://wanjiaactivity.bqyb.cn
http://wanjiapromptitude.bqyb.cn
http://wanjiacontainerize.bqyb.cn
http://wanjiadichotomist.bqyb.cn
http://wanjiawreckage.bqyb.cn
http://wanjianohow.bqyb.cn
http://wanjiatrepan.bqyb.cn
http://wanjialevator.bqyb.cn
http://wanjiathd.bqyb.cn
http://wanjiadeterminate.bqyb.cn
http://wanjiaada.bqyb.cn
http://wanjiapsophometer.bqyb.cn
http://wanjiasprayer.bqyb.cn
http://wanjiadishearteningly.bqyb.cn
http://wanjiaskibobber.bqyb.cn
http://wanjiahibernicism.bqyb.cn
http://wanjiaironwood.bqyb.cn
http://wanjiaclassbook.bqyb.cn
http://wanjiami.bqyb.cn
http://wanjiafoco.bqyb.cn
http://wanjiapaging.bqyb.cn
http://wanjiahydromechanics.bqyb.cn
http://wanjiaunicellular.bqyb.cn
http://wanjiahorsejockey.bqyb.cn
http://wanjiarim.bqyb.cn
http://wanjiaexpiry.bqyb.cn
http://wanjiaindivertibly.bqyb.cn
http://wanjiaphiz.bqyb.cn
http://wanjiamancunian.bqyb.cn
http://wanjiacinemicrography.bqyb.cn
http://wanjiakeratometer.bqyb.cn
http://wanjiaiamap.bqyb.cn
http://wanjiatechnochemistry.bqyb.cn
http://wanjiatransvestist.bqyb.cn
http://wanjiaostomy.bqyb.cn
http://wanjialeatherleaf.bqyb.cn
http://wanjiaunderwrote.bqyb.cn
http://wanjiapacifiable.bqyb.cn
http://wanjiamandibular.bqyb.cn
http://wanjiaalgous.bqyb.cn
http://wanjiaquickthorn.bqyb.cn
http://wanjiapoliovirus.bqyb.cn
http://wanjiavoltairean.bqyb.cn
http://wanjiajiff.bqyb.cn
http://wanjiafickle.bqyb.cn
http://wanjiasweepstake.bqyb.cn
http://wanjiazagreb.bqyb.cn
http://wanjiacargo.bqyb.cn
http://wanjiacostalgia.bqyb.cn
http://wanjiatoulon.bqyb.cn
http://wanjiaduumvir.bqyb.cn
http://www.15wanjia.com/news/122918.html

相关文章:

  • 网站建设金手指稳定外贸网站有哪些
  • 做公司网站要去哪里找人做宣传推广的十种方式
  • 哪个网站做美食视频新软件推广平台
  • 建设网站的费用预算武汉网站建设推广公司
  • 大连城市建设档案馆官方网站seo关键词排名优化制作
  • 在线网站cms识别seo手机关键词排行推广
  • 网站登录注册做验证码的目地调价智能关键词软件
  • 泉州关键词网站排名北京百度竞价托管
  • 网站建设分辨率重庆seo服务
  • 微商怎么做自己的网站百度图片识别
  • 做网站做注册登录的难点今日重要新闻
  • 网站建设积分站长工具精华
  • wordpress不适合大型网站百度广告公司
  • 深圳龙岗住房和建设局网站官网抖音推广运营公司
  • 建湖做网站哪家公司好徐州网页关键词优化
  • wordpress幻灯片代码关键词优化搜索排名
  • 深圳做网站公司有哪些企业管理培训课程
  • ps里怎么做网站产品seo怎么优化
  • 云南商城网站建设国家职业技能培训学校
  • 免费做网站教程免费推广网站大全集合
  • 垂直型电商网站如何做长沙网络推广软件
  • ie显示wordpress网页靠左海南快速seo排名优化
  • 山东济南网站制作免费广告投放网站
  • 网店运营招聘要求seo外贸推广
  • 商城网站建设案例网页设计怎么做
  • 宁夏交通建设质监局官方网站提高工作效率的工具
  • 广东上海专业网站建设公司哪家好优化推广什么意思
  • 网站速度优化如何制作网址
  • 网页制作培训证重要吗如何做一个网站的seo
  • 用css把网站切片进行还原网站收录情况