部署Ambari Server实战案例
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.准备三台虚拟机(需要自行安装jdk环境)
1>.角色分配
NameNode节点:
hdp101.yinzhengjie.org.cn
DataNode节点:
hdp101.yinzhengjie.org.cn
hdp102.yinzhengjie.org.cn
hdp103.yinzhengjie.org.cn
MySQL服务器:
hdp101.yinzhengjie.org.cn
YUM源仓库服务器:
hdp101.yinzhengjie.org.cn
2>.内存分配(根据物理机情况合理分配即可)
hdp101.yinzhengjie.org.cn: 10G-16G hdp102.yinzhengjie.org.cn: 3G-6G hdp103.yinzhengjie.org.cn: 3G-6G
二.配置SSH免密码登录
1>.生成秘钥并配置与本机的免密登录
[root@hdp101.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa Generating public/private rsa key pair. Created directory ‘/root/.ssh‘. Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:1q/IHVpogVivEj03C8ef3kUpJuDsGgaPT+PU5m8aycY root@hdp101.yinzhengjie.org.cn The key‘s randomart image is: +---[RSA 2048]----+ | | | | | . . | | + * o . | | + = S o o o | | = % B = o | | o O E = . . | | B X B.+ . | | + *+= . | +----[SHA256]-----+ [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll ~/.ssh/id_rsa -rw------- 1 root root 1679 Jan 21 02:37 /root/.ssh/id_rsa [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
2>.配置hdp101.yinzhengjie.org.cn节点到其他节点免密登陆
[root@hdp101.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp101.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘hdp101.yinzhengjie.org.cn (172.200.1.101)‘ can‘t be established. ECDSA key fingerprint is SHA256:y6iS5ipSyWSGRmgcjivbWhd78pKfrcuQHeBPd5H9/U8. ECDSA key fingerprint is MD5:da:0f:2a:93:c0:d4:6e:7e:13:16:61:f1:93:a7:38:01. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp101.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp101.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ssh hdp101.yinzhengjie.org.cn Last login: Tue Jan 21 02:35:51 2020 from 172.200.0.1 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) root pts/1 2020-01-21 02:39 (172.200.1.101) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# exit logout Connection to hdp101.yinzhengjie.org.cn closed. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp102.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘hdp102.yinzhengjie.org.cn (172.200.1.102)‘ can‘t be established. ECDSA key fingerprint is SHA256:y6iS5ipSyWSGRmgcjivbWhd78pKfrcuQHeBPd5H9/U8. ECDSA key fingerprint is MD5:da:0f:2a:93:c0:d4:6e:7e:13:16:61:f1:93:a7:38:01. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp102.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp102.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ssh hdp102.yinzhengjie.org.cn Last login: Tue Jan 21 02:36:16 2020 from 172.200.0.1 [root@hdp102.yinzhengjie.org.cn ~]# [root@hdp102.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:24 root pts/0 2020-01-21 02:36 (172.200.0.1) root pts/1 2020-01-21 02:40 (172.200.1.101) [root@hdp102.yinzhengjie.org.cn ~]# [root@hdp102.yinzhengjie.org.cn ~]# exit logout Connection to hdp102.yinzhengjie.org.cn closed. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp103.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘hdp103.yinzhengjie.org.cn (172.200.1.103)‘ can‘t be established. ECDSA key fingerprint is SHA256:y6iS5ipSyWSGRmgcjivbWhd78pKfrcuQHeBPd5H9/U8. ECDSA key fingerprint is MD5:da:0f:2a:93:c0:d4:6e:7e:13:16:61:f1:93:a7:38:01. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp103.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp103.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ssh hdp103.yinzhengjie.org.cn Last login: Tue Jan 21 02:36:38 2020 from 172.200.0.1 [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) root pts/1 2020-01-21 02:43 (172.200.1.101) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# exit logout Connection to hdp103.yinzhengjie.org.cn closed. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
3>.如果配置高可用的话,我们需要备用节点也需要到其它服务器进行免密登录(比如,我们选择hdp103.yinzhengjie.org.cn作为备用节点,则重复以上2个步骤即可)
[root@hdp103.yinzhengjie.org.cn ~]# ll ~/.ssh/ total 4 -rw------- 1 root root 412 Jan 21 02:43 authorized_keys [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa Generating public/private rsa key pair. Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Z4CmAntTl08/PU8yLhCE2baL8P2visnOmTrjY8iB7Fo root@hdp103.yinzhengjie.org.cn The key‘s randomart image is: +---[RSA 2048]----+ | +. | | o+o | |. . =.+. | | o ..+ o.+ . | |o.+ .o oS.= = . | |.o.o o o+ o * | |..Eo .. . . | | oo =o = .. | |o oo*O ...o. | +----[SHA256]-----+ [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ll ~/.ssh/ total 12 -rw------- 1 root root 412 Jan 21 02:43 authorized_keys -rw------- 1 root root 1675 Jan 21 02:44 id_rsa -rw-r--r-- 1 root root 412 Jan 21 02:44 id_rsa.pub [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]#
[root@hdp103.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp101.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘hdp101.yinzhengjie.org.cn (172.200.1.101)‘ can‘t be established. ECDSA key fingerprint is SHA256:y6iS5ipSyWSGRmgcjivbWhd78pKfrcuQHeBPd5H9/U8. ECDSA key fingerprint is MD5:da:0f:2a:93:c0:d4:6e:7e:13:16:61:f1:93:a7:38:01. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp101.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp101.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ssh hdp101.yinzhengjie.org.cn Last login: Tue Jan 21 02:39:07 2020 from 172.200.1.101 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:21 root pts/0 2020-01-21 02:35 (172.200.0.1) root pts/1 2020-01-21 02:45 (172.200.1.103) [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# exit logout Connection to hdp101.yinzhengjie.org.cn closed. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]#
[root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp102.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘hdp102.yinzhengjie.org.cn (172.200.1.102)‘ can‘t be established. ECDSA key fingerprint is SHA256:y6iS5ipSyWSGRmgcjivbWhd78pKfrcuQHeBPd5H9/U8. ECDSA key fingerprint is MD5:da:0f:2a:93:c0:d4:6e:7e:13:16:61:f1:93:a7:38:01. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp102.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp102.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ssh hdp102.yinzhengjie.org.cn Last login: Tue Jan 21 02:40:47 2020 from 172.200.1.101 [root@hdp102.yinzhengjie.org.cn ~]# [root@hdp102.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:24 root pts/0 2020-01-21 02:36 (172.200.0.1) root pts/1 2020-01-21 02:46 (172.200.1.103) [root@hdp102.yinzhengjie.org.cn ~]# [root@hdp102.yinzhengjie.org.cn ~]# exit logout Connection to hdp102.yinzhengjie.org.cn closed. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]#
[root@hdp103.yinzhengjie.org.cn ~]# ssh-copy-id root@hdp103.yinzhengjie.org.cn /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@hdp103.yinzhengjie.org.cn‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘root@hdp103.yinzhengjie.org.cn‘" and check to make sure that only the key(s) you wanted were added. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# ssh hdp103.yinzhengjie.org.cn Last login: Tue Jan 21 02:43:38 2020 from 172.200.1.101 [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) root pts/1 2020-01-21 02:48 (172.200.1.103) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# exit logout Connection to hdp103.yinzhengjie.org.cn closed. [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]# who root tty1 2020-01-21 02:27 root pts/0 2020-01-21 02:36 (172.200.0.1) [root@hdp103.yinzhengjie.org.cn ~]# [root@hdp103.yinzhengjie.org.cn ~]#
4>.安装ansible
[root@hdp101.yinzhengjie.org.cn ~]# yum -y install ansible Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirror.bit.edu.cn Resolving Dependencies --> Running transaction check ---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed --> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-six for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-setuptools for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-jinja2 for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: python-cryptography for package: ansible-2.4.2.0-2.el7.noarch --> Processing Dependency: PyYAML for package: ansible-2.4.2.0-2.el7.noarch --> Running transaction check ---> Package PyYAML.x86_64 0:3.10-11.el7 will be installed --> Processing Dependency: libyaml-0.so.2()(64bit) for package: PyYAML-3.10-11.el7.x86_64 ---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed ---> Package python-jinja2.noarch 0:2.7.2-4.el7 will be installed --> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-4.el7.noarch --> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-4.el7.noarch ---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed --> Processing Dependency: python2-pyasn1 for package: python-paramiko-2.1.1-9.el7.noarch ---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed ---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed --> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch ---> Package python-six.noarch 0:1.9.0-2.el7 will be installed ---> Package python2-cryptography.x86_64 0:1.7.2-2.el7 will be installed --> Processing Dependency: python-idna >= 2.0 for package: python2-cryptography-1.7.2-2.el7.x86_64 --> Processing Dependency: python-cffi >= 1.4.1 for package: python2-cryptography-1.7.2-2.el7.x86_64 --> Processing Dependency: python-ipaddress for package: python2-cryptography-1.7.2-2.el7.x86_64 --> Processing Dependency: python-enum34 for package: python2-cryptography-1.7.2-2.el7.x86_64 ---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed ---> Package sshpass.x86_64 0:1.06-2.el7 will be installed --> Running transaction check ---> Package libyaml.x86_64 0:0.1.4-11.el7_0 will be installed ---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed ---> Package python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 will be installed --> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch ---> Package python-cffi.x86_64 0:1.6.0-5.el7 will be installed --> Processing Dependency: python-pycparser for package: python-cffi-1.6.0-5.el7.x86_64 ---> Package python-enum34.noarch 0:1.0.4-1.el7 will be installed ---> Package python-idna.noarch 0:2.4-1.el7 will be installed ---> Package python-ipaddress.noarch 0:1.0.16-2.el7 will be installed ---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed ---> Package python2-pyasn1.noarch 0:0.1.9-7.el7 will be installed --> Running transaction check ---> Package python-backports.x86_64 0:1.0-8.el7 will be installed ---> Package python-pycparser.noarch 0:2.14-1.el7 will be installed --> Processing Dependency: python-ply for package: python-pycparser-2.14-1.el7.noarch --> Running transaction check ---> Package python-ply.noarch 0:3.4-11.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================= Installing: ansible noarch 2.4.2.0-2.el7 extras 7.6 M Installing for dependencies: PyYAML x86_64 3.10-11.el7 base 153 k libyaml x86_64 0.1.4-11.el7_0 base 55 k python-babel noarch 0.9.6-8.el7 base 1.4 M python-backports x86_64 1.0-8.el7 base 5.8 k python-backports-ssl_match_hostname noarch 3.5.0.1-1.el7 base 13 k python-cffi x86_64 1.6.0-5.el7 base 218 k python-enum34 noarch 1.0.4-1.el7 base 52 k python-httplib2 noarch 0.9.2-1.el7 extras 115 k python-idna noarch 2.4-1.el7 base 94 k python-ipaddress noarch 1.0.16-2.el7 base 34 k python-jinja2 noarch 2.7.2-4.el7 base 519 k python-markupsafe x86_64 0.11-10.el7 base 25 k python-paramiko noarch 2.1.1-9.el7 base 269 k python-passlib noarch 1.6.5-2.el7 extras 488 k python-ply noarch 3.4-11.el7 base 123 k python-pycparser noarch 2.14-1.el7 base 104 k python-setuptools noarch 0.9.8-7.el7 base 397 k python-six noarch 1.9.0-2.el7 base 29 k python2-cryptography x86_64 1.7.2-2.el7 base 502 k python2-jmespath noarch 0.9.0-3.el7 extras 39 k python2-pyasn1 noarch 0.1.9-7.el7 base 100 k sshpass x86_64 1.06-2.el7 extras 21 k Transaction Summary ======================================================================================================================================================= Install 1 Package (+22 Dependent packages) Total download size: 12 M Installed size: 60 M Downloading packages: (1/23): PyYAML-3.10-11.el7.x86_64.rpm | 153 kB 00:00:00 (2/23): libyaml-0.1.4-11.el7_0.x86_64.rpm | 55 kB 00:00:00 (3/23): python-backports-1.0-8.el7.x86_64.rpm | 5.8 kB 00:00:00 (4/23): python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm | 13 kB 00:00:00 (5/23): python-cffi-1.6.0-5.el7.x86_64.rpm | 218 kB 00:00:00 (6/23): python-enum34-1.0.4-1.el7.noarch.rpm | 52 kB 00:00:00 (7/23): python-idna-2.4-1.el7.noarch.rpm | 94 kB 00:00:00 (8/23): python-ipaddress-1.0.16-2.el7.noarch.rpm | 34 kB 00:00:00 (9/23): python-babel-0.9.6-8.el7.noarch.rpm | 1.4 MB 00:00:00 (10/23): python-markupsafe-0.11-10.el7.x86_64.rpm | 25 kB 00:00:00 (11/23): python-httplib2-0.9.2-1.el7.noarch.rpm | 115 kB 00:00:00 (12/23): python-passlib-1.6.5-2.el7.noarch.rpm | 488 kB 00:00:00 (13/23): python-pycparser-2.14-1.el7.noarch.rpm | 104 kB 00:00:00 (14/23): python-paramiko-2.1.1-9.el7.noarch.rpm | 269 kB 00:00:00 (15/23): python-jinja2-2.7.2-4.el7.noarch.rpm | 519 kB 00:00:00 (16/23): python-setuptools-0.9.8-7.el7.noarch.rpm | 397 kB 00:00:00 (17/23): python-six-1.9.0-2.el7.noarch.rpm | 29 kB 00:00:00 (18/23): python-ply-3.4-11.el7.noarch.rpm | 123 kB 00:00:00 (19/23): python2-pyasn1-0.1.9-7.el7.noarch.rpm | 100 kB 00:00:00 (20/23): python2-jmespath-0.9.0-3.el7.noarch.rpm | 39 kB 00:00:00 (21/23): python2-cryptography-1.7.2-2.el7.x86_64.rpm | 502 kB 00:00:00 (22/23): sshpass-1.06-2.el7.x86_64.rpm | 21 kB 00:00:00 (23/23): ansible-2.4.2.0-2.el7.noarch.rpm | 7.6 MB 00:00:03 ------------------------------------------------------------------------------------------------------------------------------------------------------- Total 3.7 MB/s | 12 MB 00:00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python2-pyasn1-0.1.9-7.el7.noarch 1/23 Installing : python-ipaddress-1.0.16-2.el7.noarch 2/23 Installing : python-six-1.9.0-2.el7.noarch 3/23 Installing : python-httplib2-0.9.2-1.el7.noarch 4/23 Installing : sshpass-1.06-2.el7.x86_64 5/23 Installing : libyaml-0.1.4-11.el7_0.x86_64 6/23 Installing : PyYAML-3.10-11.el7.x86_64 7/23 Installing : python-backports-1.0-8.el7.x86_64 8/23 Installing : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch 9/23 Installing : python-setuptools-0.9.8-7.el7.noarch 10/23 Installing : python-babel-0.9.6-8.el7.noarch 11/23 Installing : python-passlib-1.6.5-2.el7.noarch 12/23 Installing : python-ply-3.4-11.el7.noarch 13/23 Installing : python-pycparser-2.14-1.el7.noarch 14/23 Installing : python-cffi-1.6.0-5.el7.x86_64 15/23 Installing : python-markupsafe-0.11-10.el7.x86_64 16/23 Installing : python-jinja2-2.7.2-4.el7.noarch 17/23 Installing : python-idna-2.4-1.el7.noarch 18/23 Installing : python-enum34-1.0.4-1.el7.noarch 19/23 Installing : python2-cryptography-1.7.2-2.el7.x86_64 20/23 Installing : python-paramiko-2.1.1-9.el7.noarch 21/23 Installing : python2-jmespath-0.9.0-3.el7.noarch 22/23 Installing : ansible-2.4.2.0-2.el7.noarch 23/23 Verifying : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch 1/23 Verifying : python2-jmespath-0.9.0-3.el7.noarch 2/23 Verifying : python-enum34-1.0.4-1.el7.noarch 3/23 Verifying : python-setuptools-0.9.8-7.el7.noarch 4/23 Verifying : python-jinja2-2.7.2-4.el7.noarch 5/23 Verifying : python-six-1.9.0-2.el7.noarch 6/23 Verifying : python-idna-2.4-1.el7.noarch 7/23 Verifying : python-markupsafe-0.11-10.el7.x86_64 8/23 Verifying : python-ply-3.4-11.el7.noarch 9/23 Verifying : python-passlib-1.6.5-2.el7.noarch 10/23 Verifying : python-paramiko-2.1.1-9.el7.noarch 11/23 Verifying : python-babel-0.9.6-8.el7.noarch 12/23 Verifying : python-backports-1.0-8.el7.x86_64 13/23 Verifying : python-cffi-1.6.0-5.el7.x86_64 14/23 Verifying : python-pycparser-2.14-1.el7.noarch 15/23 Verifying : libyaml-0.1.4-11.el7_0.x86_64 16/23 Verifying : ansible-2.4.2.0-2.el7.noarch 17/23 Verifying : python-ipaddress-1.0.16-2.el7.noarch 18/23 Verifying : sshpass-1.06-2.el7.x86_64 19/23 Verifying : python-httplib2-0.9.2-1.el7.noarch 20/23 Verifying : python2-pyasn1-0.1.9-7.el7.noarch 21/23 Verifying : PyYAML-3.10-11.el7.x86_64 22/23 Verifying : python2-cryptography-1.7.2-2.el7.x86_64 23/23 Installed: ansible.noarch 0:2.4.2.0-2.el7 Dependency Installed: PyYAML.x86_64 0:3.10-11.el7 libyaml.x86_64 0:0.1.4-11.el7_0 python-babel.noarch 0:0.9.6-8.el7 python-backports.x86_64 0:1.0-8.el7 python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 python-cffi.x86_64 0:1.6.0-5.el7 python-enum34.noarch 0:1.0.4-1.el7 python-httplib2.noarch 0:0.9.2-1.el7 python-idna.noarch 0:2.4-1.el7 python-ipaddress.noarch 0:1.0.16-2.el7 python-jinja2.noarch 0:2.7.2-4.el7 python-markupsafe.x86_64 0:0.11-10.el7 python-paramiko.noarch 0:2.1.1-9.el7 python-passlib.noarch 0:1.6.5-2.el7 python-ply.noarch 0:3.4-11.el7 python-pycparser.noarch 0:2.14-1.el7 python-setuptools.noarch 0:0.9.8-7.el7 python-six.noarch 0:1.9.0-2.el7 python2-cryptography.x86_64 0:1.7.2-2.el7 python2-jmespath.noarch 0:0.9.0-3.el7 python2-pyasn1.noarch 0:0.1.9-7.el7 sshpass.x86_64 0:1.06-2.el7 Complete! [root@hdp101.yinzhengjie.org.cn ~]#
ansible基础命令使用可参考: https://www.cnblogs.com/yinzhengjie/p/10447587.html
5>.使用ansible工具验证免密配置
[root@hdp101.yinzhengjie.org.cn ~]# egrep -v "^#|^$" /etc/ansible/hosts [hdp] hdp[101:103].yinzhengjie.org.cn [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ansible hdp -m ping hdp102.yinzhengjie.org.cn | SUCCESS => { "changed": false, "ping": "pong" } hdp103.yinzhengjie.org.cn | SUCCESS => { "changed": false, "ping": "pong" } hdp101.yinzhengjie.org.cn | SUCCESS => { "changed": false, "ping": "pong" } [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# ansible hdp -m shell -a ‘ln -s /yinzhengjie/softwares/jdk1.8.0_201/bin/jps /usr/local/bin/‘ [WARNING]: Consider using file module with state=link rather than running ln hdp102.yinzhengjie.org.cn | SUCCESS | rc=0 >> hdp101.yinzhengjie.org.cn | SUCCESS | rc=0 >> hdp103.yinzhengjie.org.cn | SUCCESS | rc=0 >> [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# ansible hdp -m shell -a ‘jps‘ hdp102.yinzhengjie.org.cn | SUCCESS | rc=0 >> 5529 Jps hdp103.yinzhengjie.org.cn | SUCCESS | rc=0 >> 5761 Jps hdp101.yinzhengjie.org.cn | SUCCESS | rc=0 >> 6393 Jps [root@hdp101.yinzhengjie.org.cn ~]#
三. 部署MySQL
1>.启用yum缓存(可以保存下载的安装包便于后期自制yum仓库)
[root@hdp101.yinzhengjie.org.cn ~]# grep keepcache /etc/yum.conf keepcache=0 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# sed -r -i ‘s#(keepcache=)0#\11#g‘ /etc/yum.conf [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# grep keepcache /etc/yum.conf keepcache=1 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
2>.安装MySQL8.0软件源
[root@hdp101.yinzhengjie.org.cn ~]# ll total 0 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm --2020-01-21 03:13:48-- https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following] --2020-01-21 03:13:50-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 23.60.72.128 Connecting to repo.mysql.com (repo.mysql.com)|23.60.72.128|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 26024 (25K) [application/x-redhat-package-manager] Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’ 100%[====================================================================================================================================================================================================================================>] 26,024 152KB/s in 0.2s 2020-01-21 03:13:51 (152 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024] [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll total 28 -rw-r--r-- 1 root root 26024 Apr 25 2019 mysql80-community-release-el7-3.noarch.rpm [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/ total 32 -rw-r--r--. 1 root root 1664 Nov 23 2018 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Nov 23 2018 CentOS-CR.repo -rw-r--r--. 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Nov 23 2018 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Nov 23 2018 CentOS-Sources.repo -rw-r--r--. 1 root root 5701 Nov 23 2018 CentOS-Vault.repo [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll total 28 -rw-r--r-- 1 root root 26024 Apr 25 2019 mysql80-community-release-el7-3.noarch.rpm [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql80-community-release-el7-3 ################################# [100%] [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/ total 40 -rw-r--r--. 1 root root 1664 Nov 23 2018 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Nov 23 2018 CentOS-CR.repo -rw-r--r--. 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Nov 23 2018 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Nov 23 2018 CentOS-Sources.repo -rw-r--r--. 1 root root 5701 Nov 23 2018 CentOS-Vault.repo -rw-r--r-- 1 root root 2076 Apr 25 2019 mysql-community.repo -rw-r--r-- 1 root root 2108 Apr 25 2019 mysql-community-source.repo [root@hdp101.yinzhengjie.org.cn ~]#
3>.安装MySQL服务
[root@hdp101.yinzhengjie.org.cn ~]# yum -y install mysql-community-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql80-community | 2.5 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/3): mysql80-community/x86_64/primary_db | 97 kB 00:00:00 (2/3): mysql-connectors-community/x86_64/primary_db | 53 kB 00:00:01 (3/3): mysql-tools-community/x86_64/primary_db | 69 kB 00:00:01 Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:8.0.19-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 8.0.19-1.el7 for package: mysql-community-server-8.0.19-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.19-1.el7.x86_64 --> Running transaction check ---> Package mysql-community-client.x86_64 0:8.0.19-1.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.19-1.el7.x86_64 ---> Package mysql-community-common.x86_64 0:8.0.19-1.el7 will be installed --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be obsoleted --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:8.0.19-1.el7 will be obsoleting --> Running transaction check ---> Package mysql-community-libs-compat.x86_64 0:8.0.19-1.el7 will be obsoleting --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================================================================================================== Package Arch Version Repository Size ============================================================================================================================================================================================================================================================================== Installing: mysql-community-libs x86_64 8.0.19-1.el7 mysql80-community 4.0 M replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5 mysql-community-libs-compat x86_64 8.0.19-1.el7 mysql80-community 1.3 M replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5 mysql-community-server x86_64 8.0.19-1.el7 mysql80-community 436 M Installing for dependencies: mysql-community-client x86_64 8.0.19-1.el7 mysql80-community 41 M mysql-community-common x86_64 8.0.19-1.el7 mysql80-community 605 k Transaction Summary ============================================================================================================================================================================================================================================================================== Install 3 Packages (+2 Dependent packages) Total download size: 483 M Downloading packages: warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY ] 320 kB/s | 540 kB 00:25:42 ETA Public key for mysql-community-common-8.0.19-1.el7.x86_64.rpm is not installed (1/5): mysql-community-common-8.0.19-1.el7.x86_64.rpm | 605 kB 00:00:01 (2/5): mysql-community-libs-8.0.19-1.el7.x86_64.rpm | 4.0 MB 00:00:02 (3/5): mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm | 1.3 MB 00:00:00 (4/5): mysql-community-client-8.0.19-1.el7.x86_64.rpm | 41 MB 00:00:07 (5/5): mysql-community-server-8.0.19-1.el7.x86_64.rpm | 436 MB 00:00:42 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 10 MB/s | 483 MB 00:00:47 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql80-community-release-el7-3.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : mysql-community-common-8.0.19-1.el7.x86_64 1/6 Installing : mysql-community-libs-8.0.19-1.el7.x86_64 2/6 Installing : mysql-community-client-8.0.19-1.el7.x86_64 3/6 Installing : mysql-community-server-8.0.19-1.el7.x86_64 4/6 Installing : mysql-community-libs-compat-8.0.19-1.el7.x86_64 5/6 Erasing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 6/6 Verifying : mysql-community-libs-8.0.19-1.el7.x86_64 1/6 Verifying : mysql-community-libs-compat-8.0.19-1.el7.x86_64 2/6 Verifying : mysql-community-client-8.0.19-1.el7.x86_64 3/6 Verifying : mysql-community-common-8.0.19-1.el7.x86_64 4/6 Verifying : mysql-community-server-8.0.19-1.el7.x86_64 5/6 Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 6/6 Installed: mysql-community-libs.x86_64 0:8.0.19-1.el7 mysql-community-libs-compat.x86_64 0:8.0.19-1.el7 mysql-community-server.x86_64 0:8.0.19-1.el7 Dependency Installed: mysql-community-client.x86_64 0:8.0.19-1.el7 mysql-community-common.x86_64 0:8.0.19-1.el7 Replaced: mariadb-libs.x86_64 1:5.5.60-1.el7_5 Complete! [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# grep cachedir /etc/yum.conf cachedir=/var/cache/yum/$basearch/$releasever [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /var/cache/yum/$basearch/$releasever total 0 drwxr-xr-x. 3 root root 15 Jan 20 05:28 x86_64 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /var/cache/yum/$basearch/$releasever/x86_64 total 0 drwxr-xr-x. 8 root root 202 Jan 21 03:17 7 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /var/cache/yum/$basearch/$releasever/x86_64/7 total 8 drwxr-xr-x. 4 root root 278 Jan 21 03:17 base drwxr-xr-x. 4 root root 183 Jan 21 03:17 extras drwxr-xr-x 4 root root 137 Jan 21 03:17 mysql80-community drwxr-xr-x 4 root root 137 Jan 21 03:17 mysql-connectors-community drwxr-xr-x 4 root root 137 Jan 21 03:17 mysql-tools-community -rw-r--r-- 1 root root 530 Jan 21 03:17 timedhosts -rw-r--r--. 1 root root 489 Jan 20 05:28 timedhosts.txt drwxr-xr-x. 4 root root 183 Jan 21 03:17 updates [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /var/cache/yum/$basearch/$releasever/x86_64/7/mysql80-community total 104 -rw-r--r-- 1 root root 99494 Jan 9 19:16 1fd8234d262afcc83f200d02b90b12d38fc3f59b-primary.sqlite.bz2 -rw-r--r-- 1 root root 0 Jan 21 03:17 cachecookie drwxr-xr-x 2 root root 31 Jan 21 03:17 gen drwxr-xr-x 2 root root 279 Jan 21 03:17 packages -rw-r--r-- 1 root root 2525 Jan 9 19:16 repomd.xml [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll /var/cache/yum/$basearch/$releasever/x86_64/7/mysql80-community/packages #安装MySQL的rpm包会存在这里,我们可以直接拷贝到生产服务器上安装。 total 494732 -rw-r--r-- 1 root root 43126424 Jan 9 19:13 mysql-community-client-8.0.19-1.el7.x86_64.rpm -rw-r--r-- 1 root root 619248 Jan 9 19:13 mysql-community-common-8.0.19-1.el7.x86_64.rpm -rw-r--r-- 1 root root 4212908 Jan 9 19:14 mysql-community-libs-8.0.19-1.el7.x86_64.rpm -rw-r--r-- 1 root root 1365572 Jan 9 19:14 mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm -rw-r--r-- 1 root root 457272180 Jan 9 19:14 mysql-community-server-8.0.19-1.el7.x86_64.rpm [root@hdp101.yinzhengjie.org.cn ~]#
4>.启动MySQL并设置为开机自启
[root@hdp101.yinzhengjie.org.cn ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# systemctl start mysqld [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-01-21 03:29:33 CST; 8s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 6607 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 6684 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─6684 /usr/sbin/mysqld Jan 21 03:29:28 hdp101.yinzhengjie.org.cn systemd[1]: Starting MySQL Server... Jan 21 03:29:33 hdp101.yinzhengjie.org.cn systemd[1]: Started MySQL Server. [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]#
[root@hdp101.yinzhengjie.org.cn ~]# systemctl enable mysqld #设置MySQL服务开机自启动,若没有输出说明该服务已经是开机自启状态啦。 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# systemctl list-unit-files | grep mysql mysqld.service enabled mysqld@.service disabled [root@hdp101.yinzhengjie.org.cn ~]#
5>.查看mysql的日志使用临时密码登录数据库并初始化密码
[root@hdp101.yinzhengjie.org.cn ~]# tail /var/log/mysqld.log 2020-01-20T19:29:28.259360Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 6634 2020-01-20T19:29:30.310721Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tW-l9!YS_R<6 2020-01-20T19:29:33.011165Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 6684 2020-01-20T19:29:33.880394Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2020-01-20T19:29:33.899499Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: ‘8.0.19‘ socket: ‘/var/lib/mysql/mysql.s ock‘ port: 3306 MySQL Community Server - GPL.2020-01-20T19:29:33.920466Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: ‘/var/run/mysqld/mysqlx.sock‘ bind-address: ‘::‘ po rt: 33060[root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.19 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> alter user user() identified by ‘yzj@2019MySQL‘; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# mysql -uroot -pyzj@2019MySQL mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.19 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> set GLOBAL validate_password.policy=0; Query OK, 0 rows affected (0.00 sec) mysql> alter user user() identified by ‘yinzhengjie‘; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.19 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> show variables like ‘%validate_password_policy%‘; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | validate_password.policy | LOW | +--------------------------+-------+ 1 row in set (0.00 sec) mysql>
6>.博主推荐阅读
yum方式部署MySQL: https://www.cnblogs.com/yinzhengjie/p/10212038.html 二进制方式部署MySQL: https://www.cnblogs.com/yinzhengjie/p/10192668.html
四.安装MySQL Connector
1>.在官方下载MySQL Connector(https://dev.mysql.com/downloads/connector/j/)
[root@hdp101.yinzhengjie.org.cn ~]# ll total 0 [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.19-1.el7.noarch.rpm --2020-01-21 03:58:58-- https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.19-1.el7.noarch.rpm Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.19-1.el7.noarch.rpm [following] --2020-01-21 03:59:00-- https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.19-1.el7.noarch.rpm Resolving cdn.mysql.com (cdn.mysql.com)... 104.86.185.42 Connecting to cdn.mysql.com (cdn.mysql.com)|104.86.185.42|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2319080 (2.2M) [application/x-redhat-package-manager] Saving to: ‘mysql-connector-java-8.0.19-1.el7.noarch.rpm’ 100%[=============================================================================================================>] 2,319,080 1.20MB/s in 1.8s 2020-01-21 03:59:03 (1.20 MB/s) - ‘mysql-connector-java-8.0.19-1.el7.noarch.rpm’ saved [2319080/2319080] [root@hdp101.yinzhengjie.org.cn ~]# [root@hdp101.yinzhengjie.org.cn ~]# ll total 2268 -rw-r--r-- 1 root root 2319080 Dec 8 21:19 mysql-connector-java-8.0.19-1.el7.noarch.rpm [root@hdp101.yinzhengjie.org.cn ~]#
2>.
3>.
五.
原文:https://www.cnblogs.com/yinzhengjie2020/p/12219108.html