Linux服務器開發環境准備


前言

         因為后面要探索分布式相關的技術,因此我在騰訊雲申請了一台免費試用的雲服務器。后續會續費,支持雲服務。拿到的雲服務器,很多的的開發所需要的環境需要我們自己去構建,因此,我在此稍微做一下分享。

Linux服務器介紹

 

上圖中是取到雲服務器時,在根目錄下最初始的目錄。linux系統的目錄是一個樹狀的目錄結構。在此着重介紹幾個目錄。

①/bin:bin是binary的縮寫,用於存儲最經常使用的命令。

②/boot:存放啟動Linux時使用的一些核心文件,包括一些連接文件以及鏡像文件。

③/dev:存放linux的外部設備,在Linux中訪問設備的方式和訪問文件的方式相同。

④/etc:存放所有系統管理員所需要的配置文件和目錄。

⑤/home:用戶的主目錄,每一個用戶都有自己的目錄,而且這個目錄是以用戶賬號命名的。

⑥/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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM