安裝阿里云YUM源碼
[root@node1 ~]# cat <<EOF>>/etc/yum.repos.d/epel.repo
[epel]
name=epel for aliyun
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
[os]
name=os for aliyun
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0
EOF
[root@node1 ~]$ yum clean all
[root@node1 ~]$ yum makecache
安裝ansible
[cce@node1 ~]$ yum list |grep ansible*
ansible.noarch 2.3.0.0-3.el7 epel
ansible-doc.noarch 2.3.0.0-3.el7 epel
ansible-inventory-grapher.noarch 2.3.2-1.el7 epel
ansible-lint.noarch 3.4.9-1.el7 epel
ansible-openstack-modules.noarch 0-20140902git79d751a.el7 epel
ansible-review.noarch 0.13.0-2.el7 epel
kubernetes-ansible.noarch 0.6.0-0.1.gitd65ebd5.el7 epel
python2-ansible-tower-cli.noarch 3.1.3-1.el7 epel
[root@node1 ~]$ yum install -y ansible
利用jenkins密鑰對實現ansible免密分發
[jenkins@node1 ~]$ ls .ssh/
id_rsa id_rsa.pub known_hosts
將ansible所有權給我們的jenkins用戶
[root@node1 ~]# chown -R jenkins:jenkins /etc/ansible/
將兩臺客戶端服務器加入我們的ansible認真hosts表里,并歸納為test組
[jenkins@node1 ~]# tail -3 /etc/ansible/hosts
[jenkins]
192.168.1.72
192.168.1.73
編寫簡單的YML來實現以上創建步驟(我們的jenkins用戶也需要開通sudo權限來完成一些例如服務重啟的工作)
[root@node1 ~]# cat key.yml
---
- hosts: jenkins
remote_user: root
tasks:
- name: Create User
user: name=jenkins
- name: grant permissions
shell: usermod -aG wheel jenkins
- name: Mkdir Key Director
file: path=/home/jenkins/.ssh mode=0700 owner=jenkins group=jenkins state=directory
- name: Copy Public Key
copy: src=/home/jenkins/.ssh/id_rsa.pub dest=/home/jenkins/.ssh/authorized_keys owner=jenkins group=jenkins mode=600
[ops@node1 ~]$ egrep "^[^#\[]" /etc/ansible/ansible.cfg
inventory=/etc/ansible/hosts
remote_tmp=~/.ansible/tmp
local_tmp=~/.ansible/tmp
forks=5
poll_interval=15
sudo_user=root
executable=/bin/bash
private_key_file=/home/jenkins/.ssh/id_rsa
connect_timeout=30
connect_retries=30
connect_interval=1
[root@node2 ~]# yum install mysql mysql-devel httpd httpd-devel php mariadb-server php-mysql
配置測試頁面查看我們的PHP環境是否安裝成功
[root@node2 ~]# cat /var/www/html/index.php
<?php
phpinfo();
?>
[root@node2 ~]# systemctl start httpd
[root@node2 ~]# systemctl start mariadb
[root@node2 ~]# yum install mysql mysql-devel httpd httpd-devel php mariadb-server php-mysql
配置測試頁面查看我們的PHP環境是否安裝成功
[root@node2 ~]# cat /var/www/html/index.php
<?php
phpinfo();
?>
[root@node2 ~]# systemctl start httpd
[root@node2 ~]# systemctl start mariadb
[root@node3 ~]# mkdir -pv /data/www/sourcecode/
[root@node3 ~]# chown -R jenkins:jenkins /data/www/
首先安裝以下插件:
Environment Injector Plugin
Safe Restart Plugin
Javadoc Plugin
jQuery plugin
Extended Choice Parameter Plug-In
Pre SCM BuildStep Plugin
Robot Framework plugin
Git Parameter Plug-In
[jenkins@node1 ~]$ sudo mkdir /data/www/sourcecode/ #此處為代碼存放目錄
[jenkins@node1 ~]$ sudo chown -R jenkins:jenkins /data/www/ #將屬主修改為jenkins以免出現權限問題
[jenkins@node1 ~]$ cat /usr/local/scripts/local-dev-jenkins_test-deploy.sh
#!/bin/bash
### check
if [ ! -n "$1" ];then
echo "Please enter your file's name."
exit 10
fi
name=$1
datetime=$2
destination='jenkins'
##此處的destination是72和73,73作為備份服務器所以也需要推送,72則需要部署上線操作
ansible ${destination} -m copy -a "src=/data/www/sourcecode/${name}.tar.gz dest=/data/www/jenkins_packet/" && \
ansible 192.168.1.72 -m shell -a "sudo nohup bash -x /usr/local/scripts/local-dev-jenkins_test-deploy.sh ${name} ${datetime}" ##nohup在tomcat需要重啟的時候必須使用,否則會出現tomcat被殺掉起不起來的情況
配置73的源代碼存放目錄
[root@node3 ~]# mkdir /data/www/jenkins_packet/
[root@node3 ~]# chown -R jenkins:jenkins /data/www/
配置72的代碼存放目錄和部署腳本
[root@node2 ~]# mkdir /data/www/jenkins_packet/
[root@node2 ~]# chown -R jenkins:jenkins /data/www/
[root@node2 ~]# mkdir /usr/local/scripts/
[root@node2 scripts]# cat /usr/local/scripts/local-dev-jenkins_test-deploy.sh
#!/bin/bash
#
name=${1}.tar.gz
SITE_NAME=${1}
date_time=$2
if [ -d /tmp/${SITE_NAME} ];then
rm -rf /tmp/${SITE_NAME}
fi
mkdir /tmp/${SITE_NAME}
rm -rf /var/www/html_bak
#systemctl stop httpd
if [ -d /var/www/html ];then
mv /var/www/html /var/www/html_bak
fi
tar -zxf /data/www/jenkins_packet/${name} -C /tmp/${SITE_NAME}
mv -f /tmp/${SITE_NAME} /var/www/html
chown -R apache:apache /var/www/html
#systemctl start httpd ##PHP環境無需重啟
除關機命令
rm -rf /sbin/shutdown
rm -rf /sbin/init
rm -rf /sbin/reboot
查看有哪些用戶
cat /etc/passwd
刪除用戶 禁用用戶
passwd -l username # 禁用用戶
userdel usernmae # 刪除用戶
# 也可編輯/etc/passwd 文件,在不要的用戶前加注釋
iptables防火墻
# 先看要求開放的端口,如:21,22,23,80,3306
# 因為靶機上有各種各樣的后門端口,一個一個找太麻煩,直接全關了
iptables -L # 先查看已有規則
iptables -F # 刪除所有規則
iptables -I INPUT -p tcp --dport 22 -j ACCEPT # 開放22端口,這個必須要!!! 比賽的時候是靠ssh連接上去的,如果這個關了,自己都連不上
iptables -I INPUT -p tcp --dport 21 -j ACCEPT # 開放21端口
iptables -I INPUT -p tcp --dport 23 -j ACCEPT # 開放23端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT # 開放80
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT # 開放3306
iptables -I INPUT -p icmp -j ACCEPT # icmp,比賽的時候要求能ping通,所以這個也要開放
iptables -A INPUT -j DROP # 上面的配好后直接禁掉其他的,這里的一定要用 “-A” !!!
?
?
常用命令:
-A 追加規則-->iptables -A INPUT
-D 刪除規則-->iptables -D INPUT 1(編號)
-R 修改規則-->iptables -R INPUT 1 -s 192.168.12.0 -j DROP #取代現行規則,順序不變(1是位置)
-I 插入規則-->iptables -I INPUT 1 --dport 80 -j ACCEPT #插入一條規則,原本位置上的規則將會往后移動一個順位
-L 查看規則-->iptables -L INPUT #列出規則鏈中的所有規則
-N 新的規則-->iptables -N allowed #定義新的規則
通用參數:
-p 協議 例:iptables -A INPUT -p tcp
-s源地址 例:iptables -A INPUT -s 192.168.1.1
-d目的地址 例:iptables -A INPUT -d 192.168.12.1
-sport源端口 例:iptables -A INPUT -p tcp --sport 22
-dport目的端口 例:iptables -A INPUT -p tcp --dport 22
-i指定入口網卡 例:iptables -A INPUT -i eth0
-o指定出口網卡 例:iptables -A FORWARD -o eth0
-j 指定要進行的處理動作
常用的ACTION:
DROP:丟棄
REJECT:明示拒絕
ACCEPT:接受
SNAT基于原地址的轉換
source--指定原地址
配置文件
ssh
vim /etc/ssh/sshd_config # 編輯配置文件
Prot 22 # 端口號設置為22,比賽時一般不允許修改端口
PermitRootLogin yes # 允許root登錄
PasswordAuthentication yes # 允許登錄
PermitEmptyPasswords no # 不允許空密碼登錄
ftp
vim /etc/vsftpd.conf #配置文件路徑可能有點不一樣,根據當時環境而定
anonymous_enable=YES #這是允許匿名用戶登錄,把YES改為NO即可,ftp的加固基本上就這個了
telnet
# 這個基本上沒得什么加固的,用戶名密碼難一點基本就沒問題了
http
ls /var/www/html #查看html目錄下有什么文件
cp -r /var/www/html/* /root/html_bak # 先備份
rm -rf /var/www/html/* # 刪除html目錄下所有文件
mysql
# mysql的話禁止外聯就可以了
update mysql.user set host="127.0.0.1"; # 只允許127.0.0.1連接
flush privileges; # 使其立即生效
?
還有一種改配置文件的方法
vi /etc/my.cf # 將#skip-networking注釋去掉
rsync
配置文件默認路徑為:/etc/rsyncd.conf
配置文件
uid=root #運行RSYNC守護進程的用戶
gid=root #運行RSYNC守護進程的組
use chroot=no #不使用chroot
max connections=4 # 最大連接數為4
strict modes=yes #是否檢查口令文件的權限
port=873 #默認端口873
[backup] #這里是認證的模塊名,在client端需要指定
path=/home/backup/ #需要做鏡像的目錄,不可缺少!
comment=This is a test #這個模塊的注釋信息
ignore errors #可以忽略一些無關的IO錯誤
read only=no# 只讀
list=no #不允許列文件
auth users=hening #認證的用戶名,如果沒有這行則表明是匿名,此用戶與系統無關
secrets file=/etc/rsync.pas #密碼和用戶名對比表,密碼文件自己生成
hosts allow=10.96.9.105,10.96.9.113#允許主機內容ip
hosts deny=0.0.0.0/0 #禁止主機
#transfer logging=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
我們在網上成功購買一個模板后,接下來需要做的是把網站整上線,只有網站成功上線,別人才能在瀏覽器里邊搜到我們的網站,關于網站上線的詳細教程,讓我們一起來看看,手把手教你,不相信你學不會!
1、首先備份本地模板數據,并壓縮為.zip 格式。
2、下載 8Uftp 并登陸后臺,虛擬主機空間包含 WEB、LOG、Backup 三個目錄,目錄文件不可隨意刪除或修改目錄名,WEB 目錄:放置 您的站點文件;LOG 目錄:通過“下載日志”功能將您網站的訪問日 志文件下載保存到此目錄,您可自由查看;Backup 目錄:放置您的 備份文件。
3、打開 WEB 文件,刪除景安 index 主頁,上傳備份模板數據.ZIP,在 景安后臺在線解壓,然后在 FTP 上刷新,刪除模板數據.ZIP。
4、打開瀏覽器輸入 http://你的網址/install ,如果出現 dir,那么請刪 除 install 文 件 夾 中 的 install.lock.txt 和 index.html , 并 且 把 index.php.bak 改 成 index.php ; module-install.php.bak 改 成 module-install.php,然后刷新頁面。
5、勾選后點擊繼續-繼續-填寫數據庫信息,其中數據庫主機、數據庫 用戶、數據庫密碼、數據庫名稱要按照配置的數據庫信息填寫。其它 地方不要動-繼續-安裝完成。
6、點擊“登錄網站后臺” 或者輸入 http://您的域名/dede/ 進入后 臺,為了安全起見,dede 這個文件夾的名字可以改掉。
7、后臺數據還原-點擊系統-點擊數據備份與還原-點擊右上角數據還 原-拉倒最下面點擊開始還原數據。
8、數據還原后,現在后臺登陸的賬號密碼都變成 admin 了,需要點 擊系統-系統用戶管理修改下密碼。
9、點擊系統-系統基本參數設置-站點根網址輸入 http://你的域名,前 面帶 http://結尾不要帶/,默認保存路徑/后面的 a 去掉,在基本參數 設置頁面也可以設置網站的三大標簽和其它參數,設置完成后點擊確 定。一定要修改站點根網址,一定要保持這里和瀏覽器上的地址欄域 名一致
10、點擊生成-更新系統緩存。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。