Sunday, January 19, 2025

[Jenkins] Cài đặt nhanh Jenkins bằng bash script

-

Bài trước mình đã hướng dẫn các bạn cài đặt Jenkins thủ công, ở bài viết này mình sẽ hướng dẫn các bạn cài bằng script tự động, khuyến cáo các bạn nên cài bằng tay trước để hiểu trình tự các bước đã rồi mới dùng script nhé.

sudo apt-get update
sudo apt-get clean -y
apt-get install openjdk-8-jdk -y
sudo apt-get install nginx -y
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c "echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list"
sudo apt-get update
sudo apt-get install jenkins -y
cat /var/lib/jenkins/secrets/initialAdminPassword

sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
sudo git --version
sudo apt install sshpass -y

mkdir -p /var/lib/jenkins/.ssh/
echo '' > /var/lib/jenkins/.ssh/known_hosts
echo -e """-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAxwldSynNWYEj36iWSNvsLU821sIW5cpzOWySWlaR8KrREFjN\nfCYQJWFRfzk+s+wrKSYGifvYxFvGEEsUMA80WEZEKQ1xY6s/lAoD1+Y5cJ5cbohN\nRYYno1rEUDLqz2qeARUSDyKVRw3LVtU6/01NYcGJECwavNUkzP216OUP8HmYKZXF\nWWLT9C6M1ftkUYaeI8RSn+cQr0UPDkJ92ERtRvsqQTpewNHSHpC7sS8lLDPR2nhX\nddUV1Fk8kII6gQAyH3nZ0329IUU7JwoW9RTwiD6aPkmtFQWlJSP56oHLlxr+wkk2\npOoxZ5fzxpi7icbej4g9FNDBQ2KLeQWdGhNqpQIBIwKCAQEAu6m+XM+kW7RGZSns\nyFpTtbEWcrb/pXW9GOK14CW8zPjTvvSkfF5m/qw25asAmwM+oyPaR5WvH4m6vuez\n8syBz5K1S0cwZUmw+UtFc8pwrAMGsVvxFapf4ymxx/V+TokYoe9LipzzJbyMhRIw\nT8yKyeJcqNkghigM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QC5jYRFel9+12q/xSSBf49Y2YkZ62MFzzcLr1D9QsnZ9w5jK+5e03sQA9pPKwJnCnbuEDGH1J0xZjQ3cZ03QQrLJ93lFSlR2vAcV5mXQttaRzaKKF8R6mlPXbwoQHysBH/03W72sBZ2WOLWzmYM4IIgoY/wJQodXmNTw96jkn8X+8cHodx55m1K82tWBhGdMc3OkiS98qyJR4nsYRq+3lAbd/aUP8v7N4hSP7zjhrgTaO2jOpnbDJjXYuK8WyT/OenQtbzPsdJcomPEbDN3vtd8Hme9GZ0fqS2RrmhpSzydShbGA+ytW5h82wrXAKQWIaiiS6zLihsLd4nAFjINYbxB""" > /var/lib/jenkins/.ssh/authorized_keys
chmod 600 /var/lib/jenkins/.ssh/id_rsa  /var/lib/jenkins/.ssh/authorized_keys

cd /var/lib/jenkins/.ssh/ \
  && chown jenkins:jenkins id_rsa \
  && chown jenkins:jenkins authorized_keys \
  && chown jenkins:jenkins known_hosts

systemctl status jenkins | grep active

Việc còn lại các bạn dùng trình duyệt web login vào và sử dụng thôi.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

4,956FansLike
256FollowersFollow
223SubscribersSubscribe
spot_img

Related Stories