在ubuntu18上安装nginx、mysql、tomcat、java、maven
写在前面
之前写过一篇apache,mysql,php在linux上的安装,但是现在服务器换系统了,从centos6换到了ubuntu18,主要还是centos6自带的程序版本都很老了,同时手动升级有非常麻烦,干脆就直接换了新版的ubuntu18
前期准备
1 2 3 4 5 6 7
| lsb_release -a # 查看版本信息
# Distributor ID: Ubuntu # Description: Ubuntu 18.04.4 LTS # Release: 18.04 # Codename: bionic
|
下载安装包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # 这里我是用的是jdk8 wget https://javadl.oracle.com/webapps/download/GetFile/1.8.0_261-b12/a4634525489241b9a9e1aa73d9e118e6/linux-i586/jdk-8u261-linux-x64.tar.gz -O jdk-8u261-linux-x64.tar.gz # 这个链接不保证永久可行 # 也可以使用百度云,之后可能会上传csdn
# 下载 tomcat8.5 wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz
# nginx 当前最新的稳定版1.18 wget http://nginx.org/download/nginx-1.18.0.tar.gz
# mysql 5.7 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
# 当前最新的maven3.6.3 wget https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz # 下载网址 http://maven.apache.org/download.cgi
|
安装依赖
1 2
| sudo apt update sudo apt install libpcre3 libpcre3-dev zlib1g-dev
|
jdk8 下载 链接: https://pan.baidu.com/s/1KgABp3Z8Giz4SpDG2ChIQA 提取码: cxzt
安装nginx
1 2
| # 安装依赖 apt install libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev
|
1 2 3 4 5 6
| tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --prefix=/usr/local/nginx # 选择安装目录 make make install
|
安装java
解压安装
1 2 3
| tar -zxvf jdk-8u261-linux-x64.tar.gz mkdir -p /usr/local/jdk mv jdk1.8.0_261/ /usr/local/jdk
|
配置环境变量
1 2 3 4 5 6 7 8 9
| vim /etc/profile # 修改环境变量 # 在最后添加 export JAVA_HOME=/usr/local/jdk/jdk1.8.0_261/ export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=.:${JAVA_HOME}/bin:$PATH # 使环境变量生效 source /etc/profile
|
查看是否生效
1 2 3 4 5 6
| java -version # java version "1.8.0_261" # Java(TM) SE Runtime Environment (build 1.8.0_261-b12) # Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode) javac -version # javac 1.8.0_261
|
安装maven
1 2 3
| # 安装 tar -zxvf apache-maven-3.6.3-bin.tar.gz mv apache-maven-3.6.3 /usr/local/maven
|
1 2 3 4 5 6 7 8 9 10 11 12
| # 修改并配置环境变量 vim /etc/profile source /etc/profile
# 这是最后就该完后所有添加的内容 export JAVA_HOME=/usr/local/jdk/jdk1.8.0_261/ export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=.:${JAVA_HOME}/bin:$PATH
export M2_HOME=/usr/local/maven/ export PATH=${M2_HOME}/bin:$PATH
|
测试是否安装完成
初始化本地仓库
顺便添加个ojdbc
链接:https://pan.baidu.com/s/1kwsR8MJWkxBcFxgXrgz-6A 提取码:jdbc
1
| mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/usr/local/jar/ojdbc/ojdbc14-10.2.0.4.0.jar#这里是路径
|
安装tomcat
解压安装
1 2
| tar -zxvf apache-tomcat-8.5.57.tar.gz mv apache-tomcat-8.5.57 /usr/local/tomcat8.5
|
修改启动文件
1 2 3 4 5 6 7 8 9
| sudo vim startup.sh sudo vim shutdown.sh
# 在倒数第二行加入 JAVA_HOME=/usr/local/jdk/jdk1.8.0_261/ JRE_HOME=${JAVA_HOME}/jre PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar TOMCAT_HOME=/usr/local/tomcat8.5
|
启动测试
1 2 3 4 5 6 7
| ./bin/startup.sh #Using CATALINA_BASE: /usr/local/tomcat8.5 #Using CATALINA_HOME: /usr/local/tomcat8.5 #Using CATALINA_TMPDIR: /usr/local/tomcat8.5/temp #Using JRE_HOME: /usr/local/jdk/jdk1.8.0_261//jre #Using CLASSPATH: #Tomcat started.
|
访问服务器的8080端口
看到Tomcat界面表示成功
安装mysql
1 2
| tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
|
创建用户和用户组并分配相应的权限
1 2
| groupadd mysql useradd -g mysql mysql -s /sbin/nologin
|
安装依赖
1
| sudo apt install numactl.x86_64 libaio1 libaio-dev
|
注意:这里的依赖和centos里的略有不同centos里面的为libaio
,所以看你有些的教程,嗯、你懂的
初始化及配置
编辑my.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| [client] port = 3306 socket = /tmp/mysql.sock [mysql] prompt = "\u@db \R:\m:\s [\d]> " no-auto-rehash [mysqld] user = mysql port = 3306 basedir = /usr/local/mysql datadir = /data/mysql/ socket = /tmp/mysql.sock character-set-server = utf8mb4 skip_name_resolve = 1 open_files_limit = 65535 back_log = 1024 max_connections = 512 max_connect_errors = 1000000 table_open_cache = 1024 table_definition_cache = 1024 table_open_cache_instances = 64 thread_stack = 512k external-locking = FALSE max_allowed_packet = 32M #sork_buffer_size = 4M join_buffer_size = 4M thread_cache_size = 768 query_cache_size = 0 query_cache_type = 0 interactive_timeout = 600 wait_timeout = 600 tmp_table_size = 32M max_heap_table_size = 32M slow_query_log = 1 slow_query_log_file = /data/mysql/slow.log log-error = /data/mysql/error.log long_query_time = 0.5 server-id = 3306100 log-bin = /data/mysql/mysql-binlog sync_binlog = 1 binlog_cache_size = 4M max_binlog_cache_size = 1G #max_binlog_szie = 1G expire_logs_days = 7 #master_logs_days = 7 master_info_repository = TABLE relay_log_info_repository = TABLE gtid_mode = on enforce_gtid_consistency = 1 log_slave_updates binlog_format = row relay_log_recovery = 1 relay-log-purge = 1 key_buffer_size = 32M read_buffer_size = 8M read_rnd_buffer_size = 4M bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600 explicit_defaults_for_timestamp = 1 innodb_thread_concurrency = 0 innodb_sync_spin_loops = 100 innodb_spin_wait_delay = 30 transaction_isolation = REPEATABLE-READ innodb_buffer_pool_size = 1024M innodb_buffer_pool_instances = 8 innodb_buffer_pool_load_at_startup = 1 innodb_buffer_pool_dump_at_shutdown = 1 innodb_data_file_path = ibdatal:1G:autoextend innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 32M innodb_log_file_size = 2G innodb_log_files_in_group = 2 innodb_io_capacity = 2000 innodb_io_capacity_max = 4000 innodb_flush_neighbors = 0 innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_purge_threads = 4 innodb_page_cleaners = 4 innodb_open_files = 65535 innodb_max_dirty_pages_pct = 50 innodb_flush_method = O_DIRECT innodb_lru_scan_depth = 4000 #innodb_checksum_algorithm = src32 innodb_lock_wait_timeout = 10 innodb_rollback_on_timeout = 1 innodb_print_all_deadlocks = 1 innodb_file_per_table = 1 innodb_online_alter_log_max_size = 4G #internal_tmp_disk_storage_engine = InnoDB innodb_stats_on_metadata = 0 innodb_status_file = 1 innodb_status_output = 0 innodb_status_output_locks = 0 #performance_schema performance_schema = 1 performance_schema_instrument = '%=on' #innodb monitor innodb_monitor_enable = "module_innodb" innodb_monitor_enable = "module_server" innodb_monitor_enable = "module_dml" innodb_monitor_enable = "module_ddl" innodb_monitor_enable = "module_trx" innodb_monitor_enable = "module_os" innodb_monitor_enable = "module_purge" innodb_monitor_enable = "module_log" innodb_monitor_enable = "module_lock" innodb_monitor_enable = "module_buffer" innodb_monitor_enable = "module_index" innodb_monitor_enable = "module_ibuf_system" innodb_monitor_enable = "module_buffer_page" innodb_monitor_enable = "module_adaptive_hash" [mysqldump] quick max_allowd_packet
|
别忘了添加权限不是root账户的话记得添加sudo
1 2 3
| chown mysql:mysql -R /usr/local/mysql mkdir -p /data/mysql chown mysql:mysql -R /data/mysql
|
初始化
1 2 3 4 5 6
| cd /usr/local/mysql bin/mysqld \ --initialize \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/data/mysql
|
3.设置root用户密码
启动mysql,并查看生成的初始密码
1 2
| support-files/mysql.server start # 启动MySQL cat /data/mysql/error.log |grep password #查看生成的初始密码
|
这里提醒一下如果在启动过程中出了error或者其他错误,可以查看日志文件进行修复,没有可以忽略这一步,如果是my.cnf里面的问题,一般直接使用#进行注释就可以了
1 2
| #查看日志文件 cat /data/mysql/error.log
|
登录并输入刚才设置的密码
同理进入mysql后设置密码
1
| set password=password('root');
|
1 2
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION; FLUSH PRIVILEGES;
|
1 2 3
| vim /etc/sysconfig/iptables #加入以下字段 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEP
|