前言java
由於後面要探索分佈式相關的技術,所以我在騰訊雲申請了一臺免費試用的雲服務器。後續會續費,支持雲服務。拿到的雲服務器,不少的的開發所須要的環境須要咱們本身去構建,所以,我在此稍微作一下分享。mysql
Linux服務器介紹linux
上圖中是取到雲服務器時,在根目錄下最初始的目錄。linux系統的目錄是一個樹狀的目錄結構。在此着重介紹幾個目錄。sql
①/bin:bin是binary的縮寫,用於存儲最常常使用的命令。數據庫
②/boot:存放啓動Linux時使用的一些核心文件,包括一些鏈接文件以及鏡像文件。vim
③/dev:存放linux的外部設備,在Linux中訪問設備的方式和訪問文件的方式相同。服務器
④/etc:存放全部系統管理員所須要的配置文件和目錄。session
⑤/home:用戶的主目錄,每個用戶都有本身的目錄,並且這個目錄是以用戶帳號命名的。socket
⑥/lost+found:這個目錄通常爲空,除非非法關機後,會存儲一些文件。分佈式
⑦/root:這個目錄是系統管理員,也稱做超級用戶的主目錄。
⑧/src:存放一些服務啓動以後須要提取的一些文件。
⑨/usr:很是重要的一個目錄,許多應用程序和文件都存放在這個目錄下。
⑩/var:存放不斷擴充的文件,好比日誌文件等等。
JDK準備
1.將tar文件解壓,同時複製到 /usr/local/java 目錄下。
2.配置環境變量 vim /etv/profile ,在該文件下追加,source /etc/profile不須要重啓系統,從新加載一下該文件便可。
export JAVA_HOME=/usr/local/java/jdk1.8.0_181 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
使用java -version驗證一下是否配置正確。
MYSQL準備
1.安裝部分包:yum -y install numactl libaio*
2. 下載tar文件
3.解壓複製到/usr/local/mysql目錄下
①首先將tar文件解壓,tar -zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz.
②將mysql-5.6.41-linux-glibc2.12-x86_64這個目錄包含目錄下的全部文件複製到/user/local。而且新目錄指定爲mysql。cp -r mysql-5.6.41-linux-glibc2.12-x86_64 /usr/local/mysql。
4.添加系統mysql組和mysql用戶
[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -r -g mysql mysql
5.安裝數據庫
建立mysql數據和日誌存放目錄 [root@localhost src]# cd / [root@localhost /]# mkdir data [root@localhost /]# cd data [root@localhost data]# mkdir mysql [root@localhost data]# cd mysql [root@localhost mysql]# mkdir data [root@localhost mysql]# mkdir log [root@localhost mysql]# cd log [root@localhost log]# touch error.log [root@localhost log]# chown -R mysql:mysql /data/mysql/log [root@localhost log]# chown -R mysql:mysql /data/mysql/data 切到mysql安裝目錄 [root@localhost src]# cd /usr/local/mysql 修改當前目錄擁有者爲mysql用戶 [root@localhost mysql]# chown -R mysql:mysql ./ 安裝數據庫 [root@localhost mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
在執行安裝時出現了錯誤。此時咱們主要安裝安裝autoconf庫。 命令:yum-y install autoconf (此包安裝時會安裝Data:Dumper模塊)
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper。
繼續執行,無報錯。
6.設置mysql開機自啓動
將服務文件拷貝到init.d下,並重命名爲mysqld [root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 修改/etc/init.d/mysqld文件 [root@localhost mysql]# vi /etc/init.d/mysqld 設置basedir和datadir的路徑,配置以下: basedir=/usr/local/mysql datadir=/usr/local/mysql/data 賦予可執行權限 [root@localhost mysql]# chmod +x /etc/init.d/mysqld 加入開機啓動 [root@localhost mysql]# chkconfig --add mysqld
接下來須要安裝修改/etc/my.cnf文件
[mysqld] user = mysql port = 3306 autocommit = 1 server_id = 20180827 character-set-server=utf8 lower_case_table_names=1 basedir = /usr/local/mysql datadir = /data/mysql/data socket = /tmp/mysql.sock pid-file = /data/mysql/data/mysqld.pid # connection settings # interactive_timeout=1800 wait_timeout=1800 max_connections =1000 # session memory settings # read_buffer_size=16M read_rnd_buffer_size=64M # log settings # log_error = /data/mysql/log/error.log slow_query_log_file = /data/mysql/log/slow.log log-bin=/data/mysql/log/mysql-bin expire_logs_days=7 slow_query_log = 1 long-query-time = 1 #慢查詢時間 超過1秒則爲慢查詢 # innodb settings # innodb_log_buffer_size=64M innodb_sort_buffer_size=2M sort_buffer_size=64M thread_cache_size=80 # replication settings # master_info_repository = TABLE relay_log_info_repository = TABLE sync_binlog = 1 log_slave_updates binlog_format=row binlog_rows_query_log_events = 1 relay_log = relay.log relay_log_recovery = 1 slave_skip_errors = ddl_exist_errors slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' replicate-ignore-db=mysql replicate-ignore-db=information_schema replicate-ignore-db=performance_schema replicate-ignore-db=test
7.啓動服務而且初始化密碼
啓動mysql服務 [root@localhost mysql]# service mysqld start Starting MySQL.. SUCCESS! 配置環境變量(也能夠用不配置環境變量,設置軟連接) [root@localhost mysql]# vi /etc/profile 加入如下內容: PATH=/usr/local/mysql/bin:$PATH export PATH 使配置當即生效 [root@localhost mysql]# source /etc/profile 修改密碼 [root@localhost mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 1 Server version: 5.6.41-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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 password for root@localhost = password('root'); Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to root@'%' identified by 'root'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 從新登陸 mysql> exit Bye [root@localhost mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 2 Server version: 5.6.41-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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 databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)
若是出現ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的問題,代表密碼設置不正確,可採起如下的方式修改密碼,從新嘗試鏈接。
1.關閉mysql
# service mysqld stop
2.屏蔽權限
# mysqld_safe --skip-grant-table
屏幕出現: Starting demo from .....
3.新開起一個終端輸入
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;//記得要這句話,不然若是關閉先前的終端,又會出現原來的錯誤
mysql> \q
ZOOKEEPER準備
1.下載而且解壓到/usr/local/zookeeper目錄下
2.配置環境變量
% export ZOOKEEPER_INSTALL=/home/tom/zookeeper-x.y.z
% export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
3.在運行Zookeepr前,應先創建配置文件,按慣例命名爲zoo.cfg,並把它放在conf子目錄下,也能夠把它放在/etc/zookeeper下。
tickTime=2000(是Zookeeper獨立的工做時間單元) dataDir=/Users/tom/zookeeper(存儲數據的地址) clientPort=2181(2181是常常的選擇,此處是關於用戶和Zookeeper相連的地方)
4.獨立模式配置
配置conf/zoo.conf文件 tickTime=2000 dataDir=/usr/zdatadir dataLogDir=/usr/zlogdir clientPort=2181 initLimit=5 syncLimit=2
5.啓動zookeeper
bin/zkServer.sh start bin/zkCli.sh –server 127.0.0.1:2181