Linux用户和组管理及Apache服务安装

2.实验目的
掌握Linux系统中用户和组的创建、修改和管理方法。
学会使用C语言编写程序批量创建用户。
掌握在CentOS 7系统中安装Apache服务的方法。
3.实验内容
练习Linux命令进行用户和组的管理。
编写C语言程序批量创建用户。
在CentOS 7下安装Apache服务。
4.实验过程描述

4.1 用户和组的管理
4.1.1 创建用户
useradd zhangsan
passwd zhangsan
useradd lisi
passwd lisi
useradd wangwu
passwd wangwu
useradd zhaoliu
passwd zhaoliu
useradd sunqi
passwd sunqi

4.1.2 创建工作组
groupadd Class01
groupadd Class02
groupadd Class03
4.1.3 修改用户默认工作组

usermod -g Class01 zhangsan
usermod -g Class01 lisi
usermod -g Class02 wangwu
usermod -g Class02 zhaoliu
4.1.4 切换用户和更改工作组

su - sunqi
newgrp Class03
4.1.5 设置组管理员
usermod -G Class01 zhangsan
4.1.6 管理Class01组

gpasswd -a sunqi Class01
gpasswd -d lisi Class01
4.1.7 查看工作组成员
cat /etc/group | grep Class01
cat /etc/group | grep Class02
cat /etc/group | grep Class03
4.1.8 修改工作组密码
gpasswd Class02
4.1.9 删除用户和工作组

userdel -r sunqi
groupdel Class03
4.2 编写C语言程序批量创建用户
4.2.1 编写C程序

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
    for (int i = 1; i <= 100; i++) {
        char cmd[100];
        sprintf(cmd, "useradd Student%02d && echo stud123456 | passwd Student%02d --stdin", i, i);
        system(cmd);
    }
    return 0;
}
4.2.2 编译并运行程序

gcc -o create_users create_users.c
./create_users
4.3 安装Apache服务
4.3.1 安装依赖
yum install -y pcre-devel libxml2 expat-devel gcc*
4.3.2 安装apr
yum -y install wget
wget --no-check-certificate https://www.apache.org/dist/apr/apr-1.6.5.tar.bz2
tar xf apr-1.6.5.tar.bz2
cd apr-1.6.5
./configure --prefix=/usr/local/apr
make
make install
4.3.3 安装APR-util

wget --no-check-certificate https://www.apache.org/dist/apr/apr-util-1.6.3.tar.bz2
tar xf apr-util-1.6.3.tar.bz2
cd apr-util-1.6.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
4.3.4 安装apr-iconv

wget --no-check-certificate https://www.apache.org/dist/apr/apr-iconv-1.2.2.tar.bz2
tar xf apr-iconv-1.2.2.tar.bz2
cd apr-iconv-1.2.2
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
make
make install
4.3.5 安装Apache

wget --no-check-certificate https://www.apache.org/dist/httpd/httpd-2.4.63.tar.gz
tar xf httpd-2.4.63.tar.gz
cd httpd-2.4.63
yum -y install zlib-devel
./configure --prefix=/usr/local/apache --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-remoteip --enable-proxy --enable-proxy-fcgi --enable-proxy-uwsgi --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-ab --disable-userdir --enable-nonportable-atomics --disable-ipv6 --with-sendfile
make
make install
4.3.6 启动和测试Apache
systemctl status firewalld
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
./apachectl -t
/usr/local/apache/bin/httpd
netstat -ntpl
elinks http://192.168.9.129 -dump

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值