Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions task1/task1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
logFile="../data/test-1-action-ids.log"
outputPath="./output/"
outputFile="test-1-action-ids-output.txt"
tempFile="./output/tempNumber"

#Check the file
if [ ! -f "$logFile" ]; then
echo "The file doesn't exist..."
exit 1
fi

#Check whether the directory exists, if not, create the directory
if [ ! -d "$outputPath" ]; then
mkdir $outputPath
fi

#Match the string “ongoing” and print the next line
awk '$0~/ongoing/{getline;print$0;}' $logFile > $tempFile


#Print the third value divided by space and Remove the double quotation mark
cut -d " " -f 3 $tempFile | sed 's/\"//g' >> $outputPath$outputFile

#Delet the tempFile
rm $tempFile
14 changes: 14 additions & 0 deletions task2/apisever/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Start api services
docker:
name: demo-api
image: registry.wcl.com/wcl/api:latest
state: started
env:
username: demo
passwrod: demo
ports:
- "3000:3000"

- name: Wait for api services to be up
wait_for: delay=60 port=3000
62 changes: 62 additions & 0 deletions task2/init/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
- name: 01_configure_base_repos
get_url: url=http://mirrors.aliyun.com/repo/Centos-7.repo dest=/etc/yum.repos.d/CentOS-Base.repo

- name: 02_configure_epel_repos
get_url: url=http://mirrors.aliyun.com/repo/epel-7.repo dest=/etc/yum.repos.d/epel.repo

- name: 03_install_server
yum: name={{ item }} state=installed
loop:
- wget
- lrzsz
- lsof
- nmap
- telnet
- tree
- vim
- ntsysv
- unzip
- sysstat
- ntpdate
- iotop
- iftop
ignore_errors: yes
tags: t3

- name: 05_close firewalld
systemd: name=firewalld state=stopped enabled=no

- name: 06_set_timezone
shell: timedatectl set-timezone Asia/Shanghai

- name: 07_time_update
cron: name="ntpdate" minute="*/5" job="/usr/sbin/ntpdate time1.aliyun.com >/dev/null 2>&1"
ignore_errors: yes

- name: 08_set_sshd
become: true
block:

- name: Ensure SSHD server is installed
package:
name: openssh-server
state: present

- name: Ensure SSHD server service is running
systemd:
daemon_reload: true
enabled: true
name: sshd.service
state: started

- name: Configure sshd_config
template:
src: templates/sshd_config.j2
dest: /etc/ssh/sshd_config
owner: root
group: root
mode: '0600'
backup: true
validate: /sbin/sshd -t -f %s
notify: restart sshd
154 changes: 154 additions & 0 deletions task2/init/sshd_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{{ ansible_managed | comment }}

# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# System-wide Crypto policy:
# This system is following system-wide crypto policy. The changes to
# Ciphers, MACs, KexAlgoritms and GSSAPIKexAlgorithsm will not have any
# effect here. They will be overridden by command-line options passed on
# the server start up.
# To opt out, uncomment a line with redefinition of CRYPTO_POLICY=
# variable in /etc/sysconfig/sshd to overwrite the policy.
# For more information, see manual page for update-crypto-policies(8).

# Logging
SyslogFacility AUTH
LogLevel VERBOSE

# Authentication:

#LoginGraceTime 2m
{% if sshd_permit_root_login %}
PermitRootLogin yes
{% else %}
PermitRootLogin no
{% endif %}
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PermitEmptyPasswords no
PasswordAuthentication no


# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication no
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Fedora and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes

# It is recommended to use pam_motd in /etc/pam.d/sshd instead of PrintMotd,
# as it is more configurable and versatile than the built-in version.
PrintMotd no

#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server


# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
7 changes: 7 additions & 0 deletions task2/mysql/add_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: add_mysql_usr
user:
name: "{{ user }}"
shell: /bin/bash
tags:
- add_mysql_usr
99 changes: 99 additions & 0 deletions task2/mysql/install_mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
- name: create work_directory
file:
path: "{{ mysql_install_path }}"
state: directory
owner: "{{ user }}"
group: "{{ group }}"
recurse: yes

- name: copy_mysql_tar
copy:
src: "{{ mysql_version }}.tar.gz"
dest: "{{ mysql_install_path }}"
owner: "{{ user }}"
group: "{{ group }}"
tags:
- copy_mysql_tar

- name: unarchive_mysql_tar
unarchive:
src: "{{ mysql_install_path }}/{{ mysql_version }}.tar.gz"
dest: "{{ mysql_install_path }}"
copy: no
owner: "{{ user }}"
group: "{{ group }}"
tags:
- unarchive_mysql_tar

- name: link_mysql
file:
src: "{{ mysql_install_path }}/{{ mysql_version }}"
dest: "{{ mysql_install_path }}"
owner: "{{ user }}"
group: "{{ group }}"
state: link
tags:
- link_mysql

- name: create data_directory
file:
path: "{{ mysql_install_path }}/{{ mysql_link }}/data"
state: directory
owner: "{{ user }}"
group: "{{ group }}"

- name: copy_my.cnf
template:
src: my.cnf.j2
dest: /etc/my.cnf
tags:
- copy_my.cnf

- name: init_mysql
shell: ./bin/mysqld --initialize --user=mysql
args:
chdir: "{{ mysql_install_path }}/{{ mysql_link }}"
tags:
- init_mysql

- name: get_mysql_passwd
shell: cat ./error.log |grep localhost|grep "temporary password"|awk '{print $NF}'
register: mysql_init_passwd
args:
chdir: "{{ mysql_install_path }}/{{ mysql_link }}"
tags:
- get_mysql_passwd

- name: dispaly_passwd
debug:
msg: "{{ mysql_init_passwd.stdout }}"
tags:
- dispaly_passwd

- name: copy_mysql.server
template:
src: mysql.service.j2
dest: "/etc/init.d/mysql.server"
mode: 0755
tags:
- copy_mysql.server

- name: add_mysql_systemd
template:
src: mysql.service.j2
dest: /etc/systemd/system/mysql-{{ mysql_port }}.service
tags:
- add_mysql_systemd

- name: start_mysql_service
command: /etc/init.d/mysql.server start
tags:
- start_mysql_service

- name: alter_passwd
shell: ./bin/mysqladmin -u root -p'{{mysql_init_passwd.stdout}}' password '{{ mysql_root_passwd }}'
args:
chdir: "{{ mysql_install_path }}/{{ mysql_link }}"
tags:
- alter_passwd
11 changes: 11 additions & 0 deletions task2/mysql/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
mysql_version: mysql-5.7.33-linux-glibc2.12-x86_64
mysql_install_path: /opt/data/mysql_data
mysql_link: mysql
mysql_sock: /tmp/mysql.sock
mysql_port: 8901
mysql_root_passwd: "Root_123^"
repl_user: repl
repl_passwd: "Repl_123^"
user: mysql
group: mysql
Loading