diff --git a/Terraform/serverJenkins.sh b/Terraform/serverJenkins.sh index 0a12488f79755c294c2d9622d8ec3853acdc67ee..0fcd145c35a76f0cf96e3e02a86ec66538d300d4 100644 --- a/Terraform/serverJenkins.sh +++ b/Terraform/serverJenkins.sh @@ -1,39 +1,35 @@ #!/usr/bin/bash -echo "update logging configuration..." -sudo sh -c "echo '*.info;mail.none;authpriv.none;cron.none /dev/ttyS0' >> /etc/rsyslog.conf" -sudo systemctl restart rsyslog -echo "update logging configuration..." - -echo "cd to root directory..." -cd root - -echo "whoami..." +su centos +cd /home/centos whoami +echo logged in as $USER. +echo in directory $PWD -echo "pwd..." -pwd +# 安装常用工具 +sudo yum install wget -y +sudo yum install unzip -y +sudo yum install git -y -# commented out to speed things up, do not do this in production -# echo "upgrading..." -# sudo yum upgrade -y +# 安装 OpenSSH +echo "Installing OpenSSH..." +sudo yum install -y openssh-server -echo "installing gfortran..." -sudo yum install gcc-gfortran -y +# 启动并启用 OpenSSH +echo "Starting and enabling OpenSSH..." +sudo systemctl start sshd +sudo systemctl enable sshd -echo "installing git..." -sudo yum install git -y +# 检查 OpenSSH 服务状态 +sudo systemctl status sshd +# 配置 GitLab 服务器 SSH 密钥 echo "installing gitlab server key..." -touch .ssh/known_hosts -ssh-keyscan git.cardiff.ac.uk >> .ssh/known_hosts -chmod 644 .ssh/known_hosts - -sudo apt-get update -sudo apt-get install -y openssh-server -sudo systemctl start ssh -sudo systemctl enable ssh +sudo touch ~/.ssh/known_hosts +sudo ssh-keyscan gitlab.cs.cf.ac.uk >> ~/.ssh/known_hosts +sudo chmod 644 ~/.ssh/known_hosts +# 配置用户 SSH 密钥 echo "installing gitlab deployment key..." touch matrix_keypair.key cat << `EOF` >> matrix_keypair.key @@ -67,18 +63,103 @@ vNfQn99+1/Zo5LdYEwAAABhJRCtzY21pbWNAV1JBODdFRUFCM0E0NkIB `EOF` chmod 400 matrix_keypair.key +# 通过 SSH 密钥克隆一个 Git 仓库 echo "cloning repository..." echo $PWD ssh-agent bash -c 'ssh-add matrix_keypair.key; git clone git@git.cardiff.ac.uk:scmimc/matrix.git' -echo "changing to repository directory..." -cd matrix +# 更新 rsyslog 配置以将日志输出到特定设备 +echo "update logging configuration..." +sudo sh -c "echo '*.info;mail.none;authpriv.none;cron.none /dev/ttyS0' >> /etc/rsyslog.conf" +sudo systemctl restart rsyslog + +# 确认当前的工作目录是否成功切换 +cd /home/rocky +echo in directory $PWD + +# 安装并配置 MariaDB 数据库 +echo "installing MariaDB..." +# sudo yum install mysql -y +sudo dnf install mariadb-server -y +sudo systemctl start mariadb +sudo systemctl status mariadb +sudo systemctl enable mariadb + + +echo "creating mysql_secure_installation.txt..." +touch mysql_secure_installation.txt +cat << `EOF` >> mysql_secure_installation.txt + +n +Y +comsc +comsc +Y +Y +Y +Y +Y +`EOF` + +echo "running mysql_secure_installation..." +sudo mysql_secure_installation < mysql_secure_installation.txt + +sudo yum install wget -y +sudo yum install unzip -y +sudo yum install git -y + +# 安装 Java 17 +echo "Installing Java 17..." +sudo yum install java-17-openjdk-devel -q -y +echo java --version + +# 安装 Jenkins +echo "install Jenkins" +# https://pkg.jenkins.io/redhat-stable/ +curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo +sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key +sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io-2023.key +sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y +sudo yum install jenkins -y + +# 配置 Jenkins 的 SSH known_hosts 文件 +echo "installing gitlab server key... has to be added to the jenkins user home (~) dir " +mkdir /var/lib/jenkins/.ssh +sudo touch /var/lib/jenkins/.ssh/known_hosts +sudo ssh-keyscan git.cardiff.ac.uk >> /var/lib/jenkins/.ssh/known_hosts +sudo chmod 644 /var/lib/jenkins/.ssh/known_hosts + + +# If you want jenkins on port 8081 so you can run your app on 8080 then change the default jenkins port. +#(look up linux sed - it is really cool) +# sudo sed -i 's/JENKINS_PORT="8080"/JENKINS_PORT="8081"/g' /etc/sysconfig/jenkins +sudo systemctl start jenkins +systemctl status jenkins +sudo systemctl enable jenkins -echo "enabling execution..." -chmod a+x *.sh +# echo "Installing Java 10..." +# curl -O https://download.java.net/java/GA/jdk10/10.0.2/19aef61b38124481863b1413dce1855f/13/GPL/openjdk-10.0.2_linux-x64_bin.tar.gz +# tar zxvf openjdk-10.0.2_linux-x64_bin.tar.gz +# sudo mv jdk-10.0.2 /usr/local/ +# export JAVA_HOME=/usr/local/jdk-10.0.2 +# export PATH=$PATH:$JAVA_HOME/bin +# java --version +# sudo ln -s /usr/local/jdk-10.0.2/bin/java /usr/bin/java -echo "compiling matrix..." -./make.sh +# 安装 Gradle 7.6 +echo "Installing gradle..." +# wget https://services.gradle.org/distributions/gradle-6.7.1-bin.zip +wget https://services.gradle.org/distributions/gradle-7.6-bin.zip +sudo mkdir /opt/gradle +# sudo unzip -d /opt/gradle gradle-6.7.1-bin.zip +# export PATH=$PATH:/opt/gradle/gradle-6.7.1/bin +sudo unzip -q -d /opt/gradle gradle-7.6-bin.zip +export PATH=$PATH:/opt/gradle/gradle-7.6/bin +echo gradle -v -echo "running matrix..." -nohup ./run.sh & +# 安装 Terraform 1.1.5 +echo "Installing terraform..." +cd /home/rocky +wget https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip +unzip terraform_1.1.5_linux_amd64.zip +sudo mv terraform /usr/local/bin/