一文搞定linux N個服務的搭建

一文搞定 N個服務的搭建

搭建開發測試環境很是麻煩,公司的開發測試服務器中毒作數據恢復,順帶整理下搭建的方式。css

本人是程序員,linux系統知識比較薄弱,故系統的安全方面本文未涉及,請酌情作安全策略html

原本是內網服務器,用frp暴露到了公網,致使被挖礦。。感受frp仍是不安全,如今只能在須要穿透的時候開下,其餘時候java

關閉。node

mysql數據備份和恢復參考:juejin.im/post/5d8b85…mysql

SpringBoot整合jwt和mybatis-plus的腳手架項目linux

更新日誌

  • 2019-10-27 添加修改hostname的方式
  • 2019-10-25 添加elastic search的安裝方式
  • 2019-10-23 添加docker安裝RabbitMq
  • 2019-10-23 添加docker的安裝方式
  • 2019-10-14 添加nginx安裝後綁定80端口衝突的解決方式
  • 2019-10-13 添加zookeeper的安裝方式

基本配置

安裝基本命令

有些命令可能未默認安裝,若是發現命令沒法使用,再經過下面的方式進行安裝。nginx

安裝ifconfig

centos 7中自帶的查看網絡的命令是: ip addrgit

若是仍是想要 ifconfig程序員

安裝net-toolsgithub

yum install net-tools

安裝vim

yum install vim

網絡配置

若是是虛擬機模式,VM box的網絡模式修改成橋接

修改hostname

  1. 查看hostname
[root@zhirui-base ~]# hostnamectl  
   Static hostname: zhirui-base
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c9cea1249eaf47379236a0ed4e371584
           Boot ID: 94a2959e5c684c94ad6e4e4b096af282
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-957.el7.x86_64
      Architecture: x86-64
複製代碼

只查看靜態、瞬態或靈活主機名,分別使用「--static」,「--transient」或「--pretty」選項

  1. 修改hostname且退出鏈接
[root@zhirui-base ~]# hostnamectl --static set-hostname zhirui-test
[root@zhirui-base ~]# exit
logout
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.1.234) at 12:33:40.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 
複製代碼

若是你只想修改特定的主機名(靜態,瞬態或靈活),你可使用「--static」,「--transient」或「--pretty」選項。

  1. 從新連上查看hostname
Connecting to 192.168.1.234:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Sun Oct 27 12:29:20 2019 from 192.168.1.119
[root@zhirui-test ~]# hostnamectl --static
zhirui-test
[root@zhirui-test ~]# hostnamectl
   Static hostname: zhirui-test
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c9cea1249eaf47379236a0ed4e371584
           Boot ID: 94a2959e5c684c94ad6e4e4b096af282
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-957.el7.x86_64
      Architecture: x86-64
[root@zhirui-test ~]# 
複製代碼
  1. 修改hosts
[root@zhirui-test ~]# vim /etc/hosts
127.0.0.1      zhirui-test  localhost
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain
::1        localhost localhost.localdomain localhost6 localhost6.localdomai
複製代碼

在修改靜態/瞬態主機名時,任何特殊字符或空白字符會被移除,而提供的參數中的任何大寫字母會自動轉化爲小寫。一旦修改了靜態主機名,/etc/hostname 將被自動更新。然而,/etc/hosts 不會更新以保存所作的修改,因此你每次在修改主機名後必定要手動更新/etc/hosts,以後再重啓CentOS 7。不然系統再啓動時會很慢。

修改ip地址

命令爲:

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
複製代碼

修改成以下便可,而後重啓網卡service network restart

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"                   ###修改成static模式才能配置ip,默認是dhcp模式
IPADDR="192.168.1.254"               ###網卡IP地址
BROADCAST-"192.168.1.255"            ###子網廣播地址
GATEWAY="192.168.1.1"				 ###網關地址
NETMASK="255.255.255.0"				 ###網卡對應網絡掩碼
DNS1="192.168.1.1"					 ###DNS地址
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="enp0s3"
UUID="226a0768-3a2f-4485-9694-d8fea85694ad"
DEVICE="enp0s3"
ONBOOT="yes"            #系統啓動時是否設置此網絡接口,設置爲yes時,系統啓動時激活此設備。默認設置爲yes。
複製代碼

修改dns

1) vi /etc/resolv.conf
[root@localhost ~]# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1        #本機的網關地址(路由器的地址),在ip配置的時候有指定
nameserver 114.114.114.114    #其餘dns
naemserver 1.1.1.1

search localdomain
複製代碼
3)確保可用DNS解析

[root@localhost Desktop]# grep hosts /etc/nsswitch.conf

配置更新源

配置更新源爲阿里源

新建sourceSet.sh文件,貼上以下代碼執行便可:

chmod 775 sourceSet.sh

#!/bin/bash
#########################################
#Function: update source
#Usage: bash update_source.sh
#Author: Customer service department
#Company: Alibaba Cloud Computing
#Version: 5.0
#########################################

check_os_release()
{
  while true
  do
    os_release=$(grep "Red Hat Enterprise Linux Server release" /etc/issue 2>/dev/null)
    os_release_2=$(grep "Red Hat Enterprise Linux Server release" /etc/redhat-release 2>/dev/null)
    if [ "$os_release" ] && [ "$os_release_2" ]
    then
      if echo "$os_release"|grep "release 5" >/dev/null 2>&1
      then
        os_release=redhat5
        echo "$os_release"
      elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
      then
        os_release=redhat6
        echo "$os_release"
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    os_release=$(grep "Aliyun Linux release" /etc/issue 2>/dev/null)
    os_release_2=$(grep "Aliyun Linux release" /etc/aliyun-release 2>/dev/null)
    if [ "$os_release" ] && [ "$os_release_2" ]
    then
      if echo "$os_release"|grep "release 5" >/dev/null 2>&1
      then
        os_release=aliyun5
        echo "$os_release"
      elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
      then
        os_release=aliyun6
        echo "$os_release"
      elif echo "$os_release"|grep "release 7" >/dev/null 2>&1
      then
        os_release=aliyun7
        echo "$os_release"
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    os_release_2=$(grep "CentOS" /etc/*release 2>/dev/null)
    if [ "$os_release_2" ]
    then
      if echo "$os_release_2"|grep "release 5" >/dev/null 2>&1
      then
        os_release=centos5
        echo "$os_release"
      elif echo "$os_release_2"|grep "release 6" >/dev/null 2>&1
      then
        os_release=centos6
        echo "$os_release"
      elif echo "$os_release_2"|grep "release 7" >/dev/null 2>&1
      then
        os_release=centos7
        echo "$os_release"
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    os_release=$(grep -i "ubuntu" /etc/issue 2>/dev/null)
    os_release_2=$(grep -i "ubuntu" /etc/lsb-release 2>/dev/null)
    if [ "$os_release" ] && [ "$os_release_2" ]
    then
      if echo "$os_release"|grep "Ubuntu 10" >/dev/null 2>&1
      then
        os_release=ubuntu10
        echo "$os_release"
      elif echo "$os_release"|grep "Ubuntu 12.04" >/dev/null 2>&1
      then
        os_release=ubuntu1204
        echo "$os_release"
      elif echo "$os_release"|grep "Ubuntu 12.10" >/dev/null 2>&1
      then
        os_release=ubuntu1210
        echo "$os_release"
     elif echo "$os_release"|grep "Ubuntu 14.04" >/dev/null 2>&1
     then
        os_release=ubuntu1204
        echo "$os_release" 
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    os_release=$(grep -i "debian" /etc/issue 2>/dev/null)
    os_release_2=$(grep -i "debian" /proc/version 2>/dev/null)
    if [ "$os_release" ] && [ "$os_release_2" ]
    then
      if echo "$os_release"|grep "Linux 6" >/dev/null 2>&1
      then
        os_release=debian6
        echo "$os_release"
      elif echo "$os_release"|grep "Linux 7" >/dev/null 2>&1
      then
        os_release=debian7
        echo "$os_release"
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    os_release=$(grep -i "opensuse" /etc/issue 2>/dev/null)
    os_release_2=$(grep -i "opensuse" /etc/*release 2>/dev/null)
    if [ "$os_release" ] && [ "$os_release_2" ]
    then
      if echo "$os_release"|grep "openSUSE 13.1" >/dev/null 2>&1
      then
        os_release=opensuse1301
        echo "$os_release"
      else
        os_release=""
        echo "$os_release"
      fi
      break
    fi
    break
    done
}

modify_aliyun5_yum()
{
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
  sed -i 's/\$releasever/5/' /etc/yum.repos.d/CentOS-Base.repo
  wget -qO /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
  yum clean metadata
  yum makecache
  cd ~
}

modify_rhel5_yum()
{
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
  wget -qO /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
  yum clean metadata
  yum makecache
  cd ~
}

modify_rhel6_yum()
{
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  wget -qO /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  yum clean metadata
  yum makecache
  cd ~
}

modify_rhel7_yum()
{
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  wget -qO /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  yum clean metadata
  yum makecache
  cd ~
}

update_ubuntu10_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#ubuntu
deb http://cn.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
#163
deb http://mirrors.163.com/ubuntu/ maverick main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ maverick main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ maverick-updates universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ maverick-updates universe main multiverse restricted
#lupaworld
deb http://mirror.lupaworld.com/ubuntu/ maverick main universe restricted multiverse
deb-src http://mirror.lupaworld.com/ubuntu/ maverick main universe restricted multiverse
deb http://mirror.lupaworld.com/ubuntu/ maverick-security universe main multiverse restricted
deb-src http://mirror.lupaworld.com/ubuntu/ maverick-security universe main multiverse restricted
deb http://mirror.lupaworld.com/ubuntu/ maverick-updates universe main multiverse restricted
deb http://mirror.lupaworld.com/ubuntu/ maverick-proposed universe main multiverse restricted
deb-src http://mirror.lupaworld.com/ubuntu/ maverick-proposed universe main multiverse restricted
deb http://mirror.lupaworld.com/ubuntu/ maverick-backports universe main multiverse restricted
deb-src http://mirror.lupaworld.com/ubuntu/ maverick-backports universe main multiverse restricted
deb-src http://mirror.lupaworld.com/ubuntu/ maverick-updates universe main multiverse restricted
EOF
apt-get update
}

update_ubuntu1204_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#12.04
deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
EOF
apt-get update
}

update_ubuntu1210_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#12.10
deb http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
EOF
apt-get update
}

update_ubuntu1404_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#14.04
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
EOF
apt-get update
}

update_debian6_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#debian6
deb http://mirrors.aliyun.com/debian/ squeeze main non-free contrib
deb http://mirrors.aliyun.com/debian/ squeeze-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ squeeze main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ squeeze-proposed-updates main non-free contrib
EOF
apt-get update
}

update_debian7_apt_source()
{
echo -e "\033[40;32mBackup the original configuration file,new name and path is /etc/apt/sources.list.back.\n\033[40;37m"
cp -fp /etc/apt/sources.list /etc/apt/sources.list.back
cat > /etc/apt/sources.list <<EOF
#debian7
deb http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
EOF
apt-get update
}

update_opensuse_source()
{
  mv /etc/zypp/repos.d/* /tmp/
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/13.1/repo/oss/ openSUSE-13.1-Oss
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/13.1/repo/non-oss/ openSUSE-13.1-Non-Oss
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/13.1/ openSUSE-13.1-Update-Oss
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/13.1-non-oss/ openSUSE-13.1-Update-Non-Oss
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/13.1/repo/oss/ openSUSE-13.1-Oss-aliyun
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/13.1/repo/non-oss/ openSUSE-13.1-Non-Oss-aliyun  zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/13.1/ openSUSE-13.1-Update-Oss-aliyun
  zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/13.1-non-oss/ openSUSE-13.1-Update-Non-Oss-aliyun
}
 ####################Start###################
#check lock file ,one time only let the script run one time 
LOCKfile=/tmp/.$(basename $0)
if [ -f "$LOCKfile" ]
then
  echo -e "\033[1;40;31mThe script is already exist,please next time to run this script.\n\033[0m"
  exit
else
  echo -e "\033[40;32mStep 1.No lock file,begin to create lock file and continue.\n\033[40;37m"
  touch $LOCKfile
fi
 #check user
if [ $(id -u) != "0" ]
then
  echo -e "\033[1;40;31mError: You must be root to run this script, please use root to install this script.\n\033[0m"
  rm -rf $LOCKfile
  exit 1
fi
echo -e "\033[40;32mStep 2.Begin to check the OS issue.\n\033[40;37m"
os_release=$(check_os_release)
if [ "X$os_release" == "X" ]
then
  echo -e "\033[1;40;31mThe OS does not identify,So this script is not executede.\n\033[0m"
  rm -rf $LOCKfile
  exit 0
else
  echo -e "\033[40;32mThis OS is $os_release.\n\033[40;37m"
fi

echo -e "\033[40;32mStep 3.Begin to modify the source configration file and update.\n\033[40;37m"
case "$os_release" in
aliyun5)
  modify_aliyun5_yum
  ;;
redhat5|centos5)
  modify_rhel5_yum
  ;;
redhat6|centos6|aliyun6)
  modify_rhel6_yum
  ;;
centos7|aliyun7)
  modify_rhel7_yum
  ;;
ubuntu10)
  update_ubuntu10_apt_source
  ;;
ubuntu1204)
  update_ubuntu1204_apt_source
  ;;
ubuntu1210)
  update_ubuntu1210_apt_source
  ;;
ubuntu1404)
  update_ubuntu1404_apt_source
  ;;
debian6)
  update_debian6_apt_source
  ;;
debian7)
  update_debian7_apt_source
  ;;
opensuse1301)
  update_opensuse_source
  ;;
esac
echo -e "\033[40;32mSuccess,exit now!\n\033[40;37m"
rm -rf $LOCKfile

複製代碼

開發環境

JDK

下載jdk

最新jdk1.8.0_211我已經上傳到網盤:

連接:pan.baidu.com/s/1B9DRL5iZ… 提取碼:5e92 複製這段內容後打開百度網盤手機App,操做更方便哦)

上傳和解壓到該路徑: /usr/local/base/jdk1.8.0_211

設置環境變量:

vi /etc/profile 在最後添加以下內容:

#java environment
export JAVA_HOME=/usr/local/base/jdk1.8.0_211
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
複製代碼
從新加載環境變量:
[root@izwz9hy3mj62nle7573jv5z jdk1.8.0_181]# source /etc/profile
[root@izwz9hy3mj62nle7573jv5z jdk1.8.0_181]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
複製代碼

卸載jdk:

若是須要卸載,那麼刪除環境變量和jdk解壓後的目錄便可。

安裝服務

elastic search(ES)

centos下安裝

  1. jdk環境配置(參考上文)
  2. 安裝
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
tar -xvf elasticsearch-6.2.4.tar.gz
複製代碼

咱們將解壓後elasticsearch-6.2.4的路徑稱爲${elasticsearch},後面會用到。
3. 啓動
在root下對${elasticsearch}/bin目錄權限設置

chmod 775 *
複製代碼

添加用戶"elastic"

adduser elastic
複製代碼

解壓目錄受權給"elastic"用戶

chown -R elastic elasticsearch-6.2.4
複製代碼

su到elastic用戶

su elastic
複製代碼

執行${elasticsearch}/bin/elasticsearch 啓動成功,節點名爲wib4w5f,啓動如圖所示:

啓動成功, 此時這個窗口不能關閉, 若是關閉, 那麼elastic會關閉掉。
經過 ps -ef | grep elastic查看進程信息:

[root@localhost ~]# ps -ef | grep elastic
root     24494 24002  0 17:54 pts/0    00:00:00 su elastic
elastic  24495 24494  0 17:54 pts/0    00:00:00 bash
root     24670 24521  0 18:03 pts/0    00:00:00 su elastic
elastic  24671 24670  0 18:03 pts/0    00:00:00 bash
elastic  24700 24671  2 18:04 pts/0    00:00:10 /apps/jdk8/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch.KrRABQX8 -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/usr/local/elasticsearch-6.2.4 -Des.path.conf=/usr/local/elasticsearch-6.2.4/config -cp /usr/local/elasticsearch-6.2.4/lib/* org.elasticsearch.bootstrap.Elasticsearch
root     24876 24858  0 18:11 pts/1    00:00:00 grep --color=auto elastic
複製代碼
  1. 還能夠指定節點名稱啓動
./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name
複製代碼

啓動成功:

  1. 集羣模式(未測試)
    安裝後,每一個節點啓用各自的啓動方式便可。
    舉例,兩個節點:
  • 節點1啓動方式:
./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name01
複製代碼
  • 節點2啓動方式:
./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name02
複製代碼

docker

docker版本介紹: docker-io 是之前早期的版本,版本號是 1.,最新版是 1.13,而 docker-ce 是新的版本,分爲社區版 docker-ce 和企業版 docker-ee,版本號是 17. ,最新版是 17.12。企業版本須要付費。

安裝的前提條件

  1. 配置了靜態ip地址,且配置了dns。若是未配置,請參考
  2. 卸載掉舊版本,卸載方式:
$ sudo yum remove docker \
               docker-client \
               docker-client-latest \
               docker-common \
               docker-latest \
               docker-latest-logrotate \
               docker-logrotate \
               docker-selinux \
               docker-engine-selinux \
               docker-engine
複製代碼

卸載不會刪除掉docker的數據,能夠數據默認在/var/lib/docker目錄下。

安裝一些必要的系統工具:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
複製代碼

添加軟件源信息:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
複製代碼

執行如下命令,更新yum的包索引

sudo yum makecache fast
複製代碼

安裝docker

yum -y install docker-ce
複製代碼

查看安裝後的版本

docker version 
複製代碼

啓動docker

systemctl start docker
複製代碼

rabbitmq(docker方式)

進入docker hub鏡像倉庫地址:hub.docker.com/

搜索須要的鏡像

選擇一個後綴帶management的版本,有web管理頁面

拉取鏡像

docker pull rabbitmq:3.8-rc-management
複製代碼

使用docker images查看

啓動rabbitmq

docker run -d --name rabbitmq3.8.2 -p 5672:5672 -p 15672:15672 -v /data:/var/lib/rabbitmq --hostname myRabbit -e RABBITMQ_DEFAULT_VHOST=my_vhost  -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --privileged=true docker.io/rabbitmq:3.8-rc-management
複製代碼

說明: -d 後臺運行容器; --name 指定容器名; -p 指定服務運行的端口(5672:應用訪問端口;15672:控制檯Web端口號); -v 映射目錄或文件; --hostname 主機名(RabbitMQ的一個重要注意事項是它根據所謂的 「節點名稱」 存儲數據,默認爲主機名); -e 指定環境變量;(RABBITMQ_DEFAULT_VHOST:默認虛擬機名;RABBITMQ_DEFAULT_USER:默認的用戶名;RABBITMQ_DEFAULT_PASS:默認用戶名的密碼); --privileged=true 作了-v目錄映射,可能會致使沒權限。

使用命令:docker ps 查看正在運行容器

[root@test1 data]# docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS                                                                                        NAMES
872e75cf838b        docker.io/rabbitmq:3.8-rc-management   "docker-entrypoint..."   4 minutes ago       Up 4 minutes        4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   rabbitmq3.8.2
複製代碼

打開web管理端:http://youip:15672

須要配置權限,登錄帳號密碼在docker容器啓動的時候有指定爲admin/admin。 點擊右邊的Virtual Hosts添加一個爲/Virtual Hosts

zookeeper

在安裝zookeeper以前須要先安裝好jdk,由於zookeeper啓動須要jdk支持

下載

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz
複製代碼

解壓

tar -xf apache-zookeeper-3.5.5-bin.tar.gz
複製代碼

配置

zookeeper的配置文件是 zoo.cfg,須要先建立

[root@localhost ~]# cd apache-zookeeper-3.5.5-bin/conf/
[root@localhost conf]# ll
total 12
-rw-r--r--. 1 2002 2002  535 Feb 15  2019 configuration.xsl
-rw-r--r--. 1 2002 2002 2712 Apr  2  2019 log4j.properties
-rw-r--r--. 1 2002 2002  922 Feb 15  2019 zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
複製代碼

而後進行以下配置:

tickTime=2000    ##Zookeeper最小時間單元,單位毫秒(ms),默認值爲3000
dataDir=/var/lib/zookeeper    ##Zookeeper服務器存儲快照文件的目錄,必須配置
dataLogDir=/var/lib/log     ##Zookeeper服務器存儲事務日誌的目錄,默認爲dataDir
clientPort=2181    ##服務器對外服務端口,通常設置爲2181
initLimit=5    ##Leader服務器等待Follower啓動並完成數據同步的時間,默認值10,表示tickTime的10倍
syncLimit=2    ##Leader服務器和Follower之間進行心跳檢測的最大延時時間,默認值5,表示tickTime的5倍
複製代碼

啓動

進入bin命令下,而後啓動

[root@localhost conf]# cd ../bin
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
複製代碼

集羣安裝參考:www.cnblogs.com/cyfonly/p/5…

nginx

添加源

# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
複製代碼

安裝

yum install -y nginx
複製代碼

查看安裝後的目錄

# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz
複製代碼
  • Nginx配置路徑:/etc/nginx/
  • 執行程序路徑:/usr/sbin/nginx
  • PID目錄:/var/run/nginx.pid
  • 錯誤日誌:/var/log/nginx/error.log
  • 訪問日誌:/var/log/nginx/access.log
  • 默認站點目錄:/usr/share/nginx/html

須要主要的是配置路徑執行程序路徑

啓停命令

#啓動
[root@nginx]#/usr/sbin/nginx -c /etc/nginx/nginx.conf
#檢測配置
[root@nginx]#/usr/sbin/nginx -c /etc/nginx/nginx.conf -t
#重啓
[root@nginx]# /usr/sbin/nginx -s reload
[root@nginx]# /usr/sbin/nginx -c /etc/nginx/nginx.conf -s reload

複製代碼

測試

若是顯示錶示成功

[root@zhirui-base nginx]# curl localhost:80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Fedora</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
       ...
複製代碼

固然也能夠在瀏覽器打開網址測試。

記得防火牆放開端口!,CentOS7防火牆操做參考:juejin.im/post/5d3b26…

nginx配置文件配置參考:

juejin.im/post/5d7e3f…

juejin.im/post/5d8190…

遇到的問題

第一次配置80端口後臺提示衝突問題

在安裝後修改配置文件,添加了80端口的監聽

[root@zhirui-base nginx]# vim /etc/nginx/nginx.conf
server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main; 
        location / {
            root /wms/website;
            index  index.html index.htm;
        }
    }

複製代碼

經過命令/usr/sbin/nginx -c /etc/nginx/nginx.conf -t檢測,報錯以下:

[root@zhirui-base ~]# /usr/sbin/nginx -c /etc/nginx/nginx.conf -s reload
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
複製代碼

解決方式: 經過grep -r localhost /etc/nginx/命令查看衝突的地方,發現一個default.conf下也綁定了80端口。

[root@zhirui-base ~]# grep -r localhost /etc/nginx/
/etc/nginx/conf.d/default.conf:    server_name  localhost;
Binary file /etc/nginx/.nginx.conf.swp matches
/etc/nginx/nginx.conf:        server_name  localhost;
複製代碼

default.conf更名後再檢測和啓動nginx成功。

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
複製代碼

mysql

安裝:

這裏安裝的是mariadb,mariadb和mysql是能夠通用的,是mysql的開源分支,比mysql更加有前景。

# yum install mariadb-server mariadb 
複製代碼

配置配置文件:

#vim /etc/my.cnf
[mysqld]
character-set-server = utf8    #設置默認編碼, 在[mysqld]下配置,[client][mysql]不配置!!!
lower_case_table_names = 1   #配置大小寫不敏感, 查詢時不區分大小寫, 1:不區分, 0:區分
group_concat_max_len = 204800  #修改最大返回字符串的長度
複製代碼

啓停操做:

systemctl start mariadb  #啓動MariaDB
systemctl stop mariadb  #中止MariaDB
systemctl restart mariadb  #重啓MariaDB
systemctl enable mariadb  #設置開機啓動
複製代碼

配置賬號和權限

第一次登錄的時候不須要密碼

# mysql -uroot -p
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
update user set password=password("123456") where user='root';
flush privileges;
exit
複製代碼

添加端口到防火牆,並重啓防火牆:

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
複製代碼

若是須要卸載使用以下方式:

參考:www.cnblogs.com/javahr/p/92…

  1. 使用如下命令查看當前安裝mysql狀況,查找之前是否裝有mysql
`rpm -qa|grep -i mysql`
複製代碼

  能夠看到以下圖的所示:

img

  顯示以前安裝了:

​    MySQL-client-5.5.25a-1.rhel5

​   MySQL-server-5.5.25a-1.rhel5

  1. 中止mysql服務、刪除以前安裝的mysql

  刪除命令:rpm -e –nodeps 包名

&emsp;&emsp;rpm -ev --nodeps MySQL-client-5.5.25a-1.rhel5
&emsp;&emsp;rpm -ev --nodeps MySQL-server-5.5.25a-1.rhel5
複製代碼
  1. 查找以前老版本mysql的目錄、而且刪除老版本mysql的文件和庫**
`find / -name mysql`
複製代碼

  查找結果以下:

`find / -name mysql` `/var/lib/mysql``/var/lib/mysql/mysql``/usr/lib64/mysql  `
複製代碼

  刪除對應的mysql目錄

`rm -rf /var/lib/mysql``rm -rf /var/lib/mysql``rm -rf /usr/lib64/mysql`
複製代碼

  具體的步驟如圖:查找目錄並刪除

img

  **注意:**卸載後/etc/my.cnf不會刪除,須要進行手工刪除

`rm -rf /etc/my.cnf`
複製代碼
  1. 再次查找機器是否安裝mysql
`rpm -qa|grep -i mysql`
複製代碼

若是是yum命令安裝的還須要執行以下命令:

yum remove mariadb*

yum remove mysql*

redis

安裝一個倉庫

爲了可以實現yum命令安裝,故先須要安裝該倉庫

yum install epel-release
複製代碼

安裝redis數據庫

`yum ``install` `redis`
複製代碼

安裝完畢後,使用下面的命令啓動redis服務

`# 啓動redis``service redis start``# 中止redis``service redis stop``# 查看redis運行狀態``service redis status``# 查看redis進程``ps` `-ef | ``grep` `redis`
複製代碼

設置redis爲開機自動啓動

`chkconfig redis on`
複製代碼

進入redis服務

`# 進入本機redis``redis-cli``# 列出全部key``keys *`
複製代碼

修改配置

打開配置文件
`vi` `/etc/redis``.conf`
複製代碼
修改默認端口

查找 port 6379 修改成相應端口便可

修改默認密碼

查找 requirepass foobared 將 foobared 修改成你的密碼

容許遠程訪問
# 找到 bind 127.0.0.1 將其註釋
# 找到 protected-mode yes 將其改成
protected-mode no
複製代碼

nexus

安裝

官網地址:www.sonatype.com/download-os…

# cd /opt
# wget https://download.sonatype.com/nexus/3/nexus-3.2.0-01-unix.tar.gz
# tar zxvf nexus-3.2.0-01-unix.tar.gz
複製代碼

解壓後,在當前目錄中除了nexus-3.2.0-01還有一個sonatyoe-work目錄,用戶存放倉庫數據的,可根據須要將其改成其餘路徑,或使用軟連接的方式。 這裏說下經過改配置文件的方式,將其改成其餘路徑吧。 查看nexus-3.2.0-01/bin/nexus.vmoptions文件:

# vim /opt/nexus-3.2.0-01/bin/nexus.vmoptions
複製代碼

分別對應着如下屬性,有需求能夠修改:

-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=../sonatype-work/nexus3
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
複製代碼

sonatype-work/nexus3/etc的目錄下有個配置文件nexus.properties,能夠配置對應的ip地址和端口

用vim打開文件:

vim nexus.properties
複製代碼

默認是以下配置,若是ip衝突能夠按需修改端口等:

# Jetty section
# application-port=8081
# application-host=0.0.0.0
# nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
# nexus-context-path=/
...
複製代碼

也能夠在nexus-3.2.0-01/bin/nexus.rc上指定新的賬號運行nexus。

編輯nexus.rc:

run_as_user="nexus"
複製代碼

那麼linux系統中須要添加一個叫作nexus的用戶,用來啓動nexus。

配置

訪問nexus:http://serverip:8081,配置以前須要先登陸

默認賬號是admin,默認密碼是admin123

配置maven-central

修改central倉庫的遠程倉庫地址(建議修改爲spring或者阿里雲的倉庫)

倉庫地址以下:

1.http://repo1.maven.org/maven2 (官方,速度通常)
2.http://maven.aliyun.com/nexus/content/repositories/central/ (阿里雲,速度快)
3.http://repository.jboss.com/maven2/
4.<https://repository.sonatype.org/content/groups/public/> 
5.http://mvnrepository.com/
複製代碼

修改後rebuild下index

配置第三方倉庫

該倉庫用於上傳私有jar用。

點擊Create repository填寫名稱3rd-repo,其餘默認便可。

配置maven-public

maven-public是nexus的中心組,咱們使用的nexus的url填寫的就是這個組的地址。因此咱們須要在這裏將剛剛建立的倉庫添加到這個組裏面。

選中,添加到右邊便可:

maven部署到nexus

我在這裏整理了幾種部署到maven的方式:juejin.im/post/5d8b7a…

git

安裝jinkens以前須要安裝git,直接用yum命令進行安裝

# yum install git
複製代碼

安裝後須要經過以下方式找到git程序位置,後面的jenkins須要使用。

# find / -name git
/usr/bin/git
複製代碼

能夠查看到git所在位置爲/usr/bin/git

查看git的版本

# git --version
git version 1.8.3.1
複製代碼

maven

安裝

安裝jinkens以前須要安裝maven

下載頁:maven.apache.org/download.cg…

下載和安裝:

wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
tar -zxf apache-maven-3.6.2-bin.tar.gz
mv apache-maven-3.6.2
cd apache-maven-3.6.2/conf
vim settings.xml 
複製代碼

settings.xml配置

在conf目錄下,有個settings.xml,在使用前須要進行配置。

若是配置後jenkins沒法構建,請參考:《maven配置:jenkins的生產環境

須要配置的幾個配置項:

  1. 配置下載jar的存儲路徑
<localRepository>/path/to/local/repo</localRepository>
複製代碼
  1. <mirrors> </mirrors>下配置倉庫地址

    我在jenkins構建的時候,同時配置了下面兩個倉庫,程序須要的私服私有jar一直跑去阿里雲下載,而後提示下載不下來。若是出現這種狀況,請只保留私服的倉庫地址試試。

<!-- 私服地址 -->
<mirror>
	<id>com.zhirui.group</id>
	<mirrorOf>central</mirrorOf>
	<name>com.zhirui.group</name>
	<url>http://192.168.1.254:8081/repository/maven-public/</url>
</mirror>
<!-- 阿里雲的倉庫地址 -->
<mirror>
	<id>alimaven</id>
	<name>aliyun maven</name>
	<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
	<mirrorOf>central</mirrorOf>
</mirror>
複製代碼

jenkins

jenkins安裝比較複雜,我另外寫了篇文章來詳細講解若是安裝和配置,點擊查看《jenkins自動部署Spring Cloud服務實戰

jira

jira安裝比較複雜,我另外寫了篇文章來詳細講解若是安裝和配置,點擊查看《jenkins自動部署Spring Cloud服務實戰

gitblit

幾大代碼管理工具對比,這裏只講gitblit:

官網地址:

www.gitblit.com/

安裝:

wget http://dl.bintray.com/gitblit/releases/gitblit-1.8.0.tar.gz
複製代碼

修改端口:

server.httpPort = 7000 
server.httpsPort = 7443
複製代碼

開始訪問

url:http://192.168.1.234:7000/

默認帳號密碼:admin/admin

frp

frp用於內網穿透用,能夠實如今公網訪問內網的服務。

下載

wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz
複製代碼

更多的版本下載:github.com/fatedier/fr…

服務器端

配置
# 配置和frp客戶端鏈接用
[common]
bind_port = 7000
token = javasea@frp

dashboard_port = 7557
#儀表板的用戶名和密碼都是可選的,若是沒有設置,默認是admin。
dashboard_user = admin
dashboard_pwd = javasea@frpdash
複製代碼
啓動
# frps -c frps.ini
複製代碼

客戶端

配置
# 配置和frp服務端鏈接用
[common]
server_addr = 120.xx.xx.166
server_port = 7000
token = zhirui@frp   #用於和服務器端認證
# mysql暴露到公網
[mysql]
type = tcp
local_port = 3306
remote_port = 7575
# gitblit暴露到公網
[gitblit]
type = tcp
local_port = 7000
remote_port = 7576

複製代碼
啓動
# frpc -c frpc.ini
複製代碼
管理頁面:

url: http://192.168.1.254:7557, 7557就是上面服務器端配置的dash端口。

相關文章
相關標籤/搜索