DevOpsSOP:基於阿里雲ECS的通用系統安裝及初始化

Jacky_L發表於2018-02-28

CentOS Setup

通用設定(必要)

Aliyun ECS 系統初始化

  • Operating System: CentOS Linux 7 (Core)
  • Kernel: Linux 3.10.0-693.17.1.el7.x86_64
  • Architecture: x86-64

設定主機名稱 hostname

# get hostname info
hostnamectl status

# set hostname
hostnamectl set-hostname your-name
複製程式碼

解決語言區域問題 locale

# 檢視當前系統的語言區域設定,報警如下:
# locale: Cannot set LC_CTYPE to default locale: No such file or directory
# locale: Cannot set LC_ALL to default locale: No such file or directory
locale

# 檢視系統設定語言
cat /etc/locale.conf
# 檢視系統能夠支援的語言, 先確保語言列表中包含上面的語言設定
locale -a 

# 修復問題,將無法set的引數在下面的配置中新增
vim /etc/locale.conf
    LC_CTYPE="en_US.UTF-8"
    LC_ALL="en_US.UTF-8"

# 確認問題解決
locale
複製程式碼

設定SSH登陸歡迎資訊 welcome message

一般ssh預設的歡迎介面包括以下幾個部分

  1. greetings
###############################
# 自定義greetings
vim /etc/ssh/ssh_greetings.txt
    > ###############################
    > #                             #
    > #      This is greeting msg   #
    > #                             #
    > ###############################
# 修改ssh配置
vim /etc/ssh/sshd_config
    > Banner /etc/ssh/ssh_greetings.txt
# 重新載入配置
systemctl reload sshd
複製程式碼
  1. motd (message of the day)
###############################    
# 修改方式1:靜態motd資訊
vim /etc/motd 
# 重新載入配置
systemctl reload sshd

# 修改方式2:自定義motd
vim /etc/profile.d/motd.sh
    > #!/bin/bash
    > # 注: 登陸系統時會自動執行/etc/profile
    > # 其中會遍歷/etc/profile.d/下的所有.sh可執行檔案
    > echo -e "
    > ##################################
    > #
    > #     Welcome to `hostname`
    > #     This system is running `cat /etc/redhat-release`
    > #     kernel is `uname -r`
    > #     You are logged in as `whoami`
    > # 
    > #     GOD BLESS OUR SERVER !!!
    > #               -- DevOps Group
    > #
    > ##################################
    > "
# 增加檔案可執行許可權
chmod +x /etc/profile.d/motd.sh   
# 修改ssh配置
vim /etc/ssh/sshd_config
    > PrintMotd no # 關閉預設的motd列印
# 重新載入配置
systemctl reload sshd
複製程式碼
  1. last login informations

建立運維賬戶devops

  1. Issue the useradd command to create a locked user account:
useradd devops
# or you can use "adduser <username>"
複製程式碼
  1. Unlock the account by issuing the passwd command to assign a password and set password aging guidelines:
passwd devops
複製程式碼
  1. Use the usermod command to add the user to the wheel group.
# By default, on CentOS, members of the wheel group have sudo privileges.
usermod -aG wheel devops
# BTW,為使用者新增sudo許可權,還可以直接編輯sudoer檔案"vim /etc/sudoers"

# get user | group info
id devops
groups devops
複製程式碼
  1. gen ssh key
# 切換賬戶
su - devops
# 生成ssh key
ssh-keygen
複製程式碼
  1. 設定使用者的ssh公鑰登入
    vim /home/devops/.ssh/authorized_keys

SSH安全設定

## 編輯ssh配置
sudo vim /etc/ssh/sshd_config 
  PermitRootLogin no ## 禁用伺服器root使用者的ssh登陸
  PasswordAuthentication no ## 禁用ssh使用者密碼登陸,僅能使用ssh pub key

## 重啟sshd ,或者可以使用命令
systemctl restart sshd 
複製程式碼

初始化運維工作區 work space

## 應用工程
mkdir -p /opt/apps
## 資料目錄
mkdir -p /opt/data/tmp
## 軟體目錄
mkdir -p /opt/software
## 自定義軟體安裝位置
mkdir -p /opt/tools
複製程式碼

通用工具

  1. git sudo yum install git
  2. vim plugin manager
## 下載vim-plug工具
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
複製程式碼

系統升級

# Install Extra Packages for Enterprise Linux
yum install epel-release

# Update yum
yum update
複製程式碼

可選設定

安裝程式守護 Supervisor

  1. Install supervisor
# 安裝
easy_install supervisor

# 配置啟動項 Configs programs 
echo_supervisord_conf  > /etc/supervisord.conf
vim /etc/supervisord.conf
    > [program:foo_test]
    > command=/bin/cat
    
# 啟動supervisor
supervisord -c /etc/supervisord.conf -n 

# 其它命令
supervisorctl
help
supervisorctl stop all    
supervisorctl status all

複製程式碼
  1. 通過systemd管理supervisor(程式守護+開機啟動)
## systemd常用命令
systemctl status
systemctl  # same as "systemctl list-units"
systemctl --failed
systemctl start[|stop|restart|reload|status|help] unit
systemctl reboot    # Shut down and reboot the system:
systemctl poweroff  # Shut down

## 在systemd中配置supervisor
vim /etc/systemd/system/supervisor.service
    # supervisord service for systemd (CentOS 7.0+)
    
    [Unit]
    Description=Supervisor daemon
    
    [Service]
    Type=forking
    ExecStart=/usr/bin/supervisord
    ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
    ExecReload=/usr/bin/supervisorctl $OPTIONS reload
    KillMode=process
    Restart=on-failure
    RestartSec=42s

## 載入supervisor服務
systemctl daemon-reload
systemctl status supervisor
systemctl start supervisor
systemctl is-enabled supervisor
systemctl enable supervisor

## 開機啟動
ln -s '/etc/systemd/system/supervisor.service' '/etc/systemd/system/multi-user.target.wants/supervisor.service'

# 測試
reboot
systemctl reboot

複製程式碼
  1. 參考文件

安裝Java開發環境 JDK Setup

# Check which specific RPM package provides the java.
rpm -q --whatprovides java

# Uninstall any earlier installations of the JDK packages.
rpm -e package_name 

# Install the package.
rpm -ivh jdk-8uversion-linux-x64.rpm

java -version
javac -version
複製程式碼

安裝Maven環境

# 解壓
tar xzvf apache-maven-3.5.2-bin.tar.gz -C /opt/tools/

# 配置MVN_HOME和bin PATH
vim /etc/profile.d/global_ops_cmd.sh
    export MVN_HOME="/opt/tools/apache-maven-3.5.2"
    export PATH="$PATH:$MVN_HOME/bin"
    
# 新增阿里雲maven映象源地址
vim /opt/tools/apache-maven-3.5.2/conf/settings.xml
    <mirrors>
        <mirror>
          <id>alimaven</id>
          <mirrorOf>central</mirrorOf>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
    </mirrors>
    
mvn -v
複製程式碼

  • DEVOPS SOP (Standard operating procedur)
  • Title: 《SOP-OPS-基於阿里雲ECS的通用系統安裝及初始化》
  • Modify History:
    • 2018-02-27 v1.0
  • Authors: Jacky.L、...
  • Published:

相關文章