一些软件的离线安装会容易一点的并未记录在线yum安装, 比如tomcat等.
很多内容和写的另外一篇博客nginx+keepalived+pgsql+mysql+redis+tomcat离线部署过程有部分重合
因为一些在线安装, 无非是
rpm
/tar.gz
压缩包: 同上有一些服务器会自带java8
rpm -qa|grep jdk
查看copy-jdk-configs-4.0-1.hce2.noarch java-1.8.0-openjdk-headless-1.8.0.342.b07-0.hce2.x86_64 java-1.8.0-openjdk-1.8.0.342.b07-0.hce2.x86_64 java-1.8.0-openjdk-devel-1.8.0.342.b07-0.hce2.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.342.b07-0.hce2.x86_64
rpm -ivh jdk-8u371-linux-x64.rpm
java
/ javac
/ java -version
yum install -y java-1.8.0-openjdk-devel.x86_64
下载: 官网下载tar.gz压缩包, apache-tomcat-8.5.81.tar.gz
为例
上传: 将压缩包上传到服务器的一个目录上
解压: tar -zxvf apache-tomcat-8.5.81.tar.gz
重命名: mv apache-tomcat-8.5.81.tar.gz tomcat
移动到安装目录(位置随意): mv tomcat /usr/local/tomcat
创建tomcat.service, vi /etc/systemd/system/tomcat.service
, 并输入(注意java路径和tomcat路径):
[Unit] Description=Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/ Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/usr/local/tomcat/ Environment=CATALINA_BASE=/usr/local/tomcat/ Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' ExecStart=/usr/local/tomcat/bin/startup.sh ExecStop=/usr/local/tomcat/bin/shutdown.sh User=root Group=root UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
常用指令
验证: curl localhost:8080
修改默认端口8080为80, vi /usr/local/tomcat/conf/service.xml
, 差不多69行(或者通过/ + 输入8080寻找)
<Connector port="80" protocol="HTTP/1.1"...
将8080
修改成80即可
重启tomcat: systemctl restart tomcat
端口放行
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --list-port
firewall-cmd --reload
curl ip:80
参考:
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
grep 'temporary password' /var/log/mysqld.log
mysql -p t&ki3u&+ib7X
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
mysql> update mysql.user set host='%' where user="root";
mysql> flush privileges;
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --list-port
firewall-cmd --reload
mysql-8.0.32-el7-x86_64.tar.gz
/usr/local下
tar -zxvf mysql-8.0.32-el7-x86_64.tar.gz
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql mysql/
vim /etc/my.cnf
, 其中local_case_table_names=1
是忽略大小写[mysql] default-character-set=utf8mb4 [client] #port=3306 socket=/var/lib/mysql/mysql.sock [mysqld] user=mysql general_log = 1 general_log_file= /var/log/mysql/mysql.log socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data log-bin=/usr/local/mysql/data/mysql-bin innodb_data_home_dir=/usr/local/mysql/data innodb_log_group_home_dir=/usr/local/mysql/data/ character-set-server=utf8mb4 lower_case_table_names=1 autocommit=1 default_authentication_plugin=mysql_native_password symbolic-links=0 # Disabling symbolic-links is recommended to prevent assorted security risks # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/usr/local/mysql/data/mysql.log pid-file=/usr/local/mysql/data/mysql.pid # # include all files from the config directory
chown 777 /etc/my.cnf
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
source /etc/profile
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
, 会输出日志如下(最后一行是默认密码):2023-04-18T06:52:34.464698Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2023-04-18T06:52:34.464786Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. 2023-04-18T06:52:34.464809Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.32) initializing of server in progress as process 11924 2023-04-18T06:52:34.480151Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2023-04-18T06:52:34.946560Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2023-04-18T06:52:36.589592Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fGzmjdZXj0<p
cp -a ./support-files/mysql.server /etc/init.d/mysql cp -a ./support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysql chmod +x /etc/init.d/mysqld
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
service mysql start
service mysql restart
service mysql stop
/usr/local/mysql/bin/mysql -p
, 回车输入密码(初始化数据库那个默认密码)ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '5h%jqTlsjfgm0UjHksklP3vL';
flush privileges;
vim /etc/systemd/system/mysql.service
[Unit] Description=MySQL Server After=network.target [Service] Type=forking User=mysql ExecStart=/etc/init.d/mysql start ExecStop=/etc/init.d/mysql stop [Install] WantedBy=multi-user.target
service mysql stop
systemctl daemon-reload
systemctl enable mysql
syatemctl start mysql
会自动生成service, 目录在/usr/lib/systemd/system/
下, 自己创建的service在这里和/etc/systemd/system/
下都是可以生效, 区别是/usr/
下的一般是软件安装时候自动生成的, /etc/
下是用户自己定义的.
Linux
-> Red Hat/Rocky/CentOS
-> 1.软件版本最新就行
-> 2.系统版本根据自己的选择对应版本
-> 3.位数 x86_64就行
下方会出现安装需要执行的指令sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo yum install -y postgresql15-server sudo /usr/pgsql-15/bin/postgresql-15-setup initdb sudo systemctl enable postgresql-15 sudo systemctl start postgresql-15
sudo – u postgres psql
\password postgres
, 回车等待输入密码alter user postgres with password 'your_new_password';
也行\q
postgresql.conf
:
vim /var/lib/pgsql/14/data/postgresql.conf
, 修改成listen_addresses="*"
pg_hab.conf
: vim /var/lib/pgsql/14/data/pg_hba.conf
在IPV4
下添加host all all 0.0.0.0/0 md5
systemctl status firewalld
查看防火墙状态)
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
systemctl restart postgresql-15
https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-7-x86_64/
rpm -ivh postgresql15-libs-15.3-1PGDG.rhel7.x86_64.rpm rpm -ivh postgresql15-15.3-1PGDG.rhel7.x86_64.rpm rpm -ivh postgresql15-server-15.3-1PGDG.rhel7.x86_64.rpm
/usr/pgsql-15/bin/postgresql-15-setup initdb
systemctl enable postgresql-15
systemctl start postgresql-15
gcc pcre-devel openssl-devel zlib-devel
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
rpm -ivh *.rpm --nodeps --force
批量安装redis-7.0.11.tar.gz
, 上传服务器tar -zxvf redis-7.0.11.tar.gz
cd redis-7.0.11
make
make install PREFIX=/usr/local/redis
, 不指定目录, 默认/usr/local/bin
, 指定了会在目录下生成bin
目录cp redis.conf /usr/local/redis/bin/
vim /usr/local/redis/bin/redis.conf
daemonize yes
# bind 127.0.0.1
或者改成 0.0.0.0
protected-mode no
port 6379
requirepass 123456
logfile "/usr/local/redis/bin/redis.log"
// 需要手动创建出[Unit] Description=redis-server After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable redis
systemctl start redis
firewall-cmd --add-port=6379
firewall-cmd --reload
学习使用过程整理了ngix安装与使用
也需要先提前安装5.1中的内容
下载: https://nginx.org/en/download.html, 中的Stable version
, 以nginx-1.24.0.tar.gz
为例
上传服务器
解压: tar -zxvf nginx-1.24.0.tar.gz
切换目录: cd nginx-1.24.0
配置: ./configure
编译: make
安装: make install
, 默认安装目录/usr/local/nginx
, 也可想redis一样指定安装目录
修改配置文件(简单配置)
http
下与server
同级的地方upstream myservers { # 可多个 # 输入ip端口和权重 server 127.0.0.1:8080 weight=1; }
server
节点下location
中修改server { listen 80; server_name: localhost; location / { proxy_pass http://myservers; proxy_redirect default; #root html; #index index.html index.htm; } }
注册nginx.service, vim /etc/systemd/system/nginx.service
[Unit] Description=Nginx HTTP Server After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
重载: systemctl daemon-reload
开机自启: systemctl enable nginx
启动: systemctl start nginx
重载配置(修改配置后需要): systemctl reload nginx
测试能否实现转发
去https://www.keepalived.org/download.html上下载最新安装包
复制到/opt
下
解压: tar -zxvf keepalived-2.2.7.tar.gz
进入目录: cd keepalived-2.2.7/
配置: ./configure --prefix=/usr/local/keepalived
, 指定安装目录
编译: make
安装: make install
进入安装目录: cd /usr/local/keepalived/
会自动生成:
drwxr-xr-x. 2 root root 21 May 5 03:19 bin drwxr-xr-x. 4 root root 41 May 5 03:19 etc drwxr-xr-x. 2 root root 24 May 5 03:19 sbin drwxr-xr-x. 5 root root 40 May 5 03:19 share
新建配置文件(同目录下有配置文件的demo可参考): vim ./etc/keepalived/keepalived.conf
备用服务器上的state 填入BACK_UP, 优先级小一点. 其他一样
! Configuration File for keepalived # 定义虚拟路由, 必须叫VI_1 vrrp_instance VI_1 { state MASTER #设置为主服务器, 备份服务器设置为BACKUP interface eth0 #监控的网络接口(ifconfig或者ip addr指令找出网卡) priority 100 #(优先级, 主机大一点, 备份机小一点) virtual_router_id 99 #同一个vrrp_instance下routerId必须是一致的 authentication { auth_type PASS #vrrp认证方式主备必须一致 auth_pass 12345 #密码 } virtual_ipaddress { 127.0.0.88 #虚拟ip, 主从一致, 可配置多个 } }
修改service
使用离线方式安装keepalived后会自动生成keepalived.service文件位置在: /usr/lib/systemd/system/keepalived.service
注: 一般系统的或者安装程序自动生成的service文件会在/usr/lib/systemd/system
下
用户自己配置的service一般会放在/etc/systemd/system/下, 两个目录下都可以用systemctl命令操作到.
默认的keepalived.service文件
[Unit] Description=LVS and VRRP High Availability Monitor After=network-online.target syslog.target Wants=network-online.target Documentation=man:keepalived(8) Documentation=man:keepalived.conf(5) Documentation=man:genhash(1) Documentation=https://keepalived.org [Service] Type=forking PIDFile=/run/keepalived.pid KillMode=process EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
修改后的keepalived.service文件
需要修改ExecStart命令后指向配置文件位置. -f /path/to/keepalived.conf
(因为默认的配置文件都在/usr/local/keepalived/etc/内, 就没有往/etc/keepalived/内复制)
[Unit] Description=LVS and VRRP High Availability Monitor After=network-online.target syslog.target Wants=network-online.target Documentation=man:keepalived(8) Documentation=man:keepalived.conf(5) Documentation=man:genhash(1) Documentation=https://keepalived.org [Service] Type=forking PIDFile=/run/keepalived.pid KillMode=process EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS -f /usr/local/keepalived/etc/keepalived/keepalived.conf ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
使用systemctl控制
systemctl daemon-reload
systemctl enable keepalived
systemctl start keepalived
systemctl restart keepalived
systemctl stop keepalived
systemctl status keepalived
keepalived的默认日志在/var/log/messages下, 修改日志方法参考这个
防火墙放行vrrp通信: firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent
防火墙重载: firewall-cmd --reload
检查通信是否正常: tcpdump -i eth0-nn host 224.0.0.18
, 只有一个等级高为正常
通过访问虚拟ip查看是否由正在工作的主或备来处理ip内的请求.