必要設(shè)置
Aliyun ECS 系統(tǒng)初始化
- Operating System: CentOS Linux 7 (Core)
- Kernel: Linux 3.10.0-693.17.1.el7.x86_64
- Architecture: x86-64
設(shè)置主機(jī)名稱 hostname
# get hostname info
hostnamectl status
# set hostname
hostnamectl set-hostname your-name
解決語言區(qū)域問題 locale
# 查看當(dāng)前系統(tǒng)的語言區(qū)域設(shè)置,報(bào)警如下:
# 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
# 查看系統(tǒng)設(shè)置語言
cat /etc/locale.conf
# 查看系統(tǒng)能夠支持的語言, 先確保語言列表中包含上面的語言設(shè)置
locale -a
# 修復(fù)問題周蹭,將無法set的參數(shù)在下面的配置中新增
vim /etc/locale.conf
LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
# 確認(rèn)問題解決
locale
- 問題參考方案 Fix locale error
設(shè)置SSH登陸歡迎信息 welcome message
一般ssh默認(rèn)的歡迎界面包括以下幾個(gè)部分
- 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
- motd (message of the day)
###############################
# 修改方式1:靜態(tài)motd信息
vim /etc/motd
# 重新加載配置
systemctl reload sshd
# 修改方式2:自定義motd
vim /etc/profile.d/motd.sh
> #!/bin/bash
> # 注: 登陸系統(tǒng)時(shí)會(huì)自動(dòng)執(zhí)行/etc/profile
> # 其中會(huì)遍歷/etc/profile.d/下的所有.sh可執(zhí)行文件
> 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
> #
> ##################################
> "
# 增加文件可執(zhí)行權(quán)限
chmod +x /etc/profile.d/motd.sh
# 修改ssh配置
vim /etc/ssh/sshd_config
> PrintMotd no # 關(guān)閉默認(rèn)的motd打印
# 重新加載配置
systemctl reload sshd
- last login informations
- 參考資料
創(chuàng)建運(yùn)維賬戶devops
- Issue the useradd command to create a locked user account:
useradd devops
# or you can use "adduser <username>"
- Unlock the account by issuing the passwd command to assign a password and set password aging guidelines:
passwd devops
- 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權(quán)限,還可以直接編輯sudoer文件"vim /etc/sudoers"
# get user | group info
id devops
groups devops
- gen ssh key
# 切換賬戶
su - devops
# 生成ssh key
ssh-keygen
- 設(shè)置用戶的ssh公鑰登錄
vim /home/devops/.ssh/authorized_keys
SSH安全設(shè)置
## 編輯ssh配置
sudo vim /etc/ssh/sshd_config
PermitRootLogin no ## 禁用服務(wù)器root用戶的ssh登陸
PasswordAuthentication no ## 禁用ssh用戶密碼登陸饶辙,僅能使用ssh pub key
## 重啟sshd ,或者可以使用命令
systemctl restart sshd
初始化運(yùn)維工作區(qū) work space
## 應(yīng)用工程
mkdir -p /opt/apps
## 數(shù)據(jù)目錄
mkdir -p /opt/data/tmp
## 軟件目錄
mkdir -p /opt/software
## 自定義軟件安裝位置
mkdir -p /opt/tools
通用工具
- git
sudo yum install git
- vim plugin manager
## 下載vim-plug工具
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
系統(tǒng)升級(jí)
# Install Extra Packages for Enterprise Linux
yum install epel-release
# Update yum
yum update
可選設(shè)置
安裝進(jìn)程守護(hù) Supervisor
- Install supervisor
# 安裝
easy_install supervisor
# 配置啟動(dòng)項(xiàng) Configs programs
echo_supervisord_conf > /etc/supervisord.conf
vim /etc/supervisord.conf
> [program:foo_test]
> command=/bin/cat
# 啟動(dòng)supervisor
supervisord -c /etc/supervisord.conf -n
# 其它命令
supervisorctl
help
supervisorctl stop all
supervisorctl status all
- 通過systemd管理supervisor(進(jìn)程守護(hù)+開機(jī)啟動(dòng))
## 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服務(wù)
systemctl daemon-reload
systemctl status supervisor
systemctl start supervisor
systemctl is-enabled supervisor
systemctl enable supervisor
## 開機(jī)啟動(dòng)
ln -s '/etc/systemd/system/supervisor.service' '/etc/systemd/system/multi-user.target.wants/supervisor.service'
# 測試
reboot
systemctl reboot
- 參考文檔
- Supervisor is based on four components: supervisord洒敏、supervisorctl矗蕊、a web server、an XML-RPC Interface
- How To Create a systemd Service in Linux
- Supervisor/initscripts
安裝Java開發(fā)環(huán)境 JDK Setup
- 下載 JDK 1.8 rpm包
- 安裝JDK
# 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