linux 初始配置
關閉Selinux
編輯 /etc/selinux/config
SELINUX=disabled
需要重啟
查看selinux 狀態(tài)
sestatus
SELinux status: disabled
關閉Firewalld
做實驗的時候,端口無法訪問的事情是經常發(fā)生的。不折騰了。
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
firewall-cmd --state
安裝 Epel
yum install epel-release
查看repo情況
yum repolist
配置 Hostname
cat /etc/hostname
kolla
cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.110 kolla
檢查
#hostname -F /etc/hostname
#hostname
kolla
同步時間
yum install ntp
systemctl enable ntpd.service
systemctl start ntpd.service
手工同步時間
ntpdate 0.centos.pool.ntp.org
配置 pip 鏡像
mkdir ~/.pip
vi ~/.pip/pip.conf
寫入如下內容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
內核調優(yōu)
調大打開文件數(shù)
修改/etc/security/limits.conf
* soft nofile 65555
* hard nofile 65555
* hard core 65555
* soft core 65555
* hard noproc 65555
* soft noproc 65555
修改netfilter 配置
#net.netfilter.nf_conntrack_buckets 的值
# 臨時生效
echo 262144 > /sys/module/nf_conntrack/parameters/hashsize
# 重啟永久生效,新建文件:/etc/modprobe.d/iptables.conf,設置如下
options nf_conntrack hashsize = 32768
# 修改net.netfilter.nf_conntrack_max 最大追蹤連接數(shù)修改 調優(yōu)
# 臨時生效
sudo sysctl -w net.netfilter.nf_conntrack_max=1048576
suod sysctl -w net.nf_conntrack_max=1048576
# 永久生效
# 添加修改內核配置文件(/etc/sysctl.conf)
net.netfilter.nf_conntrack_max=1048576
net.nf_conntrack_max=1048576
# 當數(shù)據包超長時,不丟棄數(shù)據包。K8S重要
net.netfilter.nf_conntrack_tcp_be_liberal=1
# 如果要馬上應用配置文件里的設置:
sudo sysctl -p /etc/sysctl.conf
# 臨時生效
# 主動方的最后1個狀態(tài)。默認120秒
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_fin_wait=30
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
# CLOSE_WAIT是被動方收到FIN發(fā)ACK,然后會轉到LAST_ACK發(fā)FIN,除非程序寫得有問題,正常來說這狀態(tài)持續(xù)時間很短。#默認 60 秒
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_close_wait=15
# 理論上不用這么長,不小于 net.ipv4.tcp_keepalive_time 就行了。默認 432000 秒(5天)
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_established=300
-----------------------------------------------------
# 永久生效
# 修改內核配置文件(/etc/sysctl.conf)
net.netfilter.nf_conntrack_tcp_timeout_fin_wait=30
net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
net.netfilter.nf_conntrack_tcp_timeout_close_wait=15
net.netfilter.nf_conntrack_tcp_timeout_established=300
# 如果要馬上應用配置文件里的設置:
sudo sysctl -p /etc/sysctl.conf
## 安裝 lrzsz
``` shell
yum install -y lrzsz
安裝zsh
yum install -y zsh git
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# chsh -s /usr/bin/zsh 更換使用的shell 程序為zsh
推薦主題
直接設置使用即可,無需修改原主題
ZSH_THEME="agnoster"
定制化主題
安裝之后會發(fā)現(xiàn)看不到當前用戶的用戶名。解決方案如下
# 查看當前zsh用的哪一個主題
echo $ZSH_THEME # 輸出robbyrussell
cp ~/.oh-my-zsh/themes/robbyrussell.zsh-theme .oh-my-zsh/themes/myrobbyrussell.zsh-theme
修改 myrobbyrussell.zsh-theme 的內容為如下內容
#PROMPT="%(?:%{$fg_bold[green]%}? :%{$fg_bold[red]%}? )"
#PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[magenta]%}%n%{$fg_bold[cyan]%}@%{$fg[green]%}%m %{$fg_bold[green]%}%p%{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$fg_bold[blue]%}? %{$fg[yellow]%}# '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
修改 ~/.zshrc
ZSH_THEME="myrobbyrussell"
參考設置
#1
PROMPT='%{$fg[green]%}%m@%{$fg[magenta]%}%(?..%?%1v)%n:%{$reset_color%}%{$fg[cyan]%}%~#'
#2
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[green]%}%p%{$fg[cyan]%}%d %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$reset_color%}~#:'
#3
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[green]%}%p%{$fg[cyan]%}%d %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$reset_color%}~#: '
#4
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[magenta]%}%n%{$fg_bold[cyan]%}@%{$fg[green]%}%m %{$fg_bold[green]%}%p%{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$fg_bold[blue]%}? %{$fg[yellow]%}# '
# 5 推薦
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[magenta]%}%n%{$fg_bold[cyan]%}@%{$fg[green]%}%m %{$fg_bold[green]%}%p%{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$fg_bold[blue]%}? %{$reset_color%}~#: '
zsh 與bash 的共用問題
方案
為了便于在bash和zsh切換后可以使用同樣的配置的alias等配置,采用如下方案:
自定義配置放在~/.profile中
.bashrc配置文件中使用source ~/.profile加載自定義配置
.zshrc配置文件中使用[[ -e ~/.profile ]] && emulate sh -c ‘source ~/.profile’加載自定義配置
配置文件示例如下:
.bashrc
zzzzzzzzzzzzz原有配置
下面一行為新加配置
source ~/.profile
.zshrc
zzzzzzzzzzzzz原有配置
下面一行為新加配置
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
zsh 與 bash 加載環(huán)境配置文件的順序
bash加載配置文件順序
login 和 non-login bash shell 的情況下,讀取的配置文件數(shù)據并不一樣所致。
一般來說 login shell 會讀取兩個配置文件:
/etc/profile:這是系統(tǒng)整體的設定,修改這個文件要慎重
~/.bash_profile 或 ~/.bash_login 或~/.profile:屬于使用者個人設定,要改自己的數(shù)據,可以寫在這里。
bash 在讀完整體環(huán)境設定的 /etc/profile 并藉此呼叫其他配置文件后,接下來則會讀取使用者的個人配置文件。在login shell 的 bash 環(huán)境中,所讀取的個人偏好配置文件主要有三個,依順序分別為:
- 1.~/.bash_profile
- 2.~/.bash_login
- 3.~/.profile 其實 bash 的 login shell 設定只會讀取上面三個文件的其中一個,而讀取的順序則是依照上面的順序。

實線的方向是主線程流程,虛線的方向則是被調用的配置文件。
source與.bashrc
non-login shell 這種非登入情況取得 bash 操作接口的環(huán)境配置文件又是什么? 當你取得 non-login shell 時,該 bash 配置文件僅會讀取 ~/.bashrc 而已。
由于 /etc/profile 與 ~/.bash_profile 都是在取得 login shell 的時候才會讀取的配置文件,所以,如果將自己的偏好設定寫入上述文件后,通常都是得注銷在登入后,改設定才會生效。那么,能不能直接讀取配置文件而不注銷登入呢?可以的,那就是利用 source 這個指令。
利用 source 或小數(shù)的(.)都可以將配置文件的內容讀進來目前的 shell 環(huán)境中。
zsh加載配置文件順序
當 Zsh 啟動時,它會按照順序依次讀取下面的配置文件:
- /etc/zsh/zshenv
該文件應該包含用來設置PATH 環(huán)境變量[broken link: invalid section]以及其他一些環(huán)境變量的命令;不應該包含那些可以產生輸出結果或者假設終端已經附著到 tty 上的命令。
- ~/.zshenv
該文件和 /etc/zsh/zshenv 相似,但是它是針對每個用戶而言的。一般來說是用來設置一些有用的環(huán)境變量。
- /etc/zsh/zprofile
這是一個全局的配置文件,在用戶登錄的時候加載。一般是用來在登錄的時候執(zhí)行一些命令。請注意,在 Arch Linux 里該文件默認包含一行配置,用來加載 /etc/profile 文件,詳見 #全局配置文件。
- /etc/profile
在登錄時,該文件應該被所有和伯克利(Bourne)終端相兼容的終端加載:它在登錄的的時候會加載應用相關的配置(/etc/profile.d/*.sh)。注意在 Arch Linux 里,Zsh 會默認加載該文件。
- ~/.zprofile
該文件一般用來在登錄的時候自動執(zhí)行一些用戶腳本。
- /etc/zsh/zshrc
當 Zsh 被作為交互式終端的時候,會加載這樣一個全局配置文件。
- ~/.zshrc
當 Zsh 被作為交互式終端的時候,會加載這樣一個用戶配置文件。
- /etc/zsh/zlogin
在登錄完畢后加載的一個全局配置文件。
- ~/.zlogin
和 /etc/zsh/zlogin 相似,但是它是針對每個用戶而言的。
- /etc/zsh/zlogout
在注銷的時候被加載的一個全局配置文件。
- ~/.zlogout
和 /etc/zsh/zlogout 相似,但是它是針對每個用戶而言的.
參數(shù)說明
| code | info |
|---|---|
| %T | 系統(tǒng)時間(時:分) |
| %* | 系統(tǒng)時間(時:分:秒) |
| %D | 系統(tǒng)日期(年-月-日) |
| %n | 你的用戶名 |
| %B - %b | 開始到結束使用粗體打印 |
| %U - %u | 開始到結束使用下劃線打印 |
| %d | 你目前的工作目錄 |
| %~ | 你目前的工作目錄相對于~的相對路徑 |
| %M | 計算機的主機名 |
| %m | 計算機的主機名(在第一個句號之前截斷) |
| %l | 你當前的tty |
| %n | 登錄名 |
CENTOS 8 替換yum源
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
cp /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo.bak
cp /etc/yum.repos.d/CentOS-Extras.repo /etc/yum.repos.d/CentOS-Extras.repo.bak
sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
sed -i 's/#baseurl=/baseurl=/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
cp /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.bak
cp /etc/yum.repos.d/epel-playground.repo /etc/yum.repos.d/epel-playground.repo.bak
sed -i 's/metalink=/#metalink=/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
sed -i 's/#baseurl=/baseurl=/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
sed -i 's/https:\/\/download.fedoraproject.org\/pub/https:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
最后, 懶人腳本
if [ `whoami` != 'root' ]
then
echo 'you must run this script as root'
exit 0
fi
yum install -y epel-release
version =`cat /etc/centos-release | awk '{print $4}' | cut -d . -f1`
if [[ version == 8 ]]; then
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
cp /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo.bak
cp /etc/yum.repos.d/CentOS-Extras.repo /etc/yum.repos.d/CentOS-Extras.repo.bak
sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
sed -i 's/#baseurl=/baseurl=/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
sed -i 's/http:\/\/mirror.centos.org/https:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-Extras.repo
cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
cp /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.bak
cp /etc/yum.repos.d/epel-playground.repo /etc/yum.repos.d/epel-playground.repo.bak
sed -i 's/metalink=/#metalink=/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
sed -i 's/#baseurl=/baseurl=/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
sed -i 's/https:\/\/download.fedoraproject.org\/pub/https:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-playground.repo
fi
if [[ version == 7 ]]; then
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
fi
yum install -y vim zsh git lrzsz wget
systemctl stop firewalld
systemctl disable firewalld
# 關閉selinux
setenforce 0
# 永久關閉
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
mkdir ~/.pip
touch ~/.pip/pip.conf
cat > ~/.pip/pip.conf <<-EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
read -p "請輸入hostname 名稱 :" host
hostnamectl --static set-hostname $host
# install oh my zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
cat > ~/.oh-my-zsh/themes/myrobbyrussell.zsh-theme <<-EOF
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[magenta]%}%n%{$fg_bold[cyan]%}@%{$fg[green]%}%m %{$fg_bold[green]%}%p%{$fg[cyan]%}%~ %{$fg_bold[blue]%}\$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$fg_bold[blue]%}? %{$reset_color%}~#: '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
EOF
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="agnoster"/g' ~/.zshrc
# chsh -s /usr/bin/zsh 更換使用的shell 程序為zsh